public override ExchangeUpdateOrder UpdateOrder(ExchangeOrderResult orderCancel, ExchangeOrderRequest orderNew)
        {
            ExchangeUpdateOrder updateOrder = new ExchangeUpdateOrder();

            decimal minAmount = MinAmountWithRounding(orderNew.Price, orderNew.Symbol);

            if (orderNew.Amount < minAmount)
            {
                updateOrder.Cancel         = new ExchangeCancelOrder();
                updateOrder.Cancel.Details = orderCancel;
                updateOrder.Result         = orderCancel;
                updateOrder.ItsUpdate      = false;
                updateOrder.OptionToUpdate = false;
                return(updateOrder);
            }

            updateOrder.Cancel = CancelOrder(orderCancel);
            if (updateOrder.Cancel.Result == true & !(updateOrder.Cancel.Success == ExchangeAPIOrderResult.Filled))
            {
                if (updateOrder.Cancel.Success == ExchangeAPIOrderResult.FilledPartially) // Case of partial cancellation made partial invitation update
                {
                    decimal newAmount = updateOrder.Cancel.Details.Amount - updateOrder.Cancel.Details.AmountFilled;

                    if (newAmount >= minAmount)
                    {
                        orderNew.Amount       = newAmount;
                        updateOrder.Result    = PlaceOrder(orderNew);
                        updateOrder.ItsUpdate = true;
                    }
                    else
                    {
                        updateOrder.ItsUpdate      = false;
                        updateOrder.OptionToUpdate = false;
                        updateOrder.Result         = GetOrderDetails(orderCancel);
                    }
                }
                else
                {
                    updateOrder.Result    = PlaceOrder(orderNew);
                    updateOrder.ItsUpdate = true;
                }
            }
            else
            {
                updateOrder.ItsUpdate = false;
                updateOrder.Result    = updateOrder.Cancel.Details;
            }

            return(updateOrder);
        }
        public override ExchangeOrderResult PlaceOrder(ExchangeOrderRequest order)
        {
            string symbol = NormalizeSymbol(order.Symbol);
            Dictionary <string, object> payload = GetNoncePayload();

            payload["symbol"] = symbol;
            payload["side"]   = order.IsBuy ? "BUY" : "SELL";
            payload["type"]   = order.OrderType.ToStringUpperInvariant();

            // Binance has strict rules on which prices and quantities are allowed. They have to match the rules defined in the market definition.
            decimal outputQuantity = ClampOrderQuantity(symbol, order.Amount);
            decimal outputPrice    = ClampOrderPrice(symbol, order.Price);
            decimal outputStopPrice;

            switch (order.OrderType)
            {
            case OrderType.Limit:
                payload["timeInForce"] = "GTC";
                payload["quantity"]    = outputQuantity;
                payload["price"]       = outputPrice;
                break;

            case OrderType.Market:
                payload["quantity"] = outputQuantity;
                break;

            case OrderType.STOP_LOSS:
                payload["quantity"]  = outputQuantity;
                outputStopPrice      = ClampOrderPrice(symbol, order.StopPrice);
                payload["stopPrice"] = outputStopPrice;
                break;

            case OrderType.STOP_LOSS_LIMIT:
                payload["timeInForce"] = "GTC";
                payload["quantity"]    = outputQuantity;
                payload["price"]       = outputPrice;
                outputStopPrice        = ClampOrderPrice(symbol, order.StopPrice);
                payload["stopPrice"]   = outputStopPrice;
                break;

            case OrderType.TAKE_PROFIT:
                payload["quantity"]  = outputQuantity;
                outputStopPrice      = ClampOrderPrice(symbol, order.StopPrice);
                payload["stopPrice"] = outputStopPrice;
                break;

            case OrderType.TAKE_PROFIT_LIMIT:
                payload["timeInForce"] = "GTC";
                payload["quantity"]    = outputQuantity;
                payload["price"]       = outputPrice;
                outputStopPrice        = ClampOrderPrice(symbol, order.StopPrice);
                payload["stopPrice"]   = outputStopPrice;
                break;

            case OrderType.LIMIT_MAKER:
                payload["quantity"] = outputQuantity;
                payload["price"]    = outputPrice;
                break;
            }

            JToken token = MakeJsonRequest <JToken>("/order", BaseUrlPrivate, payload, "POST");

            CheckError(token);
            return(ParseOrder(token));
        }
Exemplo n.º 3
0
 /// <summary>
 /// ASYNC - Place an order
 /// </summary>
 /// <param name="order">The order request</param>
 /// <returns>Result</returns>
 public Task <ExchangeOrderResult> PlaceOrderAsync(ExchangeOrderRequest order) => Task.Factory.StartNew(() => PlaceOrder(order));
Exemplo n.º 4
0
 /// <summary>
 /// Update Existing order
 /// </summary>
 /// <param name="orderCancel">old order</param>
 /// <param name="orderNew">new order</param>
 /// <returns>Result Cancel</returns>
 public virtual ExchangeUpdateOrder UpdateOrder(ExchangeOrderResult orderCancel, ExchangeOrderRequest orderNew)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 5
0
 /// <summary>
 /// Place an order
 /// </summary>
 /// <param name="order">The order request</param>
 /// <returns>Result</returns>
 public virtual ExchangeOrderResult PlaceOrder(ExchangeOrderRequest order)
 {
     throw new NotImplementedException();
 }