Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More command line options for testing #658

Merged
merged 5 commits into from
Sep 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/ExchangeSharpConsole/Options/DepositAddressOption.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using CommandLine;
using ExchangeSharpConsole.Options.Interfaces;
using System;
using System.Threading.Tasks;

namespace ExchangeSharpConsole.Options
{
[Verb("deposit-address", HelpText = "Get a deposit address for given currency")]
public class DepositAddressOption : BaseOption, IOptionPerExchange, IOptionWithCurrency
{
public string ExchangeName { get; set; }

public string Currency { get; set; }

public override async Task RunCommand()
{
using var api = GetExchangeInstance(ExchangeName);

Authenticate(api);

var address = await api.GetDepositAddressAsync(Currency);

Console.WriteLine($"Address: {address}");
}
}
}
13 changes: 13 additions & 0 deletions src/ExchangeSharpConsole/Options/Interfaces/IOptionWithAddress.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using CommandLine;

namespace ExchangeSharpConsole.Options.Interfaces
{
public interface IOptionWithAddress
{
[Option('d', "address", Required = true, HelpText = "Crypto address")]
string Address { get; set; }

[Option('t', "address-tag", Required = false, HelpText = "Tag describing the address")]
string Tag { get; set; }
}
}
10 changes: 10 additions & 0 deletions src/ExchangeSharpConsole/Options/Interfaces/IOptionWithAmount.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using CommandLine;

namespace ExchangeSharpConsole.Options.Interfaces
{
public interface IOptionWithCurrencyAmount : IOptionWithCurrency
{
[Option('a', "amount", Required = true, HelpText = "Amount of the currency.")]
decimal Amount { get; set; }
}
}
10 changes: 10 additions & 0 deletions src/ExchangeSharpConsole/Options/Interfaces/IOptionWithCurrency.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using CommandLine;

namespace ExchangeSharpConsole.Options.Interfaces
{
public interface IOptionWithCurrency
{
[Option('c', "currency", Required = true, HelpText = "Currency, e.g. BTC.")]
string Currency { get; set; }
}
}
39 changes: 39 additions & 0 deletions src/ExchangeSharpConsole/Options/WithdrawOption.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using CommandLine;
using ExchangeSharp;
using ExchangeSharpConsole.Options.Interfaces;
using System;
using System.Threading.Tasks;

namespace ExchangeSharpConsole.Options
{
[Verb("withdraw", HelpText = "Withdraw given amount in given currency to target address")]
public class WithdrawOption : BaseOption, IOptionPerExchange, IOptionWithAddress, IOptionWithCurrencyAmount
{
public string ExchangeName { get; set; }

public string Address { get; set; }

public string Tag { get; set; }

public decimal Amount { get; set; }

public string Currency { get; set; }

public override async Task RunCommand()
{
using var api = GetExchangeInstance(ExchangeName);

Authenticate(api);

var result = await api.WithdrawAsync(new ExchangeWithdrawalRequest
{
Address = Address,
AddressTag = Tag,
Amount = Amount,
Currency = Currency
});

Console.WriteLine($"Withdrawal successful: {result.Success}, id: {result.Id}, optional message: {result.Message}");
}
}
}
4 changes: 3 additions & 1 deletion src/ExchangeSharpConsole/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public partial class Program
typeof(CancelOrderOption),
typeof(CandlesOption),
typeof(ConvertOption),
typeof(DepositAddressOption),
typeof(CurrenciesOption),
typeof(ExampleOption),
typeof(ExportOption),
Expand All @@ -38,7 +39,8 @@ public partial class Program
typeof(WebSocketsPositionsOption),
typeof(WebSocketsTickersOption),
typeof(WebSocketsTradesOption),
typeof(WebSocketsCandlesOption)
typeof(WebSocketsCandlesOption),
typeof(WithdrawOption)
};

public Program()
Expand Down