|
@ -21,10 +21,15 @@ namespace Binance.TradeRobot.Business.Exchange |
|
|
|
|
|
|
|
|
public void AddExchangeAccount(AddExchangeAccountRequest addExchangeAccountRequest) |
|
|
public void AddExchangeAccount(AddExchangeAccountRequest addExchangeAccountRequest) |
|
|
{ |
|
|
{ |
|
|
if (addExchangeAccountRequest.Id == 0 || string.IsNullOrEmpty(addExchangeAccountRequest.LoginName)) |
|
|
if (addExchangeAccountRequest.Id == 0 || |
|
|
|
|
|
string.IsNullOrEmpty(addExchangeAccountRequest.LoginName) || |
|
|
|
|
|
string.IsNullOrEmpty(addExchangeAccountRequest.APIKey) || |
|
|
|
|
|
string.IsNullOrEmpty(addExchangeAccountRequest.SecretKey)) |
|
|
throw new BusinessException("交易所账号参数有误"); |
|
|
throw new BusinessException("交易所账号参数有误"); |
|
|
if (fsql.Select<ExchangeAccount>(addExchangeAccountRequest.Id).Any()) |
|
|
if (fsql.Select<ExchangeAccount>(addExchangeAccountRequest.Id).Any()) |
|
|
throw new BusinessException("交易所账号重复"); |
|
|
throw new BusinessException("交易所账号重复"); |
|
|
|
|
|
if (fsql.Select<ExchangeAPIKey>().Where(k => k.APIKey == addExchangeAccountRequest.APIKey || k.SecretKey == addExchangeAccountRequest.SecretKey).Any()) |
|
|
|
|
|
throw new BusinessException("重复的APIKey或SecretKey"); |
|
|
|
|
|
|
|
|
var exchangeAccount = addExchangeAccountRequest.Map<ExchangeAccount>(); |
|
|
var exchangeAccount = addExchangeAccountRequest.Map<ExchangeAccount>(); |
|
|
if (addExchangeAccountRequest.TradePolicy == Enums.TradePolicy.金字塔) |
|
|
if (addExchangeAccountRequest.TradePolicy == Enums.TradePolicy.金字塔) |
|
@ -33,9 +38,17 @@ namespace Binance.TradeRobot.Business.Exchange |
|
|
if (addExchangeAccountRequest.TradePolicy == Enums.TradePolicy.动量趋势v2) |
|
|
if (addExchangeAccountRequest.TradePolicy == Enums.TradePolicy.动量趋势v2) |
|
|
exchangeAccount.BusinessType = Enums.BusinessType.Spot_Margin; |
|
|
exchangeAccount.BusinessType = Enums.BusinessType.Spot_Margin; |
|
|
|
|
|
|
|
|
fsql.Transaction(() => |
|
|
var exchangeAPIKey = new ExchangeAPIKey() |
|
|
{ |
|
|
{ |
|
|
|
|
|
Id = idGenerator.NewLong(), |
|
|
|
|
|
AccountId = addExchangeAccountRequest.Id, |
|
|
|
|
|
APIKey = addExchangeAccountRequest.APIKey, |
|
|
|
|
|
SecretKey = addExchangeAccountRequest.SecretKey |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
fsql.Transaction(() => |
|
|
|
|
|
{ |
|
|
|
|
|
fsql.Insert(exchangeAPIKey).ExecuteAffrows(); |
|
|
fsql.Insert(exchangeAccount).ExecuteAffrows(); |
|
|
fsql.Insert(exchangeAccount).ExecuteAffrows(); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|