Exemplo n.º 1
0
 private void SrvDoExecute(string msg) // handle an order (= execute request)
 {
     if (this.InvokeRequired)
     {
         this.Invoke(new DebugDelegate(SrvDoExecute), new object[] { msg });
     }
     else
     {
         Order o = Order.Deserialize(msg);
         if (gotSrvFillRequest != null)
         {
             gotSrvFillRequest(o);                            //request fill
         }
     }
 }
Exemplo n.º 2
0
        protected override void WndProc(ref System.Windows.Forms.Message m)
        {
            long             result = 0;
            TradeLinkMessage tlm    = WMUtil.ToTradeLinkMessage(ref m);

            if (tlm == null)         // if it's not a WM_COPYDATA message
            {
                base.WndProc(ref m); // let form process it
                return;              // we're done
            }

            string msg = tlm.body;

            string[] r = msg.Split(',');
            switch (tlm.type)
            {
            case TL2.ORDERCANCELRESPONSE:
                if (gotOrderCancel != null)
                {
                    gotOrderCancel(Convert.ToUInt32(msg));
                }
                break;

            case TL2.TICKNOTIFY:
                if (Index.isIdx(r[(int)TickField.symbol]))
                {
                    // we got an index update
                    Index i = Index.Deserialize(msg);
                    if (gotIndexTick != null)
                    {
                        gotIndexTick(i);
                    }
                    break;
                }
                Tick t = Tick.Deserialize(msg);
                if (t.isTrade)
                {
                    try
                    {
                        if (t.trade > chighs[t.sym])
                        {
                            chighs[t.sym] = t.trade;
                        }
                        if (t.trade < clows[t.sym])
                        {
                            clows[t.sym] = t.trade;
                        }
                    }
                    catch (KeyNotFoundException)
                    {
                        decimal high = DayHigh(t.sym);
                        decimal low  = DayLow(t.sym);
                        chighs.Add(t.sym, high);
                        if (low == 0)
                        {
                            low = 640000;
                        }
                        clows.Add(t.sym, low);
                    }
                }
                if (gotTick != null)
                {
                    gotTick(t);
                }
                break;

            case TL2.EXECUTENOTIFY:
                // date,time,symbol,side,size,price,comment
                Trade tr = Trade.Deserialize(msg);
                try
                {
                    cpos[tr.symbol] = new Position(tr.symbol, AvgPrice(tr.symbol), PosSize(tr.symbol));
                }
                catch (KeyNotFoundException)
                {
                    cpos.Add(tr.symbol, new Position(tr.symbol, AvgPrice(tr.symbol), PosSize(tr.symbol)));
                }
                if (gotFill != null)
                {
                    gotFill(tr);
                }
                break;

            case TL2.ORDERNOTIFY:
                Order o = Order.Deserialize(msg);
                if (gotOrder != null)
                {
                    gotOrder(o);
                }
                break;

            case TL2.ACCOUNTRESPONSE:
                if (gotAccounts != null)
                {
                    gotAccounts(msg);
                }
                break;

            case TL2.FEATURERESPONSE:
                string[]   p = msg.Split(',');
                List <TL2> f = new List <TL2>();
                foreach (string s in p)
                {
                    try
                    {
                        f.Add((TL2)Convert.ToInt32(s));
                    }
                    catch (Exception) { }
                }
                if (gotSupportedFeatures != null)
                {
                    gotSupportedFeatures(f.ToArray());
                }
                break;
            }
            result   = 0;
            m.Result = (IntPtr)result;
        }