Browse Source

下单

master
shanji 3 years ago
parent
commit
ca99fa1297
  1. 4
      Binance.TradeRobot.API/Controllers/ExchangeAccountController.cs
  2. 2
      Binance.TradeRobot.API/Controllers/SingalController.cs
  3. 13
      Binance.TradeRobot.Business/Binance.TradeRobot.Business.xml
  4. 8
      Binance.TradeRobot.Business/Business/ExchangeBusiness.cs
  5. 24
      Binance.TradeRobot.Business/Business/RobotBusiness.cs
  6. 12
      Binance.TradeRobot.Business/Business/SingalBusiness.cs
  7. 6
      Binance.TradeRobot.Business/Business/TradeBusiness/D21TradeBusiness.cs
  8. 11
      Binance.TradeRobot.Business/Business/TradeBusiness/ITradeBusiness.cs
  9. 10
      Binance.TradeRobot.Model/Base/MappingProfiles.cs
  10. 5
      Binance.TradeRobot.Model/Binance.TradeRobot.Model.xml
  11. 2
      Binance.TradeRobot.Model/Db/Exchange/SymbolInfo.cs
  12. 20
      Binance.TradeRobot.Model/Db/Robot/Robot.cs
  13. 25
      SDKAdapter/APIClient/BaseAPIClient.cs
  14. 32
      SDKAdapter/APIClient/BinanceAPIClient.cs
  15. 43
      SDKTestConsole/Program.cs

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

@ -1,4 +1,4 @@
using Binance.TradeRobot.Business.Exchange; using Binance.TradeRobot.Business;
using Binance.TradeRobot.Model.Base; using Binance.TradeRobot.Model.Base;
using Binance.TradeRobot.Model.Dto; using Binance.TradeRobot.Model.Dto;
using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Authentication.JwtBearer;
@ -44,7 +44,7 @@ namespace Binance.TradeRobot.API.Controllers
/// <param name="exchange"></param> /// <param name="exchange"></param>
/// <returns></returns> /// <returns></returns>
[HttpGet("{exchange}")] [HttpGet("{exchange}")]
public IList<SymbolInfoResponse> GetSymbolList(Enums.Exchange exchange) public IList<SymbolInfoResponse> GetSymbolList([FromRoute] Enums.Exchange exchange)
{ {
return exchangeBusiness.GetSymbolList(exchange); return exchangeBusiness.GetSymbolList(exchange);
} }

2
Binance.TradeRobot.API/Controllers/SingalController.cs

@ -1,4 +1,4 @@
using Binance.TradeRobot.Business.Business; using Binance.TradeRobot.Business;
using Binance.TradeRobot.Model.Dto; using Binance.TradeRobot.Model.Dto;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;

13
Binance.TradeRobot.Business/Binance.TradeRobot.Business.xml

@ -4,7 +4,7 @@
<name>Binance.TradeRobot.Business</name> <name>Binance.TradeRobot.Business</name>
</assembly> </assembly>
<members> <members>
<member name="M:Binance.TradeRobot.Business.Exchange.ExchangeBusiness.GetNoUsedExchangeAccountList(Binance.TradeRobot.Model.Base.Enums.TradePolicy,Binance.TradeRobot.Model.Base.Enums.Exchange)"> <member name="M:Binance.TradeRobot.Business.ExchangeBusiness.GetNoUsedExchangeAccountList(Binance.TradeRobot.Model.Base.Enums.TradePolicy,Binance.TradeRobot.Model.Base.Enums.Exchange)">
<summary> <summary>
获取APIKey未使用交易所账户列表 获取APIKey未使用交易所账户列表
</summary> </summary>
@ -66,7 +66,7 @@
现货策略 现货策略
</summary> </summary>
</member> </member>
<member name="M:Binance.TradeRobot.Business.ITradeBusiness.TrendChanged``2(``0,``1)"> <member name="M:Binance.TradeRobot.Business.ITradeBusiness.TrendChanged``2(``0,``1,Binance.TradeRobot.Model.Dto.SymbolInfoResponse)">
<summary> <summary>
趋势变化 趋势变化
</summary> </summary>
@ -74,8 +74,9 @@
<typeparam name="T1"></typeparam> <typeparam name="T1"></typeparam>
<param name="singalRequest"></param> <param name="singalRequest"></param>
<param name="robot"></param> <param name="robot"></param>
<param name="symbolInfo"></param>
</member> </member>
<member name="M:Binance.TradeRobot.Business.ITradeBusiness.LongCross``2(``0,``1,System.Boolean)"> <member name="M:Binance.TradeRobot.Business.ITradeBusiness.LongCross``2(``0,``1,System.Boolean,Binance.TradeRobot.Model.Dto.SymbolInfoResponse)">
<summary> <summary>
多交叉 多交叉
</summary> </summary>
@ -84,8 +85,9 @@
<param name="singalRequest"></param> <param name="singalRequest"></param>
<param name="robot"></param> <param name="robot"></param>
<param name="isRemedy">是否为补救信号</param> <param name="isRemedy">是否为补救信号</param>
<param name="symbolInfo"></param>
</member> </member>
<member name="M:Binance.TradeRobot.Business.ITradeBusiness.ShortCross``2(``0,``1,System.Boolean)"> <member name="M:Binance.TradeRobot.Business.ITradeBusiness.ShortCross``2(``0,``1,System.Boolean,Binance.TradeRobot.Model.Dto.SymbolInfoResponse)">
<summary> <summary>
空交叉 空交叉
</summary> </summary>
@ -93,7 +95,8 @@
<typeparam name="T1"></typeparam> <typeparam name="T1"></typeparam>
<param name="singalRequest"></param> <param name="singalRequest"></param>
<param name="robot"></param> <param name="robot"></param>
<param name="isRemedy">是否为补救信号</param> <param name="isRemedy">是否为补救信号</param>'
<param name="symbolInfo"></param>
</member> </member>
<member name="M:Binance.TradeRobot.Business.UserBusiness.OneWayAssetChange(System.Int64,System.Decimal,System.Int64,Binance.TradeRobot.Model.Base.Enums.CapitalChangeType,System.String)"> <member name="M:Binance.TradeRobot.Business.UserBusiness.OneWayAssetChange(System.Int64,System.Decimal,System.Int64,Binance.TradeRobot.Model.Base.Enums.CapitalChangeType,System.String)">
<summary> <summary>

8
Binance.TradeRobot.Business/Business/ExchangeBusiness.cs

@ -16,7 +16,7 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Yitter.IdGenerator; using Yitter.IdGenerator;
namespace Binance.TradeRobot.Business.Exchange namespace Binance.TradeRobot.Business
{ {
[BatchRegistration(ServiceLifetime.Singleton, RegistrationType.Self)] [BatchRegistration(ServiceLifetime.Singleton, RegistrationType.Self)]
public class ExchangeBusiness : BaseBusiness public class ExchangeBusiness : BaseBusiness
@ -74,6 +74,12 @@ namespace Binance.TradeRobot.Business.Exchange
return fsql.Select<SymbolInfo>().Where(s => s.ExchangeId == exchange).ToList<SymbolInfoResponse>(); return fsql.Select<SymbolInfo>().Where(s => s.ExchangeId == exchange).ToList<SymbolInfoResponse>();
} }
public SymbolInfoResponse GetSymbol(Enums.Exchange exchange, string symbol)
{
return fsql.Select<SymbolInfo>().Where(s => s.ExchangeId == exchange && s.Symbol == symbol).ToOne<SymbolInfoResponse>();
}
public void AddExchangeAccount(AddExchangeAccountRequest addExchangeAccountRequest) public void AddExchangeAccount(AddExchangeAccountRequest addExchangeAccountRequest)
{ {
if (addExchangeAccountRequest.Id == 0 || if (addExchangeAccountRequest.Id == 0 ||

24
Binance.TradeRobot.Business/Business/RobotBusiness.cs

@ -199,15 +199,14 @@ namespace Binance.TradeRobot.Business
bool isLoadRecentTradeProfit = true, bool isLoadRecentTradeProfit = true,
bool isLoadAPIKey = false) bool isLoadAPIKey = false)
{ {
var robotList = fsql.Select<Robot, SymbolInfo, RobotAccount, D21Policy, ExchangeAPIKey>().InnerJoin((r, s, ra, d, e) => r.Id == ra.RobotId) var robotList = fsql.Select<Robot, RobotAccount, D21Policy, ExchangeAPIKey>().InnerJoin((r, ra, d, e) => r.Id == ra.RobotId)
.InnerJoin((r, s, ra, d, e) => r.Symbol == s.Symbol && r.ExchangeId == s.ExchangeId) .InnerJoin((r, ra, d, e) => r.Id == d.RobotId)
.InnerJoin((r, s, ra, d, e) => r.Id == d.RobotId) .InnerJoin((r, ra, d, e) => r.Id == e.RobotId)
.InnerJoin((r, s, ra, d, e) => r.Id == e.RobotId) .WhereIf(robotState != null, (r, ra, d, e) => r.State == robotState)
.WhereIf(robotState != null, (r, s, ra, d, e) => r.State == robotState) .WhereIf(signalPeriod != null, (r, ra, d, e) => d.PeriodicSignal == signalPeriod)
.WhereIf(signalPeriod != null, (r, s, ra, d, e) => d.PeriodicSignal == signalPeriod) .WhereIf(!string.IsNullOrEmpty(symbol), (r, ra, d, e) => r.Symbol == symbol)
.WhereIf(!string.IsNullOrEmpty(symbol), (r, s, ra, d, e) => r.Symbol == symbol) .Where((r, ra, d, e) => r.TradePolicy == Enums.TradePolicy.D21)
.Where((r, s, ra, d, e) => r.TradePolicy == Enums.TradePolicy.D21) .ToList((r, ra, d, e) => new Robot
.ToList((r, s, ra, d, e) => new Robot()
{ {
Id = r.Id, Id = r.Id,
BusinessType = r.BusinessType, BusinessType = r.BusinessType,
@ -218,8 +217,8 @@ namespace Binance.TradeRobot.Business
CreateTime = r.CreateTime, CreateTime = r.CreateTime,
TradePolicy = r.TradePolicy, TradePolicy = r.TradePolicy,
SymbolId = s.Id, //SymbolId = s.Id,
SymbolSaleQuantityAccuracy = s.SaleQuantityAccuracy, //SymbolSaleQuantityAccuracy = s.SaleQuantityAccuracy,
RobotAccountId = ra.Id, RobotAccountId = ra.Id,
ClosePositionCount = ra.ClosePositionCount, ClosePositionCount = ra.ClosePositionCount,
@ -249,6 +248,8 @@ namespace Binance.TradeRobot.Business
D21MaxSystemLoanRatio = d.MaxSystemLoanRatio, D21MaxSystemLoanRatio = d.MaxSystemLoanRatio,
D21CreateTime = d.CreateTime D21CreateTime = d.CreateTime
}).Map<IList<D21PolicyRobotResponse>>(); }).Map<IList<D21PolicyRobotResponse>>();
if (isLoadRecentTradeProfit) if (isLoadRecentTradeProfit)
{ {
//统计近期订单利润 //统计近期订单利润
@ -259,7 +260,6 @@ namespace Binance.TradeRobot.Business
foreach (var r in robotList) foreach (var r in robotList)
r.ExchangeAPIKey = null; r.ExchangeAPIKey = null;
} }
return robotList; return robotList;
} }
} }

12
Binance.TradeRobot.Business/Business/SingalBusiness.cs

@ -1,5 +1,6 @@
using Binance.TradeRobot.Common.DI; using Binance.TradeRobot.Common.DI;
using Binance.TradeRobot.Model.Base; using Binance.TradeRobot.Model.Base;
using Binance.TradeRobot.Model.Db;
using Binance.TradeRobot.Model.Dto; using Binance.TradeRobot.Model.Dto;
using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
@ -8,12 +9,13 @@ using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Yitter.IdGenerator; using Yitter.IdGenerator;
namespace Binance.TradeRobot.Business.Business namespace Binance.TradeRobot.Business
{ {
[BatchRegistration(ServiceLifetime.Singleton, RegistrationType.Self)] [BatchRegistration(ServiceLifetime.Singleton, RegistrationType.Self)]
public class SingalBusiness : BaseBusiness public class SingalBusiness : BaseBusiness
{ {
private RobotBusiness robotBusiness; private RobotBusiness robotBusiness;
private ExchangeBusiness exchangeBusiness;
private IEnumerable<ITradeBusiness> tradeBusinessList; private IEnumerable<ITradeBusiness> tradeBusinessList;
public SingalBusiness(IFreeSql fsql, public SingalBusiness(IFreeSql fsql,
@ -21,9 +23,11 @@ namespace Binance.TradeRobot.Business.Business
IIdGenerator idGenerator, IIdGenerator idGenerator,
IMemoryCache memoryCache, IMemoryCache memoryCache,
RobotBusiness robotBusiness, RobotBusiness robotBusiness,
ExchangeBusiness exchangeBusiness,
IEnumerable<ITradeBusiness> tradeBusinessList) : base(fsql, logManager, idGenerator, memoryCache) IEnumerable<ITradeBusiness> tradeBusinessList) : base(fsql, logManager, idGenerator, memoryCache)
{ {
this.robotBusiness = robotBusiness; this.robotBusiness = robotBusiness;
this.exchangeBusiness = exchangeBusiness;
this.tradeBusinessList = tradeBusinessList; this.tradeBusinessList = tradeBusinessList;
} }
@ -34,7 +38,9 @@ namespace Binance.TradeRobot.Business.Business
if (robotList == null || robotList.Count() == 0) if (robotList == null || robotList.Count() == 0)
throw new BusinessException("未找到符合条件的机器人"); throw new BusinessException("未找到符合条件的机器人");
//var robot = robotList.FirstOrDefault(); var symbolInfo = exchangeBusiness.GetSymbol(robotList[0].ExchangeId, robotList[0].Symbol);
if (symbolInfo == null)
throw new BusinessException($"未找到交易对{robotList[0].Symbol}({robotList[0].ExchangeId})");
var d21TradeBusiness = tradeBusinessList.FirstOrDefault(t => t.TradePolicy == Enums.TradePolicy.D21); var d21TradeBusiness = tradeBusinessList.FirstOrDefault(t => t.TradePolicy == Enums.TradePolicy.D21);
foreach (var robot in robotList) foreach (var robot in robotList)
@ -43,7 +49,7 @@ namespace Binance.TradeRobot.Business.Business
{ {
case Enums.SingalType.: case Enums.SingalType.:
case Enums.SingalType.: case Enums.SingalType.:
Task.Factory.StartNew(() => d21TradeBusiness.TrendChanged(d21SingalRequest, robot)); Task.Factory.StartNew(() => d21TradeBusiness.TrendChanged(d21SingalRequest, robot, symbolInfo));
break; break;
case Enums.SingalType.: case Enums.SingalType.:

6
Binance.TradeRobot.Business/Business/TradeBusiness/D21TradeBusiness.cs

@ -41,7 +41,7 @@ namespace Binance.TradeRobot.Business
}; };
} }
public void TrendChanged<T, T1>(T singalRequest, T1 robot) where T : BaseSingalRequest where T1 : RobotResponse public void TrendChanged<T, T1>(T singalRequest, T1 robot, SymbolInfoResponse symbolInfo) where T : BaseSingalRequest where T1 : RobotResponse
{ {
try try
{ {
@ -67,7 +67,7 @@ namespace Binance.TradeRobot.Business
} }
} }
public void LongCross<T, T1>(T singalRequest, T1 robot, bool isRemedy) where T : BaseSingalRequest where T1 : RobotResponse public void LongCross<T, T1>(T singalRequest, T1 robot, bool isRemedy, SymbolInfoResponse symbolInfo) where T : BaseSingalRequest where T1 : RobotResponse
{ {
string step = string.Empty; string step = string.Empty;
var logList = new List<ExecutionLog>(); var logList = new List<ExecutionLog>();
@ -247,7 +247,7 @@ namespace Binance.TradeRobot.Business
} }
} }
public void ShortCross<T, T1>(T singalRequest, T1 robot, bool isRemedy) where T : BaseSingalRequest where T1 : RobotResponse public void ShortCross<T, T1>(T singalRequest, T1 robot, bool isRemedy, SymbolInfoResponse symbolInfo) where T : BaseSingalRequest where T1 : RobotResponse
{ {
} }

11
Binance.TradeRobot.Business/Business/TradeBusiness/ITradeBusiness.cs

@ -14,7 +14,8 @@ namespace Binance.TradeRobot.Business
/// <typeparam name="T1"></typeparam> /// <typeparam name="T1"></typeparam>
/// <param name="singalRequest"></param> /// <param name="singalRequest"></param>
/// <param name="robot"></param> /// <param name="robot"></param>
void TrendChanged<T, T1>(T singalRequest, T1 robot) where T : BaseSingalRequest where T1 : RobotResponse; /// <param name="symbolInfo"></param>
void TrendChanged<T, T1>(T singalRequest, T1 robot, SymbolInfoResponse symbolInfo) where T : BaseSingalRequest where T1 : RobotResponse;
/// <summary> /// <summary>
/// 多交叉 /// 多交叉
@ -24,7 +25,8 @@ namespace Binance.TradeRobot.Business
/// <param name="singalRequest"></param> /// <param name="singalRequest"></param>
/// <param name="robot"></param> /// <param name="robot"></param>
/// <param name="isRemedy">是否为补救信号</param> /// <param name="isRemedy">是否为补救信号</param>
void LongCross<T, T1>(T singalRequest, T1 robot, bool isRemedy) where T : BaseSingalRequest where T1 : RobotResponse; /// <param name="symbolInfo"></param>
void LongCross<T, T1>(T singalRequest, T1 robot, bool isRemedy, SymbolInfoResponse symbolInfo) where T : BaseSingalRequest where T1 : RobotResponse;
/// <summary> /// <summary>
/// 空交叉 /// 空交叉
@ -33,7 +35,8 @@ namespace Binance.TradeRobot.Business
/// <typeparam name="T1"></typeparam> /// <typeparam name="T1"></typeparam>
/// <param name="singalRequest"></param> /// <param name="singalRequest"></param>
/// <param name="robot"></param> /// <param name="robot"></param>
/// <param name="isRemedy">是否为补救信号</param> /// <param name="isRemedy">是否为补救信号</param>'
void ShortCross<T, T1>(T singalRequest, T1 robot, bool isRemedy) where T : BaseSingalRequest where T1 : RobotResponse; /// <param name="symbolInfo"></param>
void ShortCross<T, T1>(T singalRequest, T1 robot, bool isRemedy, SymbolInfoResponse symbolInfo) where T : BaseSingalRequest where T1 : RobotResponse;
} }
} }

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

@ -26,11 +26,11 @@ namespace Binance.TradeRobot.Model.Base
.ForPath(t => t.RobotAccount.WinCount, opt => opt.MapFrom(f => f.WinCount)) .ForPath(t => t.RobotAccount.WinCount, opt => opt.MapFrom(f => f.WinCount))
.ForPath(t => t.ExchangeAPIKey.AccountId, opt => opt.MapFrom(f => f.ExchangeAccountId)) .ForPath(t => t.ExchangeAPIKey.AccountId, opt => opt.MapFrom(f => f.ExchangeAccountId))
.ForPath(t => t.ExchangeAPIKey.APIKey, opt => opt.MapFrom(f => f.ExchangeAPIKey)) .ForPath(t => t.ExchangeAPIKey.APIKey, opt => opt.MapFrom(f => f.ExchangeAPIKey))
.ForPath(t => t.ExchangeAPIKey.SecretKey, opt => opt.MapFrom(f => f.ExchangeSecretKey)) .ForPath(t => t.ExchangeAPIKey.SecretKey, opt => opt.MapFrom(f => f.ExchangeSecretKey));
.ForPath(t => t.SymbolInfo.Id, opt => opt.MapFrom(f => f.SymbolId)) //.ForPath(t => t.SymbolInfo.Id, opt => opt.MapFrom(f => f.SymbolId))
.ForPath(t => t.SymbolInfo.Symbol, opt => opt.MapFrom(f => f.Symbol)) //.ForPath(t => t.SymbolInfo.Symbol, opt => opt.MapFrom(f => f.Symbol))
.ForPath(t => t.SymbolInfo.SaleQuantityAccuracy, opt => opt.MapFrom(f => f.SymbolSaleQuantityAccuracy)) //.ForPath(t => t.SymbolInfo.SaleQuantityAccuracy, opt => opt.MapFrom(f => f.SymbolSaleQuantityAccuracy))
.ForPath(t => t.SymbolInfo.ExchangeId, opt => opt.MapFrom(f => f.ExchangeId)); //.ForPath(t => t.SymbolInfo.ExchangeId, opt => opt.MapFrom(f => f.ExchangeId));
CreateMap<Robot, D21PolicyRobotResponse>().IncludeBase<Robot, RobotResponse>() CreateMap<Robot, D21PolicyRobotResponse>().IncludeBase<Robot, RobotResponse>()
.ForPath(t => t.D21Policy.Id, opt => opt.MapFrom(f => f.D21PolicyId)) .ForPath(t => t.D21Policy.Id, opt => opt.MapFrom(f => f.D21PolicyId))
.ForPath(t => t.D21Policy.RobotId, opt => opt.MapFrom(f => f.Id)) .ForPath(t => t.D21Policy.RobotId, opt => opt.MapFrom(f => f.Id))

5
Binance.TradeRobot.Model/Binance.TradeRobot.Model.xml

@ -344,11 +344,6 @@
运行时长(s) 运行时长(s)
</summary> </summary>
</member> </member>
<member name="P:Binance.TradeRobot.Model.Db.Robot.SymbolId">
<summary>
卖币精度
</summary>
</member>
<member name="P:Binance.TradeRobot.Model.Db.Robot.ClosePositionCount"> <member name="P:Binance.TradeRobot.Model.Db.Robot.ClosePositionCount">
<summary> <summary>
平仓次数 平仓次数

2
Binance.TradeRobot.Model/Db/Exchange/SymbolInfo.cs

@ -15,7 +15,7 @@ namespace Binance.TradeRobot.Model.Db
[Column(DbType = "datetime")] [Column(DbType = "datetime")]
public DateTime? CreateTime { get; set; } public DateTime? CreateTime { get; set; }
[Column(DbType = "int", MapType = typeof(int))] [Column(MapType = typeof(int), DbType = "int")]
public Enums.Exchange ExchangeId { get; set; } public Enums.Exchange ExchangeId { get; set; }
/// <summary> /// <summary>

20
Binance.TradeRobot.Model/Db/Robot/Robot.cs

@ -36,16 +36,16 @@ namespace Binance.TradeRobot.Model.Db
[Column(MapType = typeof(int), DbType = "int")] [Column(MapType = typeof(int), DbType = "int")]
public Enums.Exchange ExchangeId { get; set; } public Enums.Exchange ExchangeId { get; set; }
#region Symbol Extension //#region Symbol Extension
/// <summary> //[Column(IsIgnore = true)]
/// 卖币精度 //public long SymbolId { get; set; }
/// </summary>
[Column(IsIgnore = true)] ///// <summary>
public long SymbolId { get; set; } ///// 卖币精度
///// </summary>
[Column(IsIgnore = true)] //[Column(IsIgnore = true)]
public int SymbolSaleQuantityAccuracy { get; set; } //public int SymbolSaleQuantityAccuracy { get; set; }
#endregion //#endregion
#region RobotAccount Extension #region RobotAccount Extension

25
SDKAdapter/APIClient/BaseAPIClient.cs

@ -67,5 +67,30 @@ namespace SDKAdapter.APIClient
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
/// <summary>
/// 逐仓杠杆下单接口
/// </summary>
/// <param name="symbol">交易对</param>
/// <param name="tradeDirection">交易方向</param>
/// <param name="orderType">订单类型</param>
/// <param name="quantity">基础币数量,卖单必传</param>
/// <param name="quoteAmount">报价币金额,市价买单必传</param>
/// <param name="price">下单价格,市价不传</param>
/// <param name="stopPrice">止损价格,与STOP_LOSS,STOP_LOSS_LIMIT一起使用</param>
/// <param name="newClientOrderId">客户端订单Id</param>
/// <returns>交易所订单Id</returns>
/// <exception cref="NotImplementedException"></exception>
public virtual long IsolatedMarginPlaceOrder(string symbol,
Enums.TradeDirection tradeDirection,
Enums.OrderType orderType,
decimal? quantity,
decimal? quoteAmount,
decimal? price,
decimal? stopPrice,
string newClientOrderId)
{
throw new NotImplementedException();
}
} }
} }

32
SDKAdapter/APIClient/BinanceAPIClient.cs

@ -1,5 +1,6 @@
using Binance.Net.Clients; using Binance.Net.Clients;
using Binance.Net.Objects; using Binance.Net.Objects;
using Binance.TradeRobot.Model.Base;
using CryptoExchange.Net.Authentication; using CryptoExchange.Net.Authentication;
using SDKAdapter.Model; using SDKAdapter.Model;
using System; using System;
@ -102,5 +103,36 @@ namespace SDKAdapter.APIClient
} }
} }
public override long IsolatedMarginPlaceOrder(string symbol,
Enums.TradeDirection tradeDirection,
Enums.OrderType orderType,
decimal? quantity,
decimal? quoteAmount,
decimal? price,
decimal? stopPrice,
string newClientOrderId)
{
var binanceOrderSite = (Binance.Net.Enums.OrderSide)(int)tradeDirection;
var binanceOrderType = (Binance.Net.Enums.SpotOrderType)(int)orderType;
Binance.Net.Enums.TimeInForce? timeInForce = null;
if (orderType == Enums.OrderType.STOP_LOSS_LIMIT)
timeInForce = Binance.Net.Enums.TimeInForce.GoodTillCanceled;
var r = binanceClient.SpotApi.Trading.PlaceMarginOrderAsync(symbol,
binanceOrderSite,
binanceOrderType,
quantity,
quoteAmount,
newClientOrderId,
price: price,
timeInForce: timeInForce,
stopPrice: stopPrice,
isIsolated: true,
orderResponseType: Binance.Net.Enums.OrderResponseType.Acknowledge).Result;
if (!r.Success)
throw new Exception($"下单失败 {orderType} {tradeDirection} {r.Error?.Message}");
return r.Data.Id;
}
} }
} }

43
SDKTestConsole/Program.cs

@ -55,7 +55,7 @@ namespace SDKTestConsole
//var r = binanceClient.SpotApi.Trading.PlaceMarginOrderAsync("ETHUSDT", //var r = binanceClient.SpotApi.Trading.PlaceMarginOrderAsync("ETHUSDT",
// Binance.Net.Enums.OrderSide.Buy, // Binance.Net.Enums.OrderSide.Buy,
// Binance.Net.Enums.SpotOrderType.Market, // Binance.Net.Enums.SpotOrderType.Market,
// quoteQuantity: 20M, //报价币金额 // quoteQuantity: 30M, //报价币金额
// //quantity: 100M, // //quantity: 100M,
// //timeInForce: Binance.Net.Enums.TimeInForce.GoodTillCanceled, // //timeInForce: Binance.Net.Enums.TimeInForce.GoodTillCanceled,
// //stopPrice: 1899M, // //stopPrice: 1899M,
@ -78,19 +78,34 @@ namespace SDKTestConsole
//止损卖币 //止损卖币
//var r = binanceClient.SpotApi.Trading.PlaceMarginOrderAsync("ETHUSDT", var r = binanceClient.SpotApi.Trading.PlaceMarginOrderAsync("ETHUSDT",
// Binance.Net.Enums.OrderSide.Sell, Binance.Net.Enums.OrderSide.Sell,
// Binance.Net.Enums.SpotOrderType.StopLossLimit, Binance.Net.Enums.SpotOrderType.StopLossLimit,
// quantity: 0.00008040M, quantity: 0.0149M,
// price: 1899M, price: 1699M,
// //quoteQuantity: 20M, //报价币金额 //quoteQuantity: 20M, //报价币金额
// //quantity: 100M, //quantity: 100M,
// timeInForce: Binance.Net.Enums.TimeInForce.GoodTillCanceled, timeInForce: Binance.Net.Enums.TimeInForce.GoodTillCanceled,
// stopPrice: 1899M, stopPrice: 1699M,
// isIsolated: true, isIsolated: true,
// orderResponseType: Binance.Net.Enums.OrderResponseType.Full).Result; orderResponseType: Binance.Net.Enums.OrderResponseType.Full).Result;
//var s = JsonConvert.SerializeObject(r);
//Console.WriteLine(s); var s = JsonConvert.SerializeObject(r);
Console.WriteLine(s);
var r1 = binanceClient.SpotApi.Trading.PlaceMarginOrderAsync("ETHUSDT",
Binance.Net.Enums.OrderSide.Sell,
Binance.Net.Enums.SpotOrderType.StopLossLimit,
quantity: 0.0149M,
price: 1699M,
//quoteQuantity: 20M, //报价币金额
//quantity: 100M,
timeInForce: Binance.Net.Enums.TimeInForce.GoodTillCanceled,
stopPrice: 1699M,
isIsolated: true,
orderResponseType: Binance.Net.Enums.OrderResponseType.Full).Result;
var s1 = JsonConvert.SerializeObject(r1);
Console.WriteLine(s1);
Console.ReadKey(); Console.ReadKey();
} }
} }

Loading…
Cancel
Save