Example #1
0
 void quote_gotImbalance(Imbalance imb)
 {
     if (gotImbalance != null)
     {
         gotImbalance(imb);
     }
 }
Example #2
0
 public void newImbalance(Imbalance imb)
 {
     for (int i = 0; i < client.Count; i++)
     {
         WMUtil.SendMsg(ImbalanceImpl.Serialize(imb), hims[i], Handle, (int)MessageTypes.IMBALANCERESPONSE);
     }
 }
Example #3
0
        public void SerializeDeserilize()
        {
            // setup imbalance
            const string s  = "IBM";
            const string e  = "NYSE";
            const int    x  = 500000;
            const int    t  = 1550;
            const int    p  = 1540;
            const int    px = 400000;
            Imbalance    i  = new ImbalanceImpl(s, e, x, t, px, p, 999);

            // verify it's valid
            Assert.IsTrue(i.isValid);

            // serialize it
            string msg = ImbalanceImpl.Serialize(i);
            // deserialize it somewhere else
            Imbalance ni = ImbalanceImpl.Deserialize(msg);

            // make sure it's valid
            Assert.IsTrue(ni.isValid);

            // verify it's the same
            Assert.AreEqual(i.Symbol, ni.Symbol);
            Assert.AreEqual(i.Exchange, ni.Exchange);
            Assert.AreEqual(i.PrevImbalance, ni.PrevImbalance);
            Assert.AreEqual(i.PrevTime, ni.PrevTime);
            Assert.AreEqual(i.ThisImbalance, ni.ThisImbalance);
            Assert.AreEqual(i.ThisTime, ni.ThisTime);
            Assert.AreEqual(i.InfoImbalance, ni.InfoImbalance);
        }
Example #4
0
 public void newImbalance(Imbalance imb)
 {
     for (int i = 0; i < client.Count; i++)
     {
         TLSend(ImbalanceImpl.Serialize(imb), MessageTypes.IMBALANCERESPONSE, i);
     }
 }
Example #5
0
        public static Imbalance[] SampleImbalanceData(int count)
        {
            Random r = new Random((int)DateTime.Now.Ticks);

            string[]    syms = TradeLink.Research.RandomSymbol.GetSymbols((int)DateTime.Now.Ticks, 4, count);
            Imbalance[] imbs = new Imbalance[syms.Length];
            for (int j = 0; j < syms.Length; j++)
            {
                imbs[j] = new ImbalanceImpl(syms[j], "NYSE", r.Next(-1000, 1000) * r.Next(1000), 1550, r.Next(-1000, 1000) * r.Next(1000), 1540, 0);
            }
            return(imbs);
        }
Example #6
0
        public static Imbalance[] SampleImbalanceData(int count)
        {
            Random r = new Random((int)DateTime.Now.Ticks);
            string[] syms = TradeLink.Research.RandomSymbol.GetSymbols((int)DateTime.Now.Ticks, 4,count);
            Imbalance[] imbs = new Imbalance[syms.Length];
            for (int j = 0; j < syms.Length; j++)
            {
                imbs[j] = new ImbalanceImpl(syms[j], "NYSE", r.Next(-1000, 1000) * r.Next(1000), 1550, r.Next(-1000, 1000) * r.Next(1000), 1540, 0);
            }
            return imbs;

        }
Example #7
0
        /// called when we receive an imbalance from the datafeed
        public override void OnImbalance(Imbalance imbalance)
        {
            // no trading morning imbalances
            if (imbalance.Time < new TimeSpan(15, 30, 00))
            {
                return;
            }

            // log any imbalances greater than 500k
            if (imbalance.NetImbalance >= 100000)
            {
                log.DebugFormat(
                    "{0:MM/dd/yyyy} {1}  Imbalance: {2}  Side: {3}  PairedVolume: {4}  Net: {5}  BuyQty: {6}  SellQty: {7}",
                    imbalance.Date, imbalance.Time, imbalance.Symbol, imbalance.Side, imbalance.PairedVolume,
                    imbalance.NetImbalance, imbalance.BuyVolume, imbalance.SellVolume);
            }

            // we're only going to trade imbalances that we've seen tick data for
            Tick tick;

            if (_ticks.TryGetValue(imbalance.Symbol, out tick))
            {
                bool hasEntered = false;
                _entered.TryGetValue(imbalance.Symbol, out hasEntered);

                if (!hasEntered &&
                    (tick.High - tick.Low > 0) &&
                    imbalance.NetImbalance >= 100000)
                {
                    if ((imbalance.Side == Imbalance.ImbSide.BUY) &&            // buy imbalance
                        (tick.Last - tick.Low) / (tick.High - tick.Low) >= .6m) // stock is in upper 60% of daily range
                    {
                        _entered[tick.Symbol] = true;
                        Order entry = new Order(OrderSide.Buy, OrderType.Market, tick.Symbol, 100);
                        Order exit  = new Order(OrderSide.Sell, OrderType.MarketOnClose, tick.Symbol, 100);
                        PlaceOrder(entry);
                        PlaceOrder(exit);
                    }
                    else if ((imbalance.Side == Imbalance.ImbSide.SELL) &&           // sell imbalance
                             (tick.Last - tick.Low) / (tick.High - tick.Low) <= .4m) // stock is in lower 40% of daily range
                    {
                        _entered[tick.Symbol] = true;
                        Order entry = new Order(OrderSide.Sell, OrderType.Market, tick.Symbol, 100);
                        Order exit  = new Order(OrderSide.Buy, OrderType.MarketOnClose, tick.Symbol, 100);
                        PlaceOrder(entry);
                        PlaceOrder(exit);
                    }
                }
            }
        }
Example #8
0
        /// called when we receive an imbalance from the datafeed
        public override void OnImbalance(Imbalance imbalance)
        {
            // no trading morning imbalances
            if (imbalance.Time < new TimeSpan(15, 30, 00))
                return;

            // log any imbalances greater than 500k
            if (imbalance.NetImbalance >= 100000)
            {
                log.DebugFormat(
                    "{0:MM/dd/yyyy} {1}  Imbalance: {2}  Side: {3}  PairedVolume: {4}  Net: {5}  BuyQty: {6}  SellQty: {7}",
                    imbalance.Date, imbalance.Time, imbalance.Symbol, imbalance.Side, imbalance.PairedVolume,
                    imbalance.NetImbalance, imbalance.BuyVolume, imbalance.SellVolume);
            }

            // we're only going to trade imbalances that we've seen tick data for
            Tick tick;
            if(_ticks.TryGetValue(imbalance.Symbol, out tick))
            {
                bool hasEntered = false;
                _entered.TryGetValue(imbalance.Symbol, out hasEntered);

                if (!hasEntered
                    && (tick.High - tick.Low > 0)
                    && imbalance.NetImbalance >= 100000)
                {
                    if((imbalance.Side == Imbalance.ImbSide.BUY)                // buy imbalance
                    && (tick.Last - tick.Low) / (tick.High - tick.Low) >= .6m)  // stock is in upper 60% of daily range
                    {
                        _entered[tick.Symbol] = true;
                        Order entry = new Order(OrderSide.Buy, OrderType.Market, tick.Symbol, 100);
                        Order exit = new Order(OrderSide.Sell, OrderType.MarketOnClose, tick.Symbol, 100);
                        PlaceOrder(entry);
                        PlaceOrder(exit);
                    }
                    else if((imbalance.Side == Imbalance.ImbSide.SELL)          // sell imbalance
                    && (tick.Last - tick.Low) / (tick.High - tick.Low) <= .4m)  // stock is in lower 40% of daily range
                    {
                        _entered[tick.Symbol] = true;
                        Order entry = new Order(OrderSide.Sell, OrderType.Market, tick.Symbol, 100);
                        Order exit = new Order(OrderSide.Buy, OrderType.MarketOnClose, tick.Symbol, 100);
                        PlaceOrder(entry);
                        PlaceOrder(exit);
                    }
                }
            }
        }
Example #9
0
        void ReadImbs()
        {
            System.Diagnostics.Debug.Write("Am I called here? Imbalance in AR");
            try
            {
                while (_readimb)
                {
                    if (_imbcache.hasItems && (GotImbalanceQueued != null))
                    {
                        GotImbalanceQueued();
                    }
                    while (_imbcache.hasItems)
                    {
                        if (!_readimb)
                        {
                            break;
                        }
                        Imbalance imb = _imbcache.Read();
                        if (imb == null)
                        {
                            _nir++;
                            if (GotBadImbalance != null)
                            {
                                GotBadImbalance();
                            }
                            continue;
                        }
                        if (GotImbalance != null)
                        {
                            GotImbalance(imb);
                        }
                    }
                    // send event that queue is presently empty
                    if (_imbcache.isEmpty && (GotImbalanceQueueEmpty != null))
                    {
                        GotImbalanceQueueEmpty();
                    }

                    // clear current flag signal
                    _imbswaiting.Reset();
                    // wait for a new signal to continue reading
                    _imbswaiting.WaitOne(SLEEP);
                }
            }
            catch (ThreadInterruptedException) { }
        }
 void ar_GotImbalance(Imbalance imb)
 {
     try
     {
         bool v = (lasti <= imb.ThisTime);
         if (!v)
         {
             iorder = false;
         }
         irecv[ic++] = imb;
         lasti       = imb.ThisTime;
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         ic++;
     }
 }
Example #11
0
 public static string Serialize(Imbalance i)
 {
     char d = ',';
     StringBuilder sb = new StringBuilder();
     sb.Append(i.Symbol);
     sb.Append(d);
     sb.Append(i.Exchange);
     sb.Append(d);
     sb.Append(i.ThisImbalance);
     sb.Append(d);
     sb.Append(i.ThisTime);
     sb.Append(d);
     sb.Append(i.PrevImbalance);
     sb.Append(d);
     sb.Append(i.PrevTime);
     sb.Append(d);
     sb.Append(i.InfoImbalance);
     return sb.ToString();
 }
Example #12
0
        public void newImbalance(Imbalance imb)
        {
            _imbcache[_writeimbs] = imb;
            _writeimbs++;
            if (_writeimbs >= _imbcache.Length)
            {
                _writeimbs = 0;
                _imbflip   = true;
            }

            if ((_readimbthread != null) && (_readimbthread.ThreadState == ThreadState.Unstarted))
            {
                _readimbthread.Start();
            }
            else if ((_readimbthread != null) && (_readimbthread.ThreadState == ThreadState.WaitSleepJoin))
            {
                // signal ReadIt thread to read now
                _imbswaiting.Set();
            }
        }
Example #13
0
        public void Performance()
        {
            const int OPS = 10000;

            Imbalance[] imbs  = SampleImbalanceData(OPS);
            DateTime    start = DateTime.Now;
            bool        v     = true;

            for (int i = 0; i < OPS; i++)
            {
                Imbalance im = ImbalanceImpl.Deserialize(ImbalanceImpl.Serialize(imbs[i]));
                v &= im.ThisImbalance == imbs[i].ThisImbalance;
            }

            double time = DateTime.Now.Subtract(start).TotalSeconds;

            Assert.IsTrue(v);
            Assert.LessOrEqual(time, .15);
            Console.WriteLine(string.Format("Imbalance performance: {0:n2} {1:n0}i/s", time, OPS / time));
        }
Example #14
0
        public static string Serialize(Imbalance i)
        {
            char          d  = ',';
            StringBuilder sb = new StringBuilder();

            sb.Append(i.Symbol);
            sb.Append(d);
            sb.Append(i.Exchange);
            sb.Append(d);
            sb.Append(i.ThisImbalance);
            sb.Append(d);
            sb.Append(i.ThisTime);
            sb.Append(d);
            sb.Append(i.PrevImbalance);
            sb.Append(d);
            sb.Append(i.PrevTime);
            sb.Append(d);
            sb.Append(i.InfoImbalance);
            return(sb.ToString());
        }
Example #15
0
 void ReadImbs()
 {
     while (true)
     {
         if (GotImbalanceQueued != null)
         {
             GotImbalanceQueued();
         }
         while (_readimbs < _imbcache.Length)
         {
             if (_readimbthread.ThreadState == ThreadState.StopRequested)
             {
                 return;
             }
             if ((_readimbs >= _writeimbs) && !_imbflip)
             {
                 break;
             }
             Imbalance imb = _imbcache[_readimbs];
             if (GotImbalance != null)
             {
                 GotImbalance(imb);
             }
             _readimbs++;
             if (_readimbs >= _imbcache.Length)
             {
                 _readimbs = 0;
                 _imbflip  = false;
             }
         }
         // send event that queue is presently empty
         if (GotImbalanceQueueEmpty != null)
         {
             GotImbalanceQueueEmpty();
         }
         // clear current flag signal
         _imbswaiting.Reset();
         // wait for a new signal to continue reading
         _imbswaiting.WaitOne(-1);
     }
 }
Example #16
0
        /// <summary>
        /// write an imbalance to buffer for later processing
        /// </summary>
        /// <param name="imb"></param>
        public void newImbalance(Imbalance imb)
        {
            if (imb == null)
            {
                _niw++;
                if (GotBadImbalance != null)
                {
                    GotBadImbalance();
                }
                return;
            }
            _imbcache.Write(imb);

            if ((_readimbthread != null) && (_readimbthread.ThreadState == ThreadState.Unstarted))
            {
                _readimb = true;
                _readimbthread.Start();
            }
            else if ((_readimbthread != null) && (_readimbthread.ThreadState == ThreadState.WaitSleepJoin))
            {
                // signal ReadIt thread to read now
                _imbswaiting.Set();
            }
        }
Example #17
0
 /// <summary>
 /// notify clients of a new imbalance
 /// </summary>
 /// <param name="imb"></param>
 public void newImbalance(Imbalance imb)
 {
 }
Example #18
0
        void handle(MessageTypes type, string msg)
        {
            long result = 0;

            switch (type)
            {
            case MessageTypes.TICKNOTIFY:
                Tick t;
                try
                {
                    _lastheartbeat = DateTime.Now.Ticks;
                    t = TickImpl.Deserialize(msg);
                }
                catch (Exception ex)
                {
                    _tickerrors++;
                    debug("Error processing tick: " + msg);
                    debug("TickErrors: " + _tickerrors);
                    debug("Error: " + ex.Message + ex.StackTrace);
                    break;
                }
                if (gotTick != null)
                {
                    gotTick(t);
                }
                break;

            case MessageTypes.IMBALANCERESPONSE:
                Imbalance i = ImbalanceImpl.Deserialize(msg);
                _lastheartbeat = DateTime.Now.Ticks;
                if (gotImbalance != null)
                {
                    gotImbalance(i);
                }
                break;

            case MessageTypes.ORDERCANCELRESPONSE:
            {
                long id = 0;
                _lastheartbeat = DateTime.Now.Ticks;
                if (gotOrderCancel != null)
                {
                    if (long.TryParse(msg, out id))
                    {
                        gotOrderCancel(id);
                    }
                    else if (SendDebugEvent != null)
                    {
                        SendDebugEvent("Count not parse order cancel: " + msg);
                    }
                }
            }
            break;

            case MessageTypes.EXECUTENOTIFY:
                _lastheartbeat = DateTime.Now.Ticks;
                // date,time,symbol,side,size,price,comment
                Trade tr = TradeImpl.Deserialize(msg);
                if (gotFill != null)
                {
                    gotFill(tr);
                }
                break;

            case MessageTypes.ORDERNOTIFY:
                _lastheartbeat = DateTime.Now.Ticks;
                Order o = OrderImpl.Deserialize(msg);
                if (gotOrder != null)
                {
                    gotOrder(o);
                }
                break;

            case MessageTypes.HEARTBEATRESPONSE:
            {
                _lastheartbeat = DateTime.Now.Ticks;
                v("got heartbeat response at: " + _lastheartbeat);
                _recvheartbeat = !_recvheartbeat;
            }
            break;

            case MessageTypes.POSITIONRESPONSE:
                try
                {
                    _lastheartbeat = DateTime.Now.Ticks;
                    Position pos = PositionImpl.Deserialize(msg);
                    if (gotPosition != null)
                    {
                        gotPosition(pos);
                    }
                }
                catch (Exception ex)
                {
                    if (SendDebugEvent != null)
                    {
                        SendDebugEvent(msg + " " + ex.Message + ex.StackTrace);
                    }
                }
                break;

            case MessageTypes.ACCOUNTRESPONSE:
                _lastheartbeat = DateTime.Now.Ticks;
                if (gotAccounts != null)
                {
                    gotAccounts(msg);
                }
                break;

            case MessageTypes.FEATURERESPONSE:
                _lastheartbeat = DateTime.Now.Ticks;
                string[]            p = msg.Split(',');
                List <MessageTypes> f = new List <MessageTypes>();
                _rfl.Clear();
                foreach (string s in p)
                {
                    try
                    {
                        MessageTypes mt = (MessageTypes)Convert.ToInt32(s);
                        f.Add(mt);
                        _rfl.Add(mt);
                    }
                    catch (Exception) { }
                }
                if (gotFeatures != null)
                {
                    gotFeatures(f.ToArray());
                }
                break;

            case MessageTypes.SERVERDOWN:
                if (gotServerDown != null)
                {
                    gotServerDown(msg);
                }
                break;

            case MessageTypes.SERVERUP:
                if (gotServerUp != null)
                {
                    gotServerUp(msg);
                }
                break;

            default:
                _lastheartbeat = DateTime.Now.Ticks;
                if (gotUnknownMessage != null)
                {
                    gotUnknownMessage(type, 0, 0, 0, string.Empty, ref msg);
                }
                break;
            }
            result = 0;
        }
Example #19
0
 public void newImbalance(Imbalance imb)
 {
     for (int i = 0; i < client.Count; i++)
         WMUtil.SendMsg(ImbalanceImpl.Serialize(imb), hims[i],Handle, (int)MessageTypes.IMBALANCERESPONSE );
 }
Example #20
0
        /// <summary>
        /// write an imbalance to buffer for later processing
        /// </summary>
        /// <param name="imb"></param>
        public void newImbalance(Imbalance imb)
        {
            if (imb == null)
            {
                _niw++;
                if (GotBadImbalance != null)
                    GotBadImbalance();
                return;
            }
            _imbcache.Write(imb);

            if ((_readimbthread != null) && (_readimbthread.ThreadState == ThreadState.Unstarted))
            {
                _readimb = true;
                _readimbthread.Start();
            }
            else if ((_readimbthread != null) && (_readimbthread.ThreadState == ThreadState.WaitSleepJoin))
            {
                // signal ReadIt thread to read now
                _imbswaiting.Set();
            }
        }
Example #21
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;

            switch (tlm.type)
            {
            case MessageTypes.TICKNOTIFY:
                Tick t;
                try
                {
                    t = TickImpl.Deserialize(msg);
                }
                catch (Exception ex)
                {
                    _tickerrors++;
                    debug("Error processing tick: " + msg);
                    debug("TickErrors: " + _tickerrors);
                    debug("Error: " + ex.Message + ex.StackTrace);
                    break;
                }
                if (gotTick != null)
                {
                    gotTick(t);
                }
                break;

            case MessageTypes.IMBALANCERESPONSE:
                Imbalance i = ImbalanceImpl.Deserialize(msg);
                if (gotImbalance != null)
                {
                    gotImbalance(i);
                }
                break;

            case MessageTypes.ORDERCANCELRESPONSE:
            {
                long id = 0;
                if (gotOrderCancel != null)
                {
                    if (long.TryParse(msg, out id))
                    {
                        gotOrderCancel(id);
                    }
                    else if (SendDebugEvent != null)
                    {
                        SendDebugEvent("Count not parse order cancel: " + msg);
                    }
                }
            }
            break;

            case MessageTypes.EXECUTENOTIFY:
                // date,time,symbol,side,size,price,comment
                try
                {
                    Trade tr = TradeImpl.Deserialize(msg);
                    if (gotFill != null)
                    {
                        gotFill(tr);
                    }
                }
                catch (Exception ex)
                {
                    debug("error deserializing fill: " + msg);
                    debug("error: " + ex.Message + ex.StackTrace);
                    debug("broker: " + BrokerName);
                }
                break;

            case MessageTypes.ORDERNOTIFY:
                try
                {
                    Order o = OrderImpl.Deserialize(msg);
                    if (gotOrder != null)
                    {
                        gotOrder(o);
                    }
                }
                catch (Exception ex)
                {
                    debug("error deserializing order: " + msg);
                    debug("error: " + ex.Message + ex.StackTrace);
                    debug("broker: " + BrokerName);
                }
                break;

            case MessageTypes.POSITIONRESPONSE:
                try
                {
                    Position pos = PositionImpl.Deserialize(msg);
                    if (gotPosition != null)
                    {
                        gotPosition(pos);
                    }
                }
                catch (Exception ex)
                {
                    if (SendDebugEvent != null)
                    {
                        SendDebugEvent(msg + " " + ex.Message + ex.StackTrace);
                    }
                }
                break;

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

            case MessageTypes.FEATURERESPONSE:
                string[]            p = msg.Split(',');
                List <MessageTypes> f = new List <MessageTypes>();
                foreach (string s in p)
                {
                    try
                    {
                        f.Add((MessageTypes)Convert.ToInt32(s));
                    }
                    catch (Exception) { }
                }
                if (gotFeatures != null)
                {
                    gotFeatures(f.ToArray());
                }
                if (gotUnknownMessage != null)
                {
                    gotUnknownMessage(tlm.type, 0, 0, 0, string.Empty, ref tlm.body);
                }
                break;

            case MessageTypes.SERVERDOWN:
                if (gotServerDown != null)
                {
                    gotServerDown(msg);
                }
                break;

            case MessageTypes.SERVERUP:
                if (gotServerUp != null)
                {
                    gotServerUp(msg);
                }
                break;

            default:
                if (gotUnknownMessage != null)
                {
                    gotUnknownMessage(tlm.type, 0, 0, 0, string.Empty, ref tlm.body);
                }
                break;
            }
            result   = 0;
            m.Result = (IntPtr)result;
        }
Example #22
0
 void quote_gotImbalance(Imbalance imb)
 {
     if (gotImbalance != null)
         gotImbalance(imb);
 }
Example #23
0
 void ar_GotImbalance(Imbalance imb)
 {
     try
     {
         bool v = (lasti <= imb.ThisTime);
         if (!v)
             iorder = false;
         irecv[ic++] = imb;
         lasti = imb.ThisTime;
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         ic++;
     }
 }
 void c_gotImbalance(Imbalance imb)
 {
     imbalances++;
 }
Example #25
0
        void tl_gotImbalance(Imbalance imb)
        {
            /*("Got Imbalance: " + imb.Symbol
                + "  THIS: " + imb.ThisImbalance
                + "  PREV: " + imb.PrevImbalance
                + "  INFO: " + imb.InfoImbalance
                + "  valid: " + imb.isValid
                + "  TIME:  " + imb.ThisTime);*/

            // reserialize and pass as a message
            string message = ImbalanceImpl.Serialize(imb);
            foreach (Response resp in _reslist)
                resp.GotMessage(MessageTypes.IMBALANCERESPONSE, 0, 0, 0, "", ref message);
        }
Example #26
0
 public void newImbalance(Imbalance imb)
 {
         for (int i = 0; i < client.Count; i++)
             TLSend(ImbalanceImpl.Serialize(imb), MessageTypes.IMBALANCERESPONSE, hims[i]);
 }
Example #27
0
        public void newImbalance(Imbalance imb)
        {
            _imbcache[_writeimbs] = imb;
            _writeimbs++;
            if (_writeimbs >= _imbcache.Length)
            {
                _writeimbs = 0;
                _imbflip = true;
            }

            if ((_readimbthread != null) && (_readimbthread.ThreadState == ThreadState.Unstarted))
                _readimbthread.Start();
            else if ((_readimbthread != null) && (_readimbthread.ThreadState == ThreadState.WaitSleepJoin))
            {
                // signal ReadIt thread to read now
                _imbswaiting.Set(); 
            }
        }
Example #28
0
 /// <summary>
 /// notify clients of a new imbalance
 /// </summary>
 /// <param name="imb"></param>
 public void newImbalance(Imbalance imb) { }
Example #29
0
 public static string Serialize(Imbalance i)
 {
     string[] r = new string[] { i.Symbol, i.Exchange, i.ThisImbalance.ToString(), i.ThisTime.ToString(), i.PrevImbalance.ToString(), i.PrevTime.ToString(), i.InfoImbalance.ToString() };
     return(string.Join(",", r));
 }
Example #30
0
 public static string Serialize(Imbalance i)
 {
     string[] r = new string[] { i.Symbol, i.Exchange, i.ThisImbalance.ToString(), i.ThisTime.ToString(), i.PrevImbalance.ToString(), i.PrevTime.ToString(),i.InfoImbalance.ToString() };
     return string.Join(",", r);
 }
Example #31
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 MessageTypes.ORDERCANCELRESPONSE:
                if (gotOrderCancel != null)
                {
                    gotOrderCancel(Convert.ToUInt32(msg));
                }
                break;

            case MessageTypes.TICKNOTIFY:
                Tick t = TickImpl.Deserialize(msg);
                if (t.isTrade)
                {
                    try
                    {
                        if (t.trade > chighs[t.symbol])
                        {
                            chighs[t.symbol] = t.trade;
                        }
                        if (t.trade < clows[t.symbol])
                        {
                            clows[t.symbol] = t.trade;
                        }
                    }
                    catch (KeyNotFoundException)
                    {
                        chighs.Add(t.symbol, 0);
                        clows.Add(t.symbol, decimal.MaxValue);
                    }
                }
                if (gotTick != null)
                {
                    gotTick(t);
                }
                break;

            case MessageTypes.EXECUTENOTIFY:
                // date,time,symbol,side,size,price,comment
                Trade tr = TradeImpl.Deserialize(msg);
                if (gotFill != null)
                {
                    gotFill(tr);
                }
                break;

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

            case MessageTypes.POSITIONRESPONSE:
                Position pos = PositionImpl.Deserialize(msg);
                if (gotPosition != null)
                {
                    gotPosition(pos);
                }
                break;

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

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

            case MessageTypes.IMBALANCERESPONSE:
                Imbalance i = ImbalanceImpl.Deserialize(msg);
                if (gotImbalance != null)
                {
                    gotImbalance(i);
                }
                break;
            }
            result   = 0;
            m.Result = (IntPtr)result;
        }
Example #32
0
 void c_gotImbalance(Imbalance imb)
 {
     imbalances++;
 }
Example #33
0
        void tl_gotImbalance(Imbalance imb)
        {
            /*("Got Imbalance: " + imb.Symbol
                + "  THIS: " + imb.ThisImbalance
                + "  PREV: " + imb.PrevImbalance
                + "  INFO: " + imb.InfoImbalance
                + "  valid: " + imb.isValid
                + "  TIME:  " + imb.ThisTime);*/

            // reserialize and pass as a message
            string message = ImbalanceImpl.Serialize(imb);
            for (int i = 0; i < _reslist.Count; i++)
            {
                if (handleresponseexception)
                {
                    try {
                        _reslist[i].GotMessage(MessageTypes.IMBALANCERESPONSE,0,0,0,"",ref message);
                    }
                    catch (Exception ex)
                    {
                        notifyresponseexception(i, imb.ThisTime, "imbalance: "+imb.ToString(), ex);
                    }
                }
                else
                    _reslist[i].GotMessage(MessageTypes.IMBALANCERESPONSE, 0, 0, 0, "", ref message);
            }
        }