Ejemplo n.º 1
0
 public void cancelOrder()
 {
     if (ord == null) {
     if (cache != null) cache.Dispose();
     return;
       }
       DisplayOrder(ord);
       if (ord.CurrentStatus == "LIVE") {
     WriteLine("ORDER LIVE -- SUBMITTING CANCEL");
     state = State.CancelPending;
     CancelBuilder cxl = new CancelBuilder(ord);
     cache.SubmitCancel(cxl);
     ord = null;
       }
       cache.Dispose();
 }
Ejemplo n.º 2
0
 public void cancelOrder()
 {
     if (ord == null)
     {
         if (cache != null)
         {
             cache.Dispose();
         }
         return;
     }
     DisplayOrder(ord);
     if (ord.CurrentStatus == "LIVE")
     {
         WriteLine("ORDER LIVE -- SUBMITTING CANCEL");
         state = State.CancelPending;
         CancelBuilder cxl = new CancelBuilder(ord);
         cache.SubmitCancel(cxl);
         ord = null;
     }
     cache.Dispose();
 }
Ejemplo n.º 3
0
        void _bw_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            while (_bwgo)
            {
                bool newsym = false;
                while (!_newsyms.isEmpty)
                {
                    _newsyms.Read();
                    newsym = true;
                }
                if (newsym)
                {
                    // get symbols
                    _numDisplayed = 0;
                    _numIgnored   = 0;
                    debug("Subscribe request: " + _newsymlist);
                    if (!isConnected)
                    {
                        debug("not connected.");
                        return;
                    }

                    Basket b = BasketImpl.FromString(_newsymlist);
                    foreach (Security s in b)
                    {
                        try
                        {
                            TBL.WantData(TBL.TqlForBidAskTrade(s.Symbol, null), true, true);
                            TBL.Start();
                            //TT.WantData(TBL.TqlForBidAskTrade(s.Symbol, null), true, true);
                            //TT.Start();
                            _done.WaitOne(30000);
                        }
                        catch (Exception ex)
                        {
                            debug(s.Symbol + " error subscribing: " + ex.Message + ex.StackTrace);
                        }
                    }
                    debug(string.Format("DISPLAYED {0} TRADES AND IGNORED {1} QUOTES", _numDisplayed, _numIgnored));
                    debug("DONE.");
                    debug("registered: " + _newsymlist);
                }
                while (!_neworders.isEmpty)
                {
                    Order o  = _neworders.Read();
                    var   ob = new OrderBuilder(_oc);
                    ob.SetAccount(null, o.Account, null, null);
                    ob.SetBuySell(o.side ? OrderBuilder.BuySell.BUY : OrderBuilder.BuySell.SELL);
                    ob.SetExpiration(OrderBuilder.Expiration.DAY);
                    ob.SetRoute("NYS");
                    ob.SetSymbol(o.symbol, o.Exchange, OrderBuilder.SecurityType.STOCK);
                    if (o.size != 0)
                    {
                        ob.SetVolume(Math.Abs(o.size));
                    }
                    if (o.isMarket)
                    {
                        ob.SetPriceMarket();
                    }
                    if (o.isLimit)
                    {
                        ob.SetPriceLimit(new Price(o.price.ToString()));
                    }
                    if (o.isStop)
                    {
                        ob.SetPriceLimit(new Price(o.price.ToString()));
                    }
                    // ob.SetGoodFrom(DateTime.Now.AddMinutes(60));
                    currentOrderId = o.id;
                    state          = OrderState.OrderPending;
                    _oc.SubmitOrder(ob);
                }
                while (!_newcancel.isEmpty)
                {
                    long id = _newcancel.Read();
                    if (_orSet.ContainsKey(id))
                    {
                        var cxl = new CancelBuilder(_orSet[id]);
                        try
                        {
                            _oc.SubmitCancel(cxl);
                        }
                        catch (Exception ee)
                        {
                            debug("ORDER CANCEL FAILED:" + ee.Message);
                        }

                        state = OrderState.CancelPending;
                        debug("ORDER CANCEL FINISHED");
                    }
                    else
                    {
                        debug("ORDER CANCEL FAILED, NOT EXIST THE Order.Id:" + id);
                    }
                }
                if (_newcancel.isEmpty && _neworders.isEmpty && _newsyms.isEmpty)
                {
                    Thread.Sleep(_SLEEP);
                }
            }
        }
Ejemplo n.º 4
0
        void _bw_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            while (_bwgo)
            {
                bool newsym = false;
                while (!_newsyms.isEmpty)
                {
                    _newsyms.Read();
                    newsym = true;
                }
                if (newsym)
                {
                    // get symbols
                    _numDisplayed = 0;
                    _numIgnored = 0;
                    debug("Subscribe request: " + _newsymlist);
                    if (!isConnected)
                    {
                        debug("not connected.");
                        return;
                    }

                    Basket b = BasketImpl.FromString(_newsymlist);
                    foreach (Security s in b)
                    {
                        try
                        {
                            TBL.WantData(TBL.TqlForBidAskTrade(s.Symbol, null), true, true);
                            TBL.Start();
                            //TT.WantData(TBL.TqlForBidAskTrade(s.Symbol, null), true, true);
                            //TT.Start();
                            _done.WaitOne(30000);
                        }
                        catch (Exception ex)
                        {
                            debug(s.Symbol + " error subscribing: " + ex.Message + ex.StackTrace);
                        }
                    }
                    debug(string.Format("DISPLAYED {0} TRADES AND IGNORED {1} QUOTES", _numDisplayed, _numIgnored));
                    debug("DONE.");
                    debug("registered: " + _newsymlist);
                }
                while (!_neworders.isEmpty)
                {
                    Order o = _neworders.Read();
                    var ob = new OrderBuilder(_oc);
                    ob.SetAccount(null, o.Account, null, null);
                    ob.SetBuySell(o.side ? OrderBuilder.BuySell.BUY : OrderBuilder.BuySell.SELL);
                    ob.SetExpiration(OrderBuilder.Expiration.DAY);
                    ob.SetRoute("NYS");
                    ob.SetSymbol(o.symbol, o.Exchange, OrderBuilder.SecurityType.STOCK);
                    if (o.size != 0)
                        ob.SetVolume(Math.Abs(o.size));
                    if (o.isMarket)
                    {
                        ob.SetPriceMarket();
                    }
                    if (o.isLimit)
                    {
                        ob.SetPriceLimit(new Price(o.price.ToString()));
                    }
                    if (o.isStop)
                    {
                        ob.SetPriceLimit(new Price(o.price.ToString()));
                    }
                    // ob.SetGoodFrom(DateTime.Now.AddMinutes(60));
                    currentOrderId = o.id;
                    state = OrderState.OrderPending;
                    _oc.SubmitOrder(ob);
                }
                while (!_newcancel.isEmpty)
                {
                    long id = _newcancel.Read();
                    if (_orSet.ContainsKey(id))
                    {
                        var cxl = new CancelBuilder(_orSet[id]);
                        try
                        {
                            _oc.SubmitCancel(cxl);
                        }
                        catch (Exception ee)
                        {
                            debug("ORDER CANCEL FAILED:" + ee.Message);
                        }

                        state = OrderState.CancelPending;
                        debug("ORDER CANCEL FINISHED");

                    }
                    else
                    {
                        debug("ORDER CANCEL FAILED, NOT EXIST THE Order.Id:" + id);
                    }

                }
                if (_newcancel.isEmpty && _neworders.isEmpty && _newsyms.isEmpty)
                    Thread.Sleep(_SLEEP);
            }
        }