Skip to content

Commit bf604b5

Browse files
authored
[Coinbase] withdrawal (#657)
* [Coinbase] withdrawal * [Coinbase] withdrawal nonce * Currencies option for testing
1 parent 7816c3b commit bf604b5

File tree

4 files changed

+76
-0
lines changed

4 files changed

+76
-0
lines changed

src/ExchangeSharp/API/Exchanges/Coinbase/ExchangeCoinbaseAPI.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,31 @@ protected override async Task<Dictionary<string, decimal>> OnGetAmountsAvailable
555555
return amounts;
556556
}
557557

558+
protected override async Task<ExchangeWithdrawalResponse> OnWithdrawAsync(ExchangeWithdrawalRequest request)
559+
{
560+
var nonce = await GetNoncePayloadAsync();
561+
var payload = new Dictionary<string, object>
562+
{
563+
{ "nonce", nonce },
564+
{ "amount", request.Amount },
565+
{ "currency", request.Currency },
566+
{ "crypto_address", request.Address },
567+
{ "add_network_fee_to_total", !request.TakeFeeFromAmount },
568+
};
569+
570+
if (!string.IsNullOrEmpty(request.AddressTag))
571+
{
572+
payload.Add("destination_tag", request.AddressTag);
573+
}
574+
575+
var result = await MakeJsonRequestAsync<WithdrawalResult>("/withdrawals/crypto", null, payload, "POST");
576+
577+
return new ExchangeWithdrawalResponse
578+
{
579+
Id = result.Id
580+
};
581+
}
582+
558583
protected override async Task<ExchangeOrderResult> OnPlaceOrderAsync(ExchangeOrderRequest order)
559584
{
560585
object nonce = await GenerateNonceAsync();
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using Newtonsoft.Json;
2+
3+
namespace ExchangeSharp.Coinbase
4+
{
5+
public class WithdrawalResult
6+
{
7+
[JsonProperty("id")]
8+
public string Id { get; set; }
9+
10+
[JsonProperty("amount")]
11+
public string Amount { get; set; }
12+
13+
[JsonProperty("currency")]
14+
public string Currency { get; set; }
15+
16+
[JsonProperty("fee")]
17+
public string Fee { get; set; }
18+
19+
[JsonProperty("subtotal")]
20+
public string Subtotal { get; set; }
21+
}
22+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using CommandLine;
2+
using ExchangeSharpConsole.Options.Interfaces;
3+
using Newtonsoft.Json;
4+
using System;
5+
using System.Threading.Tasks;
6+
7+
namespace ExchangeSharpConsole.Options
8+
{
9+
[Verb("currencies", HelpText = "Gets a list of currencies available on the exchange")]
10+
public class CurrenciesOption : BaseOption, IOptionPerExchange
11+
{
12+
public string ExchangeName { get; set; }
13+
14+
public override async Task RunCommand()
15+
{
16+
using var api = GetExchangeInstance(ExchangeName);
17+
18+
Authenticate(api);
19+
20+
var currencies = await api.GetCurrenciesAsync();
21+
22+
foreach (var c in currencies)
23+
{
24+
Console.WriteLine($"{c.Key}: {c.Value.FullName}, {c.Value.AltName}");
25+
}
26+
}
27+
}
28+
}

src/ExchangeSharpConsole/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public partial class Program
1818
typeof(CancelOrderOption),
1919
typeof(CandlesOption),
2020
typeof(ConvertOption),
21+
typeof(CurrenciesOption),
2122
typeof(ExampleOption),
2223
typeof(ExportOption),
2324
typeof(InteractiveOption),

0 commit comments

Comments
 (0)