예제 #1
0
        public static TradeLinkMessage ToTradeLinkMessage(ref System.Windows.Forms.Message windowsmessageref)
        {
            if (windowsmessageref.Msg != WM_COPYDATA)
            {
                return(null);
            }
            TradeLinkMessage m   = new TradeLinkMessage();
            COPYDATASTRUCT   cds = new COPYDATASTRUCT();

            cds = (COPYDATASTRUCT)Marshal.PtrToStructure(windowsmessageref.LParam, typeof(COPYDATASTRUCT));
            if (cds.cbData > 0)
            {
                m.body = Marshal.PtrToStringAnsi(cds.lpData);
                m.type = (TL2)cds.dwData;
            }
            return(m);
        }
예제 #2
0
        protected override void WndProc(ref Message m)
        {
            TradeLinkMessage tlm = WMUtil.ToTradeLinkMessage(ref m);

            if (tlm == null)
            {
                base.WndProc(ref m);
                return;
            }
            string msg = tlm.body;

            long result = (long)TL2.OK;

            switch (tlm.type)
            {
            case TL2.ACCOUNTOPENPL:
                if (gotSrvAcctOpenPLRequest == null)
                {
                    break;
                }
                result = WMUtil.pack(gotSrvAcctOpenPLRequest(msg));
                break;

            case TL2.ACCOUNTCLOSEDPL:
                if (gotSrvAcctClosedPLRequest == null)
                {
                    break;
                }
                result = WMUtil.pack(gotSrvAcctClosedPLRequest(msg));
                break;

            case TL2.ACCOUNTREQUEST:
                if (gotSrvAcctRequest == null)
                {
                    break;
                }
                WMUtil.SendMsg(gotSrvAcctRequest(), TL2.ACCOUNTRESPONSE, Handle, msg);
                break;

            case TL2.ORDERCANCELREQUEST:
                if (OrderCancelRequest != null)
                {
                    OrderCancelRequest(Convert.ToUInt32(msg));
                }
                break;

            case TL2.GETSIZE:
                if (PositionSizeRequest != null)
                {
                    result = PositionSizeRequest(msg);
                }
                break;

            case TL2.AVGPRICE:
                if (PositionPriceRequest != null)
                {
                    result = WMUtil.pack(PositionPriceRequest(msg));
                }
                break;

            case TL2.NDAYHIGH:
                if (DayHighRequest != null)
                {
                    result = WMUtil.pack(DayHighRequest(msg));
                }
                break;

            case TL2.NDAYLOW:
                if (DayLowRequest != null)
                {
                    result = WMUtil.pack(DayLowRequest(msg));
                }
                break;

            case TL2.SENDORDER:
                SrvDoExecute(msg);
                break;

            case TL2.REGISTERCLIENT:
                SrvRegClient(msg);
                break;

            case TL2.REGISTERSTOCK:
                string[] m2 = msg.Split('+');
                SrvRegStocks(m2[0], m2[1]);
                break;

            case TL2.REGISTERINDEX:
                string[] ib = msg.Split('+');
                SrvRegIndex(ib[0], ib[1]);
                break;

            case TL2.CLEARCLIENT:
                SrvClearClient(msg);
                break;

            case TL2.CLEARSTOCKS:
                SrvClearStocks(msg);
                break;

            case TL2.HEARTBEAT:
                SrvBeatHeart(msg);
                break;

            case TL2.BROKERNAME:
                result = (long)Brokers.TradeLinkSimulation;
                break;

            case TL2.FEATUREREQUEST:
                TL2[]         f  = GetFeatures();
                List <string> mf = new List <string>();
                foreach (TL2 t in f)
                {
                    int ti = (int)t;
                    mf.Add(ti.ToString());
                }
                string msf = string.Join(",", mf.ToArray());
                WMUtil.SendMsg(msf, TL2.FEATURERESPONSE, Handle, msg);
                break;

            default:
                result = (long)TL2.FEATURE_NOT_IMPLEMENTED;
                break;
            }
            m.Result = (IntPtr)result;
        }
예제 #3
0
 public static TradeLinkMessage ToTradeLinkMessage(ref System.Windows.Forms.Message windowsmessageref)
 {
     if (windowsmessageref.Msg != WM_COPYDATA)
         return null;
     TradeLinkMessage m = new TradeLinkMessage();
     COPYDATASTRUCT cds = new COPYDATASTRUCT();
     cds = (COPYDATASTRUCT)Marshal.PtrToStructure(windowsmessageref.LParam, typeof(COPYDATASTRUCT));
     if (cds.cbData > 0)
     {
         m.body = Marshal.PtrToStringAnsi(cds.lpData);
         m.type = (TL2)cds.dwData;
     }
     return m;
 }
예제 #4
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;
        }