|
|
@ -3,6 +3,7 @@ using Binance.TradeRobot.Common.Extensions; |
|
|
|
using Binance.TradeRobot.Model.Base; |
|
|
|
using Binance.TradeRobot.Model.Db; |
|
|
|
using Binance.TradeRobot.Model.Dto; |
|
|
|
using Microsoft.Extensions.Caching.Memory; |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
@ -16,7 +17,7 @@ namespace Binance.TradeRobot.Business.Exchange |
|
|
|
[BatchRegistration(ServiceLifetime.Singleton, RegistrationType.Self)] |
|
|
|
public class ExchangeBusiness : BaseBusiness |
|
|
|
{ |
|
|
|
public ExchangeBusiness(IFreeSql fsql, NLogManager logManager, IIdGenerator idGenerator) : base(fsql, logManager, idGenerator) { } |
|
|
|
public ExchangeBusiness(IFreeSql fsql, NLogManager logManager, IIdGenerator idGenerator, IMemoryCache memoryCache) : base(fsql, logManager, idGenerator, memoryCache) { } |
|
|
|
|
|
|
|
public void AddExchangeAccount(AddExchangeAccountRequest addExchangeAccountRequest) |
|
|
|
{ |
|
|
@ -32,7 +33,12 @@ namespace Binance.TradeRobot.Business.Exchange |
|
|
|
if (addExchangeAccountRequest.TradePolicy == Enums.TradePolicy.动量趋势v2) |
|
|
|
exchangeAccount.BusinessType = Enums.BusinessType.Spot_Margin; |
|
|
|
|
|
|
|
fsql.Insert(exchangeAccount).ExecuteAffrows(); |
|
|
|
fsql.Transaction(() => |
|
|
|
{ |
|
|
|
|
|
|
|
fsql.Insert(exchangeAccount).ExecuteAffrows(); |
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public void AddExchangeAPIKey(AddExchangeAPIKeyRequest addExchangeAPIKeyRequest) |
|
|
@ -71,8 +77,10 @@ namespace Binance.TradeRobot.Business.Exchange |
|
|
|
foreach (var exchangeAccount in exchangeAccountList) |
|
|
|
{ |
|
|
|
var currentExchangeAccountAPIKeyList = exchangeAPIKeyList.Where(k => k.AccountId == exchangeAccount.Id); |
|
|
|
if (currentExchangeAccountAPIKeyList.Count() > 0) |
|
|
|
exchangeAccount.ExchangeAPIKeyList.AddRange(currentExchangeAccountAPIKeyList); |
|
|
|
if (currentExchangeAccountAPIKeyList.Count() == 0) |
|
|
|
continue; |
|
|
|
exchangeAccount.ExchangeAPIKeyList.AddRange(currentExchangeAccountAPIKeyList); |
|
|
|
|
|
|
|
var ewh = new ManualResetEvent(false); |
|
|
|
waitList.Add(ewh); |
|
|
|
Task.Factory.StartNew(() => GetExchangeAssets(exchangeAccount, ewh)); |
|
|
@ -85,7 +93,23 @@ namespace Binance.TradeRobot.Business.Exchange |
|
|
|
{ |
|
|
|
try |
|
|
|
{ |
|
|
|
|
|
|
|
var binanceClient = GetBinanceClient(exchangeAccount.ExchangeAPIKeyList[0].APIKey, exchangeAccount.ExchangeAPIKeyList[0].SecretKey); |
|
|
|
if (exchangeAccount.BusinessType == Enums.BusinessType.UPrep) |
|
|
|
{ |
|
|
|
var result = binanceClient.UsdFuturesApi.Account.GetBalancesAsync().Result; |
|
|
|
if (result.Success) |
|
|
|
{ |
|
|
|
exchangeAccount.UPrepUSDT = result.Data.FirstOrDefault(b => b.Asset == "USDT")?.WalletBalance ?? 0; |
|
|
|
} |
|
|
|
} |
|
|
|
else if (exchangeAccount.BusinessType == Enums.BusinessType.Spot) |
|
|
|
{ |
|
|
|
|
|
|
|
} |
|
|
|
else if (exchangeAccount.BusinessType == Enums.BusinessType.Spot_Margin) |
|
|
|
{ |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|