diff --git a/CryptoBotCore.sln b/CryptoBotCore.sln index 34ee418..fb6b747 100644 --- a/CryptoBotCore.sln +++ b/CryptoBotCore.sln @@ -3,24 +3,29 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.1.31911.260 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CryptoBotCore", "CryptoBotCore\CryptoBotCore.csproj", "{6F35ECF7-EF01-4473-A344-2FBD0C3D36D5}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CryptoBotCore", "CryptoBotCore\CryptoBotCore.csproj", "{6F35ECF7-EF01-4473-A344-2FBD0C3D36D5}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CryptoBotFunction", "CryptoBotFunction\CryptoBotFunction.csproj", "{E6C11A63-713F-4653-9514-8A65ACDAF036}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CryptoBotFunction", "CryptoBotFunction\CryptoBotFunction.csproj", "{E6C11A63-713F-4653-9514-8A65ACDAF036}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU + Test|Any CPU = Test|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {6F35ECF7-EF01-4473-A344-2FBD0C3D36D5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {6F35ECF7-EF01-4473-A344-2FBD0C3D36D5}.Debug|Any CPU.Build.0 = Debug|Any CPU {6F35ECF7-EF01-4473-A344-2FBD0C3D36D5}.Release|Any CPU.ActiveCfg = Release|Any CPU {6F35ECF7-EF01-4473-A344-2FBD0C3D36D5}.Release|Any CPU.Build.0 = Release|Any CPU + {6F35ECF7-EF01-4473-A344-2FBD0C3D36D5}.Test|Any CPU.ActiveCfg = Test|Any CPU + {6F35ECF7-EF01-4473-A344-2FBD0C3D36D5}.Test|Any CPU.Build.0 = Test|Any CPU {E6C11A63-713F-4653-9514-8A65ACDAF036}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {E6C11A63-713F-4653-9514-8A65ACDAF036}.Debug|Any CPU.Build.0 = Debug|Any CPU {E6C11A63-713F-4653-9514-8A65ACDAF036}.Release|Any CPU.ActiveCfg = Release|Any CPU {E6C11A63-713F-4653-9514-8A65ACDAF036}.Release|Any CPU.Build.0 = Release|Any CPU + {E6C11A63-713F-4653-9514-8A65ACDAF036}.Test|Any CPU.ActiveCfg = Test|Any CPU + {E6C11A63-713F-4653-9514-8A65ACDAF036}.Test|Any CPU.Build.0 = Test|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/CryptoBotCore/API/BinanceAPI.cs b/CryptoBotCore/API/BinanceAPI.cs index cddabd7..c22b0a4 100644 --- a/CryptoBotCore/API/BinanceAPI.cs +++ b/CryptoBotCore/API/BinanceAPI.cs @@ -1,13 +1,8 @@ -using Binance.Net; +using Binance.Net.Clients; using Binance.Net.Objects; using CryptoBotCore.Models; using CryptoExchange.Net.Authentication; using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace CryptoBotCore.API { @@ -41,7 +36,10 @@ public BinanceAPI(string pair, Dictionary creden public async Task buyOrderAsync(decimal amount) { - var callResult = await client.Spot.Order.PlaceOrderAsync($"{pair_base}{pair_quote}", Binance.Net.Enums.OrderSide.Buy, Binance.Net.Enums.OrderType.Market, quoteOrderQuantity: (decimal?)amount); + var callResult = await client.SpotApi.Trading.PlaceOrderAsync($"{pair_base}{pair_quote}", + Binance.Net.Enums.OrderSide.Buy, + Binance.Net.Enums.SpotOrderType.Market, + quoteQuantity: (decimal?)amount); // Make sure to check if the call was successful if (!callResult.Success) { @@ -57,7 +55,7 @@ public async Task buyOrderAsync(decimal amount) public async Task> getBalancesAsync() { - var callResult = await client.General.GetAccountInfoAsync(); + var callResult = await client.SpotApi.Account.GetAccountInfoAsync(); // Make sure to check if the call was successful if (!callResult.Success) { @@ -73,7 +71,7 @@ public async Task> getBalancesAsync() foreach (var item in balances) { - wallets.Add(new WalletBalances(item.Asset, item.Free)); + wallets.Add(new WalletBalances(item.Asset, item.Available)); } return wallets; @@ -82,7 +80,7 @@ public async Task> getBalancesAsync() public async Task getTakerFee() { - var callResult = await client.Spot.Market.GetTradeFeeAsync($"{pair_base}{pair_quote}"); + var callResult = await client.SpotApi.ExchangeData.GetTradeFeeAsync($"{pair_base}{pair_quote}"); // Make sure to check if the call was successful if (!callResult.Success) @@ -100,7 +98,7 @@ public async Task getTakerFee() public async Task getWithdrawalFeeAsync(decimal? amount = null, string? destinationAddress = null) { - var callResult = await client.WithdrawDeposit.GetAssetDetailsAsync(); + var callResult = await client.SpotApi.ExchangeData.GetAssetDetailsAsync(); // Make sure to check if the call was successful if (!callResult.Success) @@ -118,7 +116,7 @@ public async Task getWithdrawalFeeAsync(decimal? amount = null, string? public async Task withdrawAsync(decimal amount, string destinationAddress) { - var callResult = await client.WithdrawDeposit.WithdrawAsync(this.pair_base, destinationAddress, Convert.ToDecimal(amount)); + var callResult = await client.SpotApi.Account.WithdrawAsync(this.pair_base, destinationAddress, Convert.ToDecimal(amount)); // Make sure to check if the call was successful if (!callResult.Success) { diff --git a/CryptoBotCore/API/BitfinexAPI.cs b/CryptoBotCore/API/BitfinexAPI.cs index 0088cf4..a45feae 100644 --- a/CryptoBotCore/API/BitfinexAPI.cs +++ b/CryptoBotCore/API/BitfinexAPI.cs @@ -1,17 +1,13 @@  using Bitfinex.Net; +using Bitfinex.Net.Clients; using Bitfinex.Net.Objects; using Bittrex.Net; using Bittrex.Net.Objects; using CryptoBotCore.Models; using CryptoExchange.Net.Authentication; -using Kucoin.Net.Objects; using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; + namespace CryptoBotCore.API { @@ -45,7 +41,7 @@ public BitfinexAPI(string pair, Dictionary crede private async Task getCurrentPrice() { - var callResult = await client.GetTickerAsync($"{pair_base}{pair_quote}"); + var callResult = await client.SpotApi.ExchangeData.GetTickerAsync($"{pair_base}{pair_quote}"); // Make sure to check if the call was successful if (!callResult.Success) { @@ -55,7 +51,7 @@ private async Task getCurrentPrice() else { // Call succeeded, callResult.Data will have the resulting data - return callResult.Data.Where(x => x.Symbol == $"{pair_base}{pair_quote}").First().Ask; + return callResult.Data.BestAskPrice; } } @@ -63,9 +59,9 @@ public async Task buyOrderAsync(decimal amount) { var currentPrice = await getCurrentPrice(); var baseAmount = (decimal)amount / currentPrice; - var callResult = await client.PlaceOrderAsync($"{pair_base}{pair_quote}", - Bitfinex.Net.Objects.OrderSide.Buy, - Bitfinex.Net.Objects.OrderType.Market, + var callResult = await client.SpotApi.Trading.PlaceOrderAsync($"{pair_base}{pair_quote}", + Bitfinex.Net.Enums.OrderSide.Buy, + Bitfinex.Net.Enums.OrderType.Market, currentPrice, baseAmount); // Make sure to check if the call was successful @@ -83,7 +79,7 @@ public async Task buyOrderAsync(decimal amount) public async Task> getBalancesAsync() { - var callResult = await client.GetBalancesAsync(); + var callResult = await client.SpotApi.Account.GetBalancesAsync(); // Make sure to check if the call was successful if (!callResult.Success) { @@ -96,7 +92,7 @@ public async Task> getBalancesAsync() foreach (var account in callResult.Data) { - wallets.Add(new WalletBalances(account.Currency, account.BalanceAvailable??0m)); + wallets.Add(new WalletBalances(account.Asset, account.Available??0m)); } return wallets; @@ -105,7 +101,7 @@ public async Task> getBalancesAsync() public async Task getTakerFee() { - var callResult = await client.GetAccountInfoAsync(); + var callResult = await client.SpotApi.Account.GetAccountInfoAsync(); // Make sure to check if the call was successful if (!callResult.Success) @@ -124,7 +120,7 @@ public async Task getTakerFee() public async Task getWithdrawalFeeAsync(decimal? amount = null, string? destinationAddress = null) { - var callResult = await client.GetWithdrawalFeesAsync(); + var callResult = await client.SpotApi.Account.GetWithdrawalFeesAsync(); // Make sure to check if the call was successful if (!callResult.Success) @@ -161,7 +157,7 @@ public async Task withdrawAsync(decimal amount, string dest withdrawal_type = this.pair_base.ToLower(); } - var callResult = await client.WithdrawAsync(withdrawal_type, WithdrawWallet.Trading, (decimal)amount, destinationAddress); + var callResult = await client.SpotApi.Account.WithdrawAsync(withdrawal_type, Bitfinex.Net.Enums.WithdrawWallet.Trading, (decimal)amount, destinationAddress); // Make sure to check if the call was successful if (!callResult.Success) diff --git a/CryptoBotCore/API/BittrexAPI.cs b/CryptoBotCore/API/BittrexAPI.cs index e6eab59..1febe8f 100644 --- a/CryptoBotCore/API/BittrexAPI.cs +++ b/CryptoBotCore/API/BittrexAPI.cs @@ -1,15 +1,10 @@  using Bittrex.Net; +using Bittrex.Net.Clients; using Bittrex.Net.Objects; using CryptoBotCore.Models; using CryptoExchange.Net.Authentication; -using Kucoin.Net.Objects; using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace CryptoBotCore.API { @@ -43,7 +38,7 @@ public BittrexAPI(string pair, Dictionary creden private async Task getCurrentPrice() { - var callResult = await client.GetOrderBookAsync($"{pair_base}{pair_quote}", 0); + var callResult = await client.SpotApi.ExchangeData.GetOrderBookAsync($"{pair_base}{pair_quote}", 0); // Make sure to check if the call was successful if (!callResult.Success) { @@ -53,17 +48,17 @@ private async Task getCurrentPrice() else { // Call succeeded, callResult.Data will have the resulting data - return callResult.Data.Ask.First().Price; + return callResult.Data.Asks.First().Price; } } public async Task buyOrderAsync(decimal amount) { var baseAmount = (decimal)amount / (await getCurrentPrice()); - var callResult = await client.PlaceOrderAsync($"{pair_base}{pair_quote}", - Bittrex.Net.Objects.OrderSide.Buy, - Bittrex.Net.Objects.OrderType.Market, - TimeInForce.FillOrKill, + var callResult = await client.SpotApi.Trading.PlaceOrderAsync($"{pair_base}{pair_quote}", + Bittrex.Net.Enums.OrderSide.Buy, + Bittrex.Net.Enums.OrderType.Market, + Bittrex.Net.Enums.TimeInForce.FillOrKill, baseAmount); // Make sure to check if the call was successful if (!callResult.Success) @@ -80,7 +75,7 @@ public async Task buyOrderAsync(decimal amount) public async Task> getBalancesAsync() { - var callResult = await client.GetBalancesAsync(); + var callResult = await client.SpotApi.Account.GetBalancesAsync(); // Make sure to check if the call was successful if (!callResult.Success) { @@ -93,7 +88,7 @@ public async Task> getBalancesAsync() foreach (var account in callResult.Data) { - wallets.Add(new WalletBalances(account.Currency, account.Available)); + wallets.Add(new WalletBalances(account.Asset, account.Available)); } @@ -103,7 +98,7 @@ public async Task> getBalancesAsync() public async Task getTakerFee() { - var callResult = await client.GetTradingFeesAsync(); + var callResult = await client.SpotApi.Account.GetTradingFeesAsync(); // Make sure to check if the call was successful if (!callResult.Success) @@ -127,7 +122,7 @@ public Task getWithdrawalFeeAsync(decimal? amount = null, string? desti public async Task withdrawAsync(decimal amount, string destinationAddress) { - var callResult = await client.WithdrawAsync(this.pair_base, (decimal)amount, destinationAddress); + var callResult = await client.SpotApi.Account.WithdrawAsync(this.pair_base, (decimal)amount, destinationAddress); // Make sure to check if the call was successful if (!callResult.Success) diff --git a/CryptoBotCore/API/CoinmateAPI.cs b/CryptoBotCore/API/CoinmateAPI.cs index 4c9fe38..3e0b246 100644 --- a/CryptoBotCore/API/CoinmateAPI.cs +++ b/CryptoBotCore/API/CoinmateAPI.cs @@ -80,6 +80,7 @@ private string getSecuredHeaderPart() public async Task buyOrderAsync(decimal amount) { int wait = 0; + var attempt = 0; do { try @@ -104,9 +105,14 @@ public async Task buyOrderAsync(decimal amount) } catch (Exception ex) { + attempt++; + if (attempt >= 3) + { + throw new Exception(JsonConvert.SerializeObject(ex)); + } Log.LogError(JsonConvert.SerializeObject(ex)); wait = (wait == 0) ? 200 : wait * 2; - Thread.Sleep(wait); + await Task.Delay(wait); } } while (true); } @@ -125,6 +131,7 @@ public async Task getWithdrawalFeeAsync(decimal? amount = null, string? } int wait = 0; + var attempt = 0; do { try @@ -144,10 +151,15 @@ public async Task getWithdrawalFeeAsync(decimal? amount = null, string? } catch (Exception ex) { + attempt++; + if (attempt >= 3) + { + throw new Exception(JsonConvert.SerializeObject(ex)); + } Log.LogError(JsonConvert.SerializeObject(ex)); wait = (wait == 0) ? 200 : wait * 2; - Thread.Sleep(wait); + await Task.Delay(wait); } } while (true); } @@ -192,13 +204,13 @@ public async Task withdrawAsync(decimal amount, string dest Log.LogError(JsonConvert.SerializeObject(ex)); attempt++; - if(attempt >= 5) + if(attempt >= 3) { throw new Exception(JsonConvert.SerializeObject(ex)); } wait = (wait == 0) ? 200 : wait * 2; - Thread.Sleep(wait); + await Task.Delay(wait); } } while (true); } @@ -249,10 +261,15 @@ public async Task> getBalancesAsync() { Log.LogError(JsonConvert.SerializeObject(ex)); attempt++; + + if (attempt >= 3) + { + throw new Exception(JsonConvert.SerializeObject(ex)); + } wait = (wait == 0) ? 200 : wait * 2; - Thread.Sleep(wait); + await Task.Delay(wait); } - } while (attempt < 5); + } while (true); throw new Exception("Coinmate API is currently not available."); } diff --git a/CryptoBotCore/API/FtxAPI.cs b/CryptoBotCore/API/FtxAPI.cs index be64a03..e8d152e 100644 --- a/CryptoBotCore/API/FtxAPI.cs +++ b/CryptoBotCore/API/FtxAPI.cs @@ -2,14 +2,11 @@ using Binance.Net.Objects; using CryptoBotCore.Models; using CryptoExchange.Net.Authentication; -using FTX.Net; +using FTX.Net.Clients; using FTX.Net.Objects; +using FTX.Net.Objects.Models; using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; + namespace CryptoBotCore.API { @@ -45,9 +42,7 @@ public FtxAPI(string pair, string account, Dictionary getCurrentPrice() { - var callResult = await client.GetOrderBookAsync($"{pair_base}/{pair_quote}", 20); - // depth of the orderbook arbitrarly set to 20 (default value according to the official FTX api doc) - // depth can't be set to 0 or we get an error 400 with the answer "Depth cannot be negative" + var callResult = await client.TradeApi.CommonSpotClient.GetOrderBookAsync($"{pair_base}/{pair_quote}"); // Make sure to check if the call was successful if (!callResult.Success) { @@ -70,7 +65,7 @@ private async Task getCurrentPrice() public async Task buyOrderAsync(decimal amount) { var baseAmount = amount / (await getCurrentPrice()); - var callResult = await client.PlaceOrderAsync($"{pair_base}/{pair_quote}", FTX.Net.Enums.OrderSide.Buy, FTX.Net.Enums.OrderType.Market, quantity: baseAmount, subaccountName: account); + var callResult = await client.TradeApi.Trading.PlaceOrderAsync($"{pair_base}/{pair_quote}", FTX.Net.Enums.OrderSide.Buy, FTX.Net.Enums.OrderType.Market, quantity: baseAmount, subaccountName: account); // Make sure to check if the call was successful if (!callResult.Success) { @@ -86,7 +81,7 @@ public async Task buyOrderAsync(decimal amount) public async Task> getBalancesAsync() { - var callResult = await client.GetAllAccountBalancesAsync(); + var callResult = await client.TradeApi.Account.GetAllAccountBalancesAsync(); // Make sure to check if the call was successful if (!callResult.Success) { @@ -107,7 +102,7 @@ public async Task> getBalancesAsync() var ftxAccountBalances = ftxAccounts.Value; foreach (var entry in ftxAccountBalances) { - wallets.Add(new WalletBalances(entry.Asset, entry.Free)); + wallets.Add(new WalletBalances(entry.Asset, entry.Available)); } } } @@ -117,7 +112,7 @@ public async Task> getBalancesAsync() public async Task getTakerFee() { - var callResult = await client.GetAccountInfoAsync(); + var callResult = await client.TradeApi.Account.GetAccountInfoAsync(); // Make sure to check if the call was successful if (!callResult.Success) @@ -134,7 +129,7 @@ public async Task getTakerFee() public async Task getWithdrawalFeeAsync(decimal? amount = null, string? destinationAddress = null) { - var callResult = await client.GetWithdrawalFeesAsync(this.pair_base, (amount??0m), destinationAddress??""); // protecting from null values as the underlying lib don't support them + var callResult = await client.TradeApi.Account.GetWithdrawalFeesAsync(this.pair_base, (amount??0m), destinationAddress??""); // protecting from null values as the underlying lib don't support them // Make sure to check if the call was successful if (!callResult.Success) @@ -151,7 +146,7 @@ public async Task getWithdrawalFeeAsync(decimal? amount = null, string? public async Task withdrawAsync(decimal amount, string destinationAddress) { - var callResult = await client.WithdrawAsync(this.pair_base, Convert.ToDecimal(amount), destinationAddress); + var callResult = await client.TradeApi.Account.WithdrawAsync(this.pair_base, Convert.ToDecimal(amount), destinationAddress); // Make sure to check if the call was successful if (!callResult.Success) { diff --git a/CryptoBotCore/API/HuobiAPI.cs b/CryptoBotCore/API/HuobiAPI.cs index 3ca6a0a..7a3f3c8 100644 --- a/CryptoBotCore/API/HuobiAPI.cs +++ b/CryptoBotCore/API/HuobiAPI.cs @@ -1,12 +1,9 @@ using CryptoBotCore.Models; using CryptoExchange.Net.Authentication; -using Huobi.Net; +using Huobi.Net.Clients; +using Huobi.Net.Objects; using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; + namespace CryptoBotCore.API { @@ -35,7 +32,7 @@ public HuobiAPI(string pair, Dictionary credenti private async Task getCurrentPrice() { - var callResult = await client.GetOrderBookAsync($"{pair_base}{pair_quote}", 0); + var callResult = await client.SpotApi.ExchangeData.GetOrderBookAsync($"{pair_base}{pair_quote}", 0); // Make sure to check if the call was successful if (!callResult.Success) { @@ -53,14 +50,18 @@ public async Task buyOrderAsync(decimal amount) { var baseAmount = amount / (await getCurrentPrice()); - var accountResult = await client.GetAccountsAsync(); + var accountResult = await client.SpotApi.Account.GetAccountsAsync(); if (!accountResult.Success) { // Call failed, check accountResult .Error for more info throw new Exception(accountResult.Error?.Message); } - var callResult = await client.PlaceOrderAsync(accountResult.Data.First().Id, $"{this.pair_base}{this.pair_quote}", Huobi.Net.Objects.HuobiOrderType.MarketBuy, baseAmount); + var callResult = await client.SpotApi.Trading.PlaceOrderAsync(accountResult.Data.First().Id, + $"{this.pair_base}{this.pair_quote}", + Huobi.Net.Enums.OrderSide.Buy, + Huobi.Net.Enums.OrderType.Market, + baseAmount); // Make sure to check if the call was successful if (!callResult.Success) { @@ -75,7 +76,7 @@ public async Task buyOrderAsync(decimal amount) public async Task> getBalancesAsync() { - var accountResult = await client.GetAccountsAsync(); + var accountResult = await client.SpotApi.Account.GetAccountsAsync(); if (!accountResult.Success) { // Call failed, check accountResult .Error for more info @@ -83,7 +84,7 @@ public async Task> getBalancesAsync() } - var callResult = await client.GetBalancesAsync(accountResult.Data.First().Id); + var callResult = await client.SpotApi.Account.GetBalancesAsync(accountResult.Data.First().Id); // Make sure to check if the call was successful if (!callResult.Success) @@ -93,13 +94,13 @@ public async Task> getBalancesAsync() } else { - var balances = callResult.Data.Where(x => x.Type == Huobi.Net.Objects.HuobiBalanceType.Trade); + var balances = callResult.Data.Where(x => x.Type == Huobi.Net.Enums.BalanceType.Trade); var wallets = new List(); foreach(var item in balances) { - wallets.Add(new WalletBalances(item.Currency, item.Balance)); + wallets.Add(new WalletBalances(item.Asset, item.Balance)); } return wallets; @@ -129,7 +130,7 @@ public Task getWithdrawalFeeAsync(decimal? amount = null, string? desti public async Task withdrawAsync(decimal amount, string destinationAddress) { - var accountResult = await client.GetAccountsAsync(); + var accountResult = await client.SpotApi.Account.GetAccountsAsync(); if (!accountResult.Success) { // Call failed, check accountResult .Error for more info @@ -137,7 +138,7 @@ public async Task withdrawAsync(decimal amount, string dest } var fee = await getWithdrawalFeeAsync(); - var callResult = await client.WithdrawAsync(destinationAddress, this.pair_base.ToLower(), Convert.ToDecimal(amount), Convert.ToDecimal(fee)); + var callResult = await client.SpotApi.Account.WithdrawAsync(destinationAddress, this.pair_base.ToLower(), Convert.ToDecimal(amount), Convert.ToDecimal(fee)); // Make sure to check if the call was successful if (!callResult.Success) { diff --git a/CryptoBotCore/API/KrakenAPI.cs b/CryptoBotCore/API/KrakenAPI.cs index 8c3813b..45240c5 100644 --- a/CryptoBotCore/API/KrakenAPI.cs +++ b/CryptoBotCore/API/KrakenAPI.cs @@ -1,13 +1,10 @@  using CryptoBotCore.Models; using CryptoExchange.Net.Authentication; -using Kraken.Net; +using Kraken.Net.Clients; +using Kraken.Net.Objects; using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; + namespace CryptoBotCore.API { @@ -46,7 +43,7 @@ public KrakenAPI(string pair, string withdrawalKeyName, Dictionary getCurrentPrice() { - var callResult = await client.GetOrderBookAsync($"{pair_base}{pair_quote}", 0); + var callResult = await client.SpotApi.ExchangeData.GetOrderBookAsync($"{pair_base}{pair_quote}", 0); // Make sure to check if the call was successful if (!callResult.Success) { @@ -64,7 +61,10 @@ public async Task buyOrderAsync(decimal amount) { var baseAmount = amount / (await getCurrentPrice()); - var callResult = await client.PlaceOrderAsync($"{pair_base}{pair_quote}", Kraken.Net.Objects.OrderSide.Buy, Kraken.Net.Objects.OrderType.Market, quantity: baseAmount); + var callResult = await client.SpotApi.Trading.PlaceOrderAsync($"{pair_base}{pair_quote}", + Kraken.Net.Enums.OrderSide.Buy, + Kraken.Net.Enums.OrderType.Market, + quantity: baseAmount); // Make sure to check if the call was successful if (!callResult.Success) { @@ -80,7 +80,7 @@ public async Task buyOrderAsync(decimal amount) public async Task> getBalancesAsync() { - var callResult = await client.GetAvailableBalancesAsync(); + var callResult = await client.SpotApi.Account.GetAvailableBalancesAsync(); // Make sure to check if the call was successful if (!callResult.Success) { @@ -104,7 +104,7 @@ public async Task> getBalancesAsync() public async Task getTakerFee() { - var callResult = await client.GetSymbolsAsync(new List { $"{pair_base}{pair_quote}" }); + var callResult = await client.SpotApi.ExchangeData.GetSymbolsAsync(new List { $"{pair_base}{pair_quote}" }); // Make sure to check if the call was successful if (!callResult.Success) @@ -122,7 +122,7 @@ public async Task getTakerFee() public async Task getWithdrawalFeeAsync(decimal? amount = null, string? destinationAddress = null) { - var callResult = await client.GetWithdrawInfoAsync(this.pair_base, this.withdrawal_keyname, (amount??0m)); + var callResult = await client.SpotApi.Account.GetWithdrawInfoAsync(this.pair_base, this.withdrawal_keyname, (amount??0m)); // Make sure to check if the call was successful if (!callResult.Success) @@ -140,7 +140,7 @@ public async Task getWithdrawalFeeAsync(decimal? amount = null, string? public async Task withdrawAsync(decimal amount, string destinationAddress) { - var callResult = await client.WithdrawAsync(this.pair_base, this.withdrawal_keyname, amount); + var callResult = await client.SpotApi.Account.WithdrawAsync(this.pair_base, this.withdrawal_keyname, amount); // Make sure to check if the call was successful if (!callResult.Success) diff --git a/CryptoBotCore/API/KuCoinAPI.cs b/CryptoBotCore/API/KuCoinAPI.cs index c03be59..26a53dd 100644 --- a/CryptoBotCore/API/KuCoinAPI.cs +++ b/CryptoBotCore/API/KuCoinAPI.cs @@ -1,13 +1,8 @@  using CryptoBotCore.Models; -using Kucoin.Net; +using Kucoin.Net.Clients; using Kucoin.Net.Objects; using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace CryptoBotCore.API { @@ -42,7 +37,10 @@ public KuCoinAPI(string pair, Dictionary credent public async Task buyOrderAsync(decimal amount) { - var callResult = await client.Spot.PlaceOrderAsync($"{pair_base}{pair_quote}", Guid.NewGuid().ToString(), KucoinOrderSide.Buy, KucoinNewOrderType.Market, funds: (decimal)amount); + var callResult = await client.SpotApi.Trading.PlaceOrderAsync($"{pair_base}{pair_quote}", Kucoin.Net.Enums.OrderSide.Buy, + Kucoin.Net.Enums.NewOrderType.Market, + + quoteQuantity: (decimal)amount); // Make sure to check if the call was successful if (!callResult.Success) { @@ -52,13 +50,13 @@ public async Task buyOrderAsync(decimal amount) else { // Call succeeded, callResult.Data will have the resulting data - return callResult.Data.OrderId; + return callResult.Data.Id; } } public async Task> getBalancesAsync() { - var callResult = await client.Spot.GetAccountsAsync(); + var callResult = await client.SpotApi.Account.GetAccountsAsync(); // Make sure to check if the call was successful if (!callResult.Success) { @@ -71,7 +69,7 @@ public async Task> getBalancesAsync() foreach (var account in callResult.Data) { - wallets.Add(new WalletBalances(account.Currency, account.Available)); + wallets.Add(new WalletBalances(account.Asset, account.Available)); } return wallets; @@ -80,7 +78,7 @@ public async Task> getBalancesAsync() public async Task getTakerFee() { - var callResult = await client.Spot.GetSymbolTradingFeesAsync(new List { $"{pair_base}{pair_quote}" }); + var callResult = await client.SpotApi.Account.GetSymbolTradingFeesAsync(new List { $"{pair_base}{pair_quote}" }); // Make sure to check if the call was successful if (!callResult.Success) @@ -98,7 +96,7 @@ public async Task getTakerFee() public async Task getWithdrawalFeeAsync(decimal? amount = null, string? destinationAddress = null) { - var callResult = await client.Spot.GetWithdrawalQuotasAsync(this.pair_base); + var callResult = await client.SpotApi.Account.GetWithdrawalQuotasAsync(this.pair_base); // Make sure to check if the call was successful if (!callResult.Success) @@ -116,7 +114,7 @@ public async Task getWithdrawalFeeAsync(decimal? amount = null, string? public async Task withdrawAsync(decimal amount, string destinationAddress) { - var callResult = await client.Spot.WithdrawAsync(this.pair_base, destinationAddress, amount); + var callResult = await client.SpotApi.Account.WithdrawAsync(this.pair_base, destinationAddress, amount); // Make sure to check if the call was successful if (!callResult.Success) diff --git a/CryptoBotCore/CryptoBotCore.csproj b/CryptoBotCore/CryptoBotCore.csproj index db3f8a9..f5dbbc2 100644 --- a/CryptoBotCore/CryptoBotCore.csproj +++ b/CryptoBotCore/CryptoBotCore.csproj @@ -1,9 +1,10 @@ - + net6.0 enable enable + Debug;Release;Test @@ -17,17 +18,17 @@ - - - + + + - - - - - - - + + + + + + + diff --git a/CryptoBotFunction/AccumulationBotFunction.cs b/CryptoBotFunction/AccumulationBotFunction.cs index fed3771..d80c839 100644 --- a/CryptoBotFunction/AccumulationBotFunction.cs +++ b/CryptoBotFunction/AccumulationBotFunction.cs @@ -16,7 +16,11 @@ namespace CryptoBotFunction public static class AccumulationBotFunction { [FunctionName("AccumulationBotFunction")] - public static void Run([TimerTrigger("%DayDividerSchedule%")] TimerInfo myTimer, ILogger log) + public static void Run([TimerTrigger("%DayDividerSchedule%" + #if DEBUG || TEST + , RunOnStartup=true + #endif + )] TimerInfo myTimer, ILogger log) { LoadAppSettings(); @@ -28,6 +32,7 @@ private static void LoadAppSettings() { var env = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"); var builder = new ConfigurationBuilder() + .AddJsonFile($"local.settings.json", true, true) .AddJsonFile($"appsettings.json", true, true) .AddJsonFile($"appsettings.{env}.json", true, true) .AddEnvironmentVariables(); diff --git a/CryptoBotFunction/CryptoBotFunction.csproj b/CryptoBotFunction/CryptoBotFunction.csproj index 1234e27..4904583 100644 --- a/CryptoBotFunction/CryptoBotFunction.csproj +++ b/CryptoBotFunction/CryptoBotFunction.csproj @@ -2,9 +2,10 @@ net6.0 v4 + Debug;Release;Test - +