Exemplo n.º 1
0
        private void initTables()
        {
            _oc          = new OrderCache(_app);
            _oc.OnOrder += _oc_OnOrder;
            _oc.Start();
            state = OrderState.ConnectionPending;

            PST = new PositionTable(_app);
            PST.WantData(PST.TqlForPositions(), true, false);
            PST.OnPosition += PST_OnPosition;
            PST.Start();

            XPAT = new XPermsAccountsTable(_app);
            XPAT.OnXPermsAccounts += XPAT_OnXPermsAccounts;
            XPAT.WantData(XPAT.TqlForXPermsAccounts(), true, false);
            XPAT.Start();

            TBL         = new LiveQuoteTable(_app);
            TBL.OnData += TBL_OnData;

            _bw.RunWorkerAsync();

            _conn = true;
        }
Exemplo n.º 2
0
        void _oc_OnOrder(object sender, DataEventArgs <OrderRecord> e)
        {
            if (isConnected)
            {
                if (state != OrderState.ConnectionDead)
                {
                    foreach (var o in e)
                    {
                        if (o.Type == "UserSubmitOrder" && state == OrderState.OrderPending)
                        {
                            if (o.CurrentStatus == "COMPLETED")
                            {
                                var order = new OrderImpl();
                                order.id = currentOrderId;
                                long now  = Util.ToTLDate(DateTime.Now);
                                int  xsec = (int)(now % 100);
                                long rem  = (now - xsec) / 100;
                                order.time    = ((int)(rem % 10000)) * 100 + xsec;
                                order.date    = (int)((rem - order.time) / 10000);
                                order.symbol  = o.DispName;
                                order.side    = o.Buyorsell == "BUY" ? true : false;
                                order.size    = o.Volume.Value;
                                order.price   = o.Price.Value.DecimalValue;
                                order.stopp   = o.StopPrice.Value.DecimalValue;
                                order.Account = o.Deposit;
                                order.ex      = o.Exchange;
                                newOrder(order);
                                state = OrderState.OrderFinished;
                                _orSet[currentOrderId] = o;
                            }
                        }
                        if (o.Type == "ExchangeTradeOrder")
                        {
                            Trade f = new TradeImpl();
                            f.symbol  = o.DispName;
                            f.Account = o.TraderId;

                            foreach (var order in _orSet)
                            {
                                if (order.Value.OrderTag == o.OrderTag)
                                {
                                    f.id = order.Key;
                                }
                            }
                            f.xprice = o.Price.Value.DecimalValue;
                            f.xsize  = o.Volume ?? 0;
                            f.ex     = o.Exchange;
                            if (o.Buyorsell == "BUY")
                            {
                                f.side = true;
                            }
                            if (o.Buyorsell == "SALE")
                            {
                                f.side = false;
                            }
                            long now  = Util.ToTLDate(DateTime.Now);
                            int  xsec = (int)(now % 100);
                            long rem  = (now - xsec) / 100;
                            f.xtime = ((int)(rem % 10000)) * 100 + xsec;
                            f.xdate = (int)((now - f.xtime) / 1000000);
                            PST.Start();
                            pt.Adjust(f);
                            newFill(f);
                            state = OrderState.OrderFinished;
                        }

                        if (o.Type == "UserSubmitCancel" && state == OrderState.CancelPending)
                        {
                            if (o.CurrentStatus == "DELETED")
                            {
                                foreach (var order in _orSet)
                                {
                                    if (order.Value.OrderTag == o.OrderTag)
                                    {
                                        newOrderCancel(order.Key);
                                        state = OrderState.OrderFinished;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void initTables()
        {
            _oc = new OrderCache(_app);
            _oc.OnOrder += _oc_OnOrder;
            _oc.Start();
            state = OrderState.ConnectionPending;

            PST = new PositionTable(_app);
            PST.WantData(PST.TqlForPositions(), true, false);
            PST.OnPosition += PST_OnPosition;
            PST.Start();

            XPAT = new XPermsAccountsTable(_app);
            XPAT.OnXPermsAccounts += XPAT_OnXPermsAccounts;
            XPAT.WantData(XPAT.TqlForXPermsAccounts(), true, false);
            XPAT.Start();

            TBL = new LiveQuoteTable(_app);
            TBL.OnData += TBL_OnData;

            _bw.RunWorkerAsync();

            _conn = true;
        }