Esempio n. 1
0
        public double SendWhatIfOrder(OptionData optionData, OrderAction orderAction, int quantity)
        {
            OptionData = optionData;
            try
            {
                UnlManager.RegisterForMessage(this, EapiDataTypes.OrderStatus);
                var orderData = new OrderData
                {
                    OrderType   = OrderType.MKT,
                    OrderAction = orderAction,

                    Quantity = quantity,
                    Contract = OptionData.OptionContract,
                    WhatIf   = true,
                };
                WhatIfOrderId     = APIWrapper.CreateOrder(orderData);
                orderData.OrderId = WhatIfOrderId;
                //Put the current thread into waiting state until it receives the signal
                var isSignaled = _autoResetEvent.WaitOne(TimeSpan.FromSeconds(5));
                //Thread.Sleep(5000);
                if (!isSignaled)
                {
                    var ex = new Exception("No Answer from TWS. 5 secondfs Timeout!!!");
                    Logger.Error("No Answer from TWS. 5 secondfs Timeout!!!", ex);
                    throw ex;
                }
                if (OrderStatusData.OrderStatus == OrderStatus.Filled)
                {
                    return(OrderStatusData.Margin);
                }
                var ex1 = new Exception("Send WhatIf order failed!!!");
                Logger.Error("Send WhatIf order failed!!!", ex1);
                throw ex1;
            }
            finally
            {
                UnlManager.UnRegisterForMessage(this, EapiDataTypes.OrderStatus);
                try
                {
                    _autoResetEvent.Dispose();
                }
                catch (Exception ex)
                {
                    Logger.Error("AutoResetEvent faild on Dispose()", ex);
                }
            }
        }
Esempio n. 2
0
 public void RegisterForMessage()
 {
     UnlManager.RegisterForMessage(this, DataType);
 }