コード例 #1
0
    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);
    }
コード例 #2
0
    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!");
        }
    }
コード例 #3
0
    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);
        }
    }
コード例 #4
0
 public void CancelOrder(Spot.BinanceOrder order)
 {
     CancelOrder(order.Symbol, order.ClientOrderId);
 }