private void Run() { Random rnd = new Random(); Thread.Sleep(rnd.Next(100, 1500)); // dont push all orders at once BinanceClient bClient = new BinanceClient(); Spot.BinanceOrder order = bClient.PlaceMinBuyOrder(BinanceSpot.RandomSymbol()); if (order == null) { return; } Interlocked.Increment(ref workersCount); for (int i = 0; i < 50; i++) { if (!Terminated) { DoSleep(6000); bClient.CheckOrder(order); } } bClient.CancelOrder(order); Thread.Sleep(500); Interlocked.Decrement(ref workersCount); }
public void CheckOrder(Spot.BinanceOrder order) { string rawData = DoRestRequest("order", $"symbol={order.Symbol}&orderId={order.OrderId}", RequestType.GET, true); if (rawData.Contains("does not exist")) { long timeDelta = Convert.ToInt64((DateTime.UtcNow - order.CreateTime).TotalMilliseconds); Logger.ReportODN(timeDelta, $"The actually existing order (Market:{order.Symbol} id: {order.OrderId}, clientID: {order.ClientOrderId}) " + $"\n created {order.CreateTime.ToLongTimeString()} \n was reported as does not exist since {timeDelta} ms after creation!"); } }
public Spot.BinanceOrder PlaceBuyOrder(string symbol, double quantity, double price, string type = "LIMIT") { string ClientOrderID = "odn_" + RandomString(16); string rawData = DoRestRequest("order", $"symbol={symbol}&side=BUY&type={type}&quantity={Math.Round(quantity,8)}&price={Math.Round(price,8)}&timeInForce=GTC&newClientOrderId={ClientOrderID}", RequestType.POST, true); // Logger.ConsoleOut("Order: " + rawData); if (!string.IsNullOrEmpty(rawData) & (lastResult == HttpStatusCode.OK)) { Spot.BinanceOrder order = JsonConvert.DeserializeObject <Spot.BinanceOrder>(rawData); order.CreateTime = DateTime.UtcNow; return(order); } else { // Logger.ConsoleOut("req: " + $"symbol={symbol}&side=BUY&type={type}&quantity={Math.Round(quantity, 8)}&price={Math.Round(price, 8)}&timeInForce=GTC&newClientOrderId={ClientOrderID}"); CancelOrder(symbol, ClientOrderID); return(null); } }
public void CancelOrder(Spot.BinanceOrder order) { CancelOrder(order.Symbol, order.ClientOrderId); }