11 changed files with 254 additions and 19 deletions
@ -0,0 +1,52 @@ |
|||
using Binance.TradeRobot.Business.Exchange; |
|||
using Binance.TradeRobot.Model.Base; |
|||
using Binance.TradeRobot.Model.Dto; |
|||
using Microsoft.AspNetCore.Authentication.JwtBearer; |
|||
using Microsoft.AspNetCore.Authorization; |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using System.Collections.Generic; |
|||
|
|||
namespace Binance.TradeRobot.API.Controllers |
|||
{ |
|||
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] |
|||
public class ExchangeAccountController : BaseApiController |
|||
{ |
|||
private ExchangeBusiness exchangeBusiness; |
|||
|
|||
public ExchangeAccountController(ExchangeBusiness exchangeBusiness) |
|||
{ |
|||
this.exchangeBusiness = exchangeBusiness; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 添加交易所账号
|
|||
/// </summary>
|
|||
/// <param name="addExchangeAccountRequest"></param>
|
|||
[HttpPost] |
|||
public void AddExchangeAccount([FromBody] AddExchangeAccountRequest addExchangeAccountRequest) |
|||
{ |
|||
exchangeBusiness.AddExchangeAccount(addExchangeAccountRequest); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 添加交易所APIKey
|
|||
/// </summary>
|
|||
/// <param name="addExchangeAPIKeyRequest"></param>
|
|||
[HttpPost] |
|||
public void AddExchangeAPIKey([FromBody] AddExchangeAPIKeyRequest addExchangeAPIKeyRequest) |
|||
{ |
|||
exchangeBusiness.AddExchangeAPIKey(addExchangeAPIKeyRequest); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 获取交易所账户列表
|
|||
/// </summary>
|
|||
/// <param name="tradePolicy">交易策略</param>
|
|||
/// <returns></returns>
|
|||
[HttpGet("{tradePolicy}")] |
|||
public IList<ExchangeAccountResponse> GetExchangeAccountList([FromRoute] Enums.TradePolicy tradePolicy) |
|||
{ |
|||
return exchangeBusiness.GetExchangeAccountList(tradePolicy); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,56 @@ |
|||
using Binance.TradeRobot.Common.DI; |
|||
using Binance.TradeRobot.Common.Extensions; |
|||
using Binance.TradeRobot.Model.Base; |
|||
using Binance.TradeRobot.Model.Db; |
|||
using Binance.TradeRobot.Model.Dto; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
using Yitter.IdGenerator; |
|||
|
|||
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 void AddExchangeAccount(AddExchangeAccountRequest addExchangeAccountRequest) |
|||
{ |
|||
if (addExchangeAccountRequest.Id == 0 || string.IsNullOrEmpty(addExchangeAccountRequest.LoginName)) |
|||
throw new BusinessException("交易所账号参数有误"); |
|||
if (fsql.Select<ExchangeAccount>(addExchangeAccountRequest.Id).Any()) |
|||
throw new BusinessException("交易所账号重复"); |
|||
|
|||
var exchangeAccount = addExchangeAccountRequest.Map<ExchangeAccount>(); |
|||
if (addExchangeAccountRequest.TradePolicy == Enums.TradePolicy.金字塔) |
|||
exchangeAccount.BusinessType = Enums.BusinessType.UPrep; |
|||
|
|||
if (addExchangeAccountRequest.TradePolicy == Enums.TradePolicy.动量趋势v2) |
|||
exchangeAccount.BusinessType = Enums.BusinessType.Spot_Margin; |
|||
|
|||
fsql.Insert(exchangeAccount).ExecuteAffrows(); |
|||
} |
|||
|
|||
public void AddExchangeAPIKey(AddExchangeAPIKeyRequest addExchangeAPIKeyRequest) |
|||
{ |
|||
if (addExchangeAPIKeyRequest.AccountId == 0 || |
|||
string.IsNullOrEmpty(addExchangeAPIKeyRequest.APIKey) || |
|||
string.IsNullOrEmpty(addExchangeAPIKeyRequest.SecretKey)) |
|||
throw new BusinessException("参数有误"); |
|||
|
|||
if (fsql.Select<ExchangeAPIKey>().Where(k => k.APIKey == addExchangeAPIKeyRequest.APIKey || k.SecretKey == addExchangeAPIKeyRequest.SecretKey).Any()) |
|||
throw new BusinessException("重复的APIKey或SecretKey"); |
|||
|
|||
var exchangeAPIKey = addExchangeAPIKeyRequest.Map<ExchangeAPIKey>(); |
|||
exchangeAPIKey.Id = idGenerator.NewLong(); |
|||
fsql.Insert(exchangeAPIKey).ExecuteAffrows(); |
|||
} |
|||
|
|||
public IList<ExchangeAccountResponse> GetExchangeAccountList(Enums.TradePolicy tradePolicy) |
|||
{ |
|||
return null; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,11 @@ |
|||
namespace Binance.TradeRobot.Model.Dto |
|||
{ |
|||
public class AddExchangeAPIKeyRequest |
|||
{ |
|||
public long AccountId { get; set; } |
|||
|
|||
public string APIKey { get; set; } |
|||
|
|||
public string SecretKey { get; set; } |
|||
} |
|||
} |
@ -0,0 +1,16 @@ |
|||
using Binance.TradeRobot.Model.Base; |
|||
|
|||
namespace Binance.TradeRobot.Model.Dto |
|||
{ |
|||
public class AddExchangeAccountRequest |
|||
{ |
|||
public long Id { get; set; } |
|||
|
|||
public string LoginName { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 交易策略
|
|||
/// </summary>
|
|||
public Enums.TradePolicy TradePolicy { get; set; } |
|||
} |
|||
} |
@ -0,0 +1,9 @@ |
|||
namespace Binance.TradeRobot.Model.Dto |
|||
{ |
|||
public class ExchangeAPIKeyResponse : Db.ExchangeAPIKey |
|||
{ |
|||
public decimal SpotMarginUSDT { get; set; } |
|||
|
|||
public string RobotSymbol { get; set; } |
|||
} |
|||
} |
@ -0,0 +1,25 @@ |
|||
using Binance.TradeRobot.Model.Db; |
|||
using System.Collections.Generic; |
|||
|
|||
namespace Binance.TradeRobot.Model.Dto |
|||
{ |
|||
public class ExchangeAccountResponse : ExchangeAccount |
|||
{ |
|||
public IList<ExchangeAPIKeyResponse> ExchangeAPIKeyList { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 合约USDT资产
|
|||
/// </summary>
|
|||
public decimal UPrepUSDT { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 币币USDT资产
|
|||
/// </summary>
|
|||
public decimal SpotUSDT { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 逐仓杠杆USDT资产
|
|||
/// </summary>
|
|||
public decimal SpotMarginUSDT { get; set; } |
|||
} |
|||
} |
Loading…
Reference in new issue