Browse Source

支持交易所账号相关接口

master
shanji 3 years ago
parent
commit
3100cb064f
  1. 19
      Binance.TradeRobot.API/Binance.TradeRobot.API.xml
  2. 52
      Binance.TradeRobot.API/Controllers/ExchangeAccountController.cs
  3. 56
      Binance.TradeRobot.Business/Exchange/ExchangeBusiness.cs
  4. 5
      Binance.TradeRobot.Model/Base/MappingProfiles.cs
  5. 46
      Binance.TradeRobot.Model/Binance.TradeRobot.Model.xml
  6. 31
      Binance.TradeRobot.Model/Db/Exchange/ExchangeAPIKey.cs
  7. 3
      Binance.TradeRobot.Model/Db/Exchange/ExchangeAccount.cs
  8. 11
      Binance.TradeRobot.Model/Dto/Request/Exchange/AddExchangeAPIKeyRequest.cs
  9. 16
      Binance.TradeRobot.Model/Dto/Request/Exchange/AddExchangeAccountRequest.cs
  10. 9
      Binance.TradeRobot.Model/Dto/Response/Exchange/ExchangeAPIKeyResponse.cs
  11. 25
      Binance.TradeRobot.Model/Dto/Response/Exchange/ExchangeAccountResponse.cs

19
Binance.TradeRobot.API/Binance.TradeRobot.API.xml

@ -4,6 +4,25 @@
<name>Binance.TradeRobot.API</name>
</assembly>
<members>
<member name="M:Binance.TradeRobot.API.Controllers.ExchangeAccountController.AddExchangeAccount(Binance.TradeRobot.Model.Dto.AddExchangeAccountRequest)">
<summary>
添加交易所账号
</summary>
<param name="addExchangeAccountRequest"></param>
</member>
<member name="M:Binance.TradeRobot.API.Controllers.ExchangeAccountController.AddExchangeAPIKey(Binance.TradeRobot.Model.Dto.AddExchangeAPIKeyRequest)">
<summary>
添加交易所APIKey
</summary>
<param name="addExchangeAPIKeyRequest"></param>
</member>
<member name="M:Binance.TradeRobot.API.Controllers.ExchangeAccountController.GetExchangeAccountList(Binance.TradeRobot.Model.Base.Enums.TradePolicy)">
<summary>
获取交易所账户列表
</summary>
<param name="tradePolicy">交易策略</param>
<returns></returns>
</member>
<member name="M:Binance.TradeRobot.API.Controllers.UserController.Login(Binance.TradeRobot.Model.Dto.LoginRequest)">
<summary>
用户登录

52
Binance.TradeRobot.API/Controllers/ExchangeAccountController.cs

@ -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);
}
}
}

56
Binance.TradeRobot.Business/Exchange/ExchangeBusiness.cs

@ -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;
}
}
}

5
Binance.TradeRobot.Model/Base/MappingProfiles.cs

@ -10,6 +10,11 @@ namespace Binance.TradeRobot.Model.Base
{
CreateMap<User, UserResponse>();
CreateMap<UserAccountFundChangeRecord, UserAccountFundChangeRecordResponse>();
CreateMap<AddExchangeAccountRequest, ExchangeAccount>();
CreateMap<AddExchangeAPIKeyRequest, ExchangeAPIKey>();
CreateMap<ExchangeAPIKey, ExchangeAPIKeyResponse>();
CreateMap<ExchangeAccount, ExchangeAccountResponse>();
}
}
}

46
Binance.TradeRobot.Model/Binance.TradeRobot.Model.xml

@ -41,17 +41,17 @@
</member>
<member name="T:Binance.TradeRobot.Model.Base.Enums.BusinessType">
<summary>
业务类型 现货-币币=0,现货-逐仓杠杆=1,U本位合约=2
业务类型 币币=0,逐仓杠杆=1,U本位合约=2
</summary>
</member>
<member name="F:Binance.TradeRobot.Model.Base.Enums.BusinessType.Spot">
<summary>
现货-币币
币币
</summary>
</member>
<member name="F:Binance.TradeRobot.Model.Base.Enums.BusinessType.Spot_Margin">
<summary>
现货-逐仓杠杆
逐仓杠杆
</summary>
</member>
<member name="F:Binance.TradeRobot.Model.Base.Enums.BusinessType.UPrep">
@ -74,6 +74,26 @@
信号周期 1m=0,3m=1,5m=2,15m=3,30m=4,1h=5,2h=6,4h=7,6h=8,8h=9,12h=10,1d=11,3d=12,1w=13,1M=14
</summary>
</member>
<member name="P:Binance.TradeRobot.Model.Db.ExchangeAccount.BusinessType">
<summary>
业务类型
</summary>
</member>
<member name="P:Binance.TradeRobot.Model.Db.ExchangeAccount.LoginName">
<summary>
账号登录名
</summary>
</member>
<member name="P:Binance.TradeRobot.Model.Db.ExchangeAccount.TradePolicy">
<summary>
交易策略
</summary>
</member>
<member name="P:Binance.TradeRobot.Model.Db.ExchangeAPIKey.AccountId">
<summary>
交易所账号Id
</summary>
</member>
<member name="P:Binance.TradeRobot.Model.Db.Robot.RunningTime">
<summary>
运行时长(s)
@ -139,6 +159,11 @@
用户投资收益
</summary>
</member>
<member name="P:Binance.TradeRobot.Model.Dto.AddExchangeAccountRequest.TradePolicy">
<summary>
交易策略
</summary>
</member>
<member name="P:Binance.TradeRobot.Model.Dto.LoginRequest.Pwd">
<summary>
密码需要Md5小写加密
@ -154,6 +179,21 @@
每页记录数
</summary>
</member>
<member name="P:Binance.TradeRobot.Model.Dto.ExchangeAccountResponse.UPrepUSDT">
<summary>
合约USDT资产
</summary>
</member>
<member name="P:Binance.TradeRobot.Model.Dto.ExchangeAccountResponse.SpotUSDT">
<summary>
币币USDT资产
</summary>
</member>
<member name="P:Binance.TradeRobot.Model.Dto.ExchangeAccountResponse.SpotMarginUSDT">
<summary>
逐仓杠杆USDT资产
</summary>
</member>
<member name="P:Binance.TradeRobot.Model.Dto.UserAccountFundChangeRecordResponse.UserName">
<summary>
资金变更用户名

31
Binance.TradeRobot.Model/Db/Exchange/ExchangeAPIKey.cs

@ -5,27 +5,28 @@ namespace Binance.TradeRobot.Model.Db
{
[Table(DisableSyncStructure = true)]
public partial class ExchangeAPIKey {
public partial class ExchangeAPIKey
{
[Column(IsPrimary = true)]
public long Id { get; set; }
[Column(IsPrimary = true)]
public long Id { get; set; }
/// <summary>
/// 交易所账号Id
/// </summary>
public long AccountId { get; set; }
/// <summary>
/// 交易所账号Id
/// </summary>
public long AccountId { get; set; }
[Column(StringLength = 100, IsNullable = false)]
public string APIKey { get; set; }
[Column(StringLength = 100, IsNullable = false)]
public string APIKey { get; set; }
[Column(InsertValueSql = "getdate()")]
public DateTime CreateTime { get; set; }
[Column(InsertValueSql = "getdate()")]
public DateTime CreateTime { get; set; }
public long? RobotId { get; set; }
public long? RobotId { get; set; }
[Column(StringLength = 100, IsNullable = false)]
public string SecretKey { get; set; }
[Column(StringLength = 100, IsNullable = false)]
public string SecretKey { get; set; }
}
}
}

3
Binance.TradeRobot.Model/Db/Exchange/ExchangeAccount.cs

@ -15,7 +15,8 @@ namespace Binance.TradeRobot.Model.Db
/// <summary>
/// 业务类型
/// </summary>
public int BusinessType { get; set; }
[Column(MapType = typeof(int))]
public Enums.BusinessType BusinessType { get; set; }
[Column(InsertValueSql = "getdate()")]
public DateTime CreateTime { get; set; }

11
Binance.TradeRobot.Model/Dto/Request/Exchange/AddExchangeAPIKeyRequest.cs

@ -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; }
}
}

16
Binance.TradeRobot.Model/Dto/Request/Exchange/AddExchangeAccountRequest.cs

@ -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; }
}
}

9
Binance.TradeRobot.Model/Dto/Response/Exchange/ExchangeAPIKeyResponse.cs

@ -0,0 +1,9 @@
namespace Binance.TradeRobot.Model.Dto
{
public class ExchangeAPIKeyResponse : Db.ExchangeAPIKey
{
public decimal SpotMarginUSDT { get; set; }
public string RobotSymbol { get; set; }
}
}

25
Binance.TradeRobot.Model/Dto/Response/Exchange/ExchangeAccountResponse.cs

@ -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…
Cancel
Save