|
@ -19,6 +19,9 @@ namespace SDKAdapter.WebSockets.Order.Spot |
|
|
private CancellationTokenSource cancellationTokenSource; |
|
|
private CancellationTokenSource cancellationTokenSource; |
|
|
private string listenKey; |
|
|
private string listenKey; |
|
|
private IList<Binance.Net.Enums.OrderStatus> ignoreOrderStateList; |
|
|
private IList<Binance.Net.Enums.OrderStatus> ignoreOrderStateList; |
|
|
|
|
|
private System.Threading.Timer timer; |
|
|
|
|
|
private readonly long extendListenKeyPeriod = 1000 * 60 * 30; //30分钟
|
|
|
|
|
|
private string isolateMarginSymbol = ""; //逐仓杠杆专用
|
|
|
|
|
|
|
|
|
public BinanceSpotOrderWebSocketClient(Enums.BusinessType businessType, |
|
|
public BinanceSpotOrderWebSocketClient(Enums.BusinessType businessType, |
|
|
long accountId, |
|
|
long accountId, |
|
@ -57,6 +60,8 @@ namespace SDKAdapter.WebSockets.Order.Spot |
|
|
Binance.Net.Enums.OrderStatus.Insurance, |
|
|
Binance.Net.Enums.OrderStatus.Insurance, |
|
|
Binance.Net.Enums.OrderStatus.Adl |
|
|
Binance.Net.Enums.OrderStatus.Adl |
|
|
}; |
|
|
}; |
|
|
|
|
|
timer = new Timer(new TimerCallback(ExtendListenKey), null, -1, extendListenKeyPeriod); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public override void Start(string symbol = "") |
|
|
public override void Start(string symbol = "") |
|
@ -64,8 +69,9 @@ namespace SDKAdapter.WebSockets.Order.Spot |
|
|
if (IsConnected) |
|
|
if (IsConnected) |
|
|
return; |
|
|
return; |
|
|
IsConnected = true; |
|
|
IsConnected = true; |
|
|
|
|
|
isolateMarginSymbol = symbol; |
|
|
cancellationTokenSource = new CancellationTokenSource(); |
|
|
cancellationTokenSource = new CancellationTokenSource(); |
|
|
var getListenKeyResponse = binanceClient.SpotApi.Account.StartIsolatedMarginUserStreamAsync(symbol).Result; |
|
|
var getListenKeyResponse = binanceClient.SpotApi.Account.StartIsolatedMarginUserStreamAsync(isolateMarginSymbol).Result; |
|
|
if (!getListenKeyResponse.Success) |
|
|
if (!getListenKeyResponse.Success) |
|
|
throw new Exception(getListenKeyResponse.Error?.Message ?? ""); |
|
|
throw new Exception(getListenKeyResponse.Error?.Message ?? ""); |
|
|
listenKey = getListenKeyResponse.Data; |
|
|
listenKey = getListenKeyResponse.Data; |
|
@ -169,6 +175,11 @@ namespace SDKAdapter.WebSockets.Order.Spot |
|
|
|
|
|
|
|
|
}, |
|
|
}, |
|
|
cancellationTokenSource.Token); |
|
|
cancellationTokenSource.Token); |
|
|
|
|
|
try |
|
|
|
|
|
{ |
|
|
|
|
|
timer.Change(extendListenKeyPeriod, extendListenKeyPeriod); |
|
|
|
|
|
} |
|
|
|
|
|
catch { } |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public override void Stop(string symbol = "") |
|
|
public override void Stop(string symbol = "") |
|
@ -181,6 +192,19 @@ namespace SDKAdapter.WebSockets.Order.Spot |
|
|
cancellationTokenSource = null; |
|
|
cancellationTokenSource = null; |
|
|
_ = binanceClient.SpotApi.Account.CloseIsolatedMarginUserStreamAsync(symbol, listenKey).Result; |
|
|
_ = binanceClient.SpotApi.Account.CloseIsolatedMarginUserStreamAsync(symbol, listenKey).Result; |
|
|
listenKey = string.Empty; |
|
|
listenKey = string.Empty; |
|
|
|
|
|
try |
|
|
|
|
|
{ |
|
|
|
|
|
timer.Change(-1, extendListenKeyPeriod); |
|
|
|
|
|
} |
|
|
|
|
|
catch { } |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void ExtendListenKey(object? o) |
|
|
|
|
|
{ |
|
|
|
|
|
if (string.IsNullOrEmpty(listenKey)) |
|
|
|
|
|
return; |
|
|
|
|
|
if (BusinessType == Enums.BusinessType.IsolateMargin) |
|
|
|
|
|
_ = binanceClient.SpotApi.Account.KeepAliveIsolatedMarginUserStreamAsync(isolateMarginSymbol, listenKey); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|