public OrderRESTWS(BitMEXOrder OrderREST, TableOrder OrderWS = null)
 {
     this.OrderREST = OrderREST;
     this.OrderWS   = OrderWS;
     if (this.OrderREST != default && this.OrderWS != default && this.OrderREST.orderID != this.OrderWS.OrderID)
     {
         throw new ArgumentException();
     }
 }
Ejemplo n.º 2
0
        private Order ConvertBitMEXOrder(BitMEXOrder bitMEXOrder, int userId)
        {
            //TODO: Add checks for double values

            var order = new Order
            {
                UserId          = userId,
                Exchange        = "BitMEX",
                ExchangeOrderId = bitMEXOrder.orderID,
                Symbol          = bitMEXOrder.symbol.Substring(0, 3),
                OrderQty        = (double)bitMEXOrder.orderQty,
                Currency        = bitMEXOrder.currency,
                Price           = (double)bitMEXOrder.price,
                Timestamp       = DateTime.Parse(bitMEXOrder.timestamp),
                Side            = bitMEXOrder.side,
                IsSold          = false
            };

            return(order);
        }
        /// <summary>Создать позицию ордерами с перемещением</summary>
        /// <param name="workSymbol">Рабочий символ</param>
        /// <param name="Size">Размер</param>
        /// <returns><see langword="true"/> - создан успешно</returns>
        public bool CreateOrderAmend(string workSymbol, int Size)
        {
            if (ListOrderAmend.Count > 0)
            {
                return(false);
            }

            SideEnum side = Size.GetHand();

            if (side == SideEnum.UnKnown)
            {
                return(false);
            }

            BitMEXOrder LimitNowOrderResult = null;
            int         count = 0;

            if (IsManualPrice)
            {
                LimitNowOrderResult = bitMexREST.LimitNowOrder(workSymbol, side, Math.Abs(Size), Price);
            }
            else
            {
                do
                {
                    //if (LimitNowOrderResult != null)
                    //    Thread.Sleep(500);
                    decimal priceBest = PriceBest(side);
                    LimitNowOrderResult = bitMexREST.LimitNowOrder(workSymbol, side, Math.Abs(Size), priceBest);
                } while ((LimitNowOrderResult == null || LimitNowOrderResult.ordStatus == "Canceled") && count++ < 10);
            }

            if (LimitNowOrderResult == null || LimitNowOrderResult.ordStatus == "Canceled")
            {
                return(false);
            }

            ListOrderAmend.Add(new OrderRESTWS(LimitNowOrderResult));
            OrderAmendCommand.Invalidate();
            return(true);
        }