Skip to content

Commit

Permalink
Binance Fix. TimeStamp
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexWan committed Apr 4, 2018
1 parent 94ec638 commit 73fe03e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
11 changes: 6 additions & 5 deletions project/OsEngine/Market/Servers/Binance/BinanceClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -566,15 +566,16 @@ public string CreateQuery(Method method, string endpoint, Dictionary<string, str

private string GetNonce()
{
//var resTime = CreateQuery(Method.GET, "api/v1/time", null, false);
//var result = JsonConvert.DeserializeAnonymousType(resTime, new BinanceTime());
//return (result.serverTime+500).ToString();
DateTime yearBegin = new DateTime(1970, 1, 1);
var resTime = CreateQuery(Method.GET, "api/v1/time", null, false);
var result = JsonConvert.DeserializeAnonymousType(resTime, new BinanceTime());
return (result.serverTime+500).ToString();

/*DateTime yearBegin = new DateTime(1970, 1, 1);
var res = DateTime.UtcNow;
var timeStamp = DateTime.UtcNow - yearBegin;
var r = timeStamp.TotalMilliseconds;
var re = Convert.ToInt64(r);
return re.ToString();
return re.ToString();*/
}

private string CreateSignature(string message)
Expand Down
31 changes: 30 additions & 1 deletion project/OsEngine/Market/Servers/BitMex/BitMexServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1939,7 +1939,15 @@ private void ExecutorOrdersThreadArea()
{
try
{
Thread.Sleep(20);
Thread.Sleep(300);

if (_serverConnectStatus == ServerConnectStatus.Disconnect ||
_clientBitMex == null ||
_lastSystemOverload.AddSeconds(50) > DateTime.Now)
{
continue;
}

if (_ordersToExecute != null && _ordersToExecute.Count != 0)
{
Order order;
Expand Down Expand Up @@ -2003,6 +2011,11 @@ private void ExecutorOrdersThreadArea()
/// </summary>
private object _orderLocker = new object();

/// <summary>
/// время когда биржа последний раз оказалась не доступна из-за "перегрузки"
/// </summary>
private DateTime _lastSystemOverload;

/// <summary>
/// входящий из системы ордер
/// </summary>
Expand Down Expand Up @@ -2206,6 +2219,22 @@ public void CanselOrder(Order order)
private void ErrorEvent(string error)
{
SendLogMessage(error, LogMessageType.Error);

if (error ==
"{\"error\":{\"message\":\"The system is currently overloaded. Please try again later.\",\"name\":\"HTTPError\"}}")
{ // останавливаемся на минуту
_lastSystemOverload = DateTime.Now;
}
if (error == "{\"error\":{\"message\":\"Executing at order price would lead to immediate liquidation\",\"name\":\"ValidationError\"}}")
{
SendLogMessage("Цена ликвидации при таком объме выше чем текущая цена ордера. Уменьшите объём", LogMessageType.Error);
}
if (error == "{\"error\":{\"message\":\"This key is disabled.\",\"name\":\"HTTPError\"}}")
{
SendLogMessage("Биржа заблокировала Ваши ключи.", LogMessageType.System);
_serverStatusNead = ServerConnectStatus.Disconnect;
Thread.Sleep(2500);
}
}

/// <summary>
Expand Down
Binary file modified project/OsEngine/bin/Debug/OsEngine.exe
Binary file not shown.

0 comments on commit 73fe03e

Please sign in to comment.