예제 #1
0
        public virtual bool GotMessage(MessageTypes type, long source, long dest, long msgid, string request, ref string response)
        {
            long lv = 0;

            switch (type)
            {
            case MessageTypes.CLOSEPRICE:
            {
                if ((GotClosePrice != null) && long.TryParse(response, out lv))
                {
                    GotClosePrice(request, WMUtil.unpack(lv));
                }
                return(true);
            }

            case MessageTypes.OPENPRICE:
            {
                if ((GotOpenPrice != null) && long.TryParse(response, out lv))
                {
                    GotOpenPrice(request, WMUtil.unpack(lv));
                }
                return(true);
            }

            case MessageTypes.DAYHIGH:
            {
                if ((GotHighPrice != null) && long.TryParse(response, out lv))
                {
                    GotHighPrice(request, WMUtil.unpack(lv));
                }
                return(true);
            }

            case MessageTypes.DAYLOW:
            {
                if ((GotLowPrice != null) && long.TryParse(response, out lv))
                {
                    GotLowPrice(request, WMUtil.unpack(lv));
                }
                return(true);
            }

            case MessageTypes.NYSEDAYHIGH:
            {
                if ((GotNyseHighPrice != null) && long.TryParse(response, out lv))
                {
                    GotNyseHighPrice(request, WMUtil.unpack(lv));
                }
                return(true);
            }

            case MessageTypes.NYSEDAYLOW:
            {
                if ((GotNyseLowPrice != null) && long.TryParse(response, out lv))
                {
                    GotNyseLowPrice(request, WMUtil.unpack(lv));
                }
                return(true);
            }

            case MessageTypes.INTRADAYHIGH:
            {
                if ((GotIntraHighPrice != null) && long.TryParse(response, out lv))
                {
                    GotIntraHighPrice(request, WMUtil.unpack(lv));
                }
                return(true);
            }

            case MessageTypes.INTRADAYLOW:
            {
                if ((GotIntraLowPrice != null) && long.TryParse(response, out lv))
                {
                    GotIntraLowPrice(request, WMUtil.unpack(lv));
                }
                return(true);
            }

            case MessageTypes.BROKERNAME:
            {
                if (GotProvider != null)
                {
                    try
                    {
                        Providers p = (Providers)Enum.Parse(typeof(Providers), response);
                        GotProvider(p);
                    }
                    catch (Exception ex)
                    {
                        debug("Unknown provider: " + response);
                        debug(ex.Message + ex.StackTrace);
                        return(false);
                    }
                }
                return(true);
            }

            case MessageTypes.FEATURERESPONSE:
            {
                if (GotFeatures != null)
                {
                    string[]            r = response.Split(',');
                    List <MessageTypes> f = new List <MessageTypes>();
                    foreach (string rs in r)
                    {
                        try
                        {
                            MessageTypes mt = (MessageTypes)Enum.Parse(typeof(MessageTypes), rs);
                            f.Add(mt);
                        }
                        catch { continue; }
                    }
                    if (f.Count > 0)
                    {
                        GotFeatures(f.ToArray());
                    }
                }
                return(true);
            }

            case MessageTypes.BARRESPONSE:
            {
                try
                {
                    // get bar
                    Bar b = BarImpl.Deserialize(response);
                    // quit if bar is invalid
                    if (!b.isValid)
                    {
                        return(true);
                    }
                    // notify bar was received
                    if (GotNewBar != null)
                    {
                        GotNewBar(b.Symbol, b.Interval);
                    }
                    // update blt if desired
                    if (BLT != null)
                    {
                        // get bar list
                        BarList bl = BLT[b.Symbol, b.Interval];
                        //cjyu
                        //return if bar already exists
                        //if (BarListImpl.BarExists(bl, b))
                        //  return true;

                        // get nearest intrday bar
                        int preceed = BarListImpl.GetBarIndexPreceeding(bl, b.Bardate, b.Bartime);
                        // increment by one to get new position
                        int newpos = preceed + 1;
                        // insert bar
                        BLT[b.Symbol] = BarListImpl.InsertBar(bl, b, newpos);
                    }
                }
                catch (Exception ex)
                {
                    debug("error receiving bardata: " + response + " err: " + ex.Message + ex.StackTrace);
                    return(false);
                }
                return(true);
            }
            break;
            }
            return(false);
        }
예제 #2
0
        public virtual bool GotMessage(MessageTypes type, long source, long dest, long msgid, string request, ref string response)
        {
            long lv = 0;

            switch (type)
            {
            case MessageTypes.BARRESPONSE:
            {
                try
                {
                    // get bar
                    Bar b = BarImpl.Deserialize(response);
                    // quit if bar is invalid
                    if (!b.isValid)
                    {
                        debug(b.Symbol + " ignoring invalid bar message: " + response);
                        return(true);
                    }
                    else
                    {
                        v(b.Symbol + " got bar: " + b.ToString());
                    }
                    // notify bar was received
                    if (GotNewBar != null)
                    {
                        GotNewBar(b.Symbol, b.Interval);
                    }
                    // update blt if desired
                    if (BLT != null)
                    {
                        // get bar list
                        BarList bl = BLT[b.Symbol, b.Interval];
                        // convert to ticks
                        var barticks = BarImpl.ToTick(b);
                        // insert
                        for (int i = 0; i < barticks.Length; i++)
                        {
                            bl.newTick(barticks[i]);
                        }
                        // put it back
                        BLT[b.Symbol] = bl;
                    }
                }
                catch (Exception ex)
                {
                    debug("error receiving bardata: " + response + " err: " + ex.Message + ex.StackTrace);
                    return(false);
                }
                return(true);
            }

            case MessageTypes.CLOSEPRICE:
            {
                if ((GotClosePrice != null) && long.TryParse(response, out lv))
                {
                    GotClosePrice(request, WMUtil.unpack(lv));
                }
                return(true);
            }

            case MessageTypes.OPENPRICE:
            {
                if ((GotOpenPrice != null) && long.TryParse(response, out lv))
                {
                    GotOpenPrice(request, WMUtil.unpack(lv));
                }
                return(true);
            }

            case MessageTypes.DAYHIGH:
            {
                if ((GotHighPrice != null) && long.TryParse(response, out lv))
                {
                    GotHighPrice(request, WMUtil.unpack(lv));
                }
                return(true);
            }

            case MessageTypes.DAYLOW:
            {
                if ((GotLowPrice != null) && long.TryParse(response, out lv))
                {
                    GotLowPrice(request, WMUtil.unpack(lv));
                }
                return(true);
            }

            case MessageTypes.NYSEDAYHIGH:
            {
                if ((GotNyseHighPrice != null) && long.TryParse(response, out lv))
                {
                    GotNyseHighPrice(request, WMUtil.unpack(lv));
                }
                return(true);
            }

            case MessageTypes.NYSEDAYLOW:
            {
                if ((GotNyseLowPrice != null) && long.TryParse(response, out lv))
                {
                    GotNyseLowPrice(request, WMUtil.unpack(lv));
                }
                return(true);
            }

            case MessageTypes.INTRADAYHIGH:
            {
                if ((GotIntraHighPrice != null) && long.TryParse(response, out lv))
                {
                    GotIntraHighPrice(request, WMUtil.unpack(lv));
                }
                return(true);
            }

            case MessageTypes.INTRADAYLOW:
            {
                if ((GotIntraLowPrice != null) && long.TryParse(response, out lv))
                {
                    GotIntraLowPrice(request, WMUtil.unpack(lv));
                }
                return(true);
            }

            case MessageTypes.BROKERNAME:
            {
                if (GotProvider != null)
                {
                    try
                    {
                        Providers p = (Providers)Enum.Parse(typeof(Providers), response);
                        GotProvider(p);
                    }
                    catch (Exception ex)
                    {
                        debug("Unknown provider: " + response);
                        debug(ex.Message + ex.StackTrace);
                        return(false);
                    }
                }
                return(true);
            }

            case MessageTypes.FEATURERESPONSE:
            {
                if (GotFeatures != null)
                {
                    string[]            r = response.Split(',');
                    List <MessageTypes> f = new List <MessageTypes>();
                    foreach (string rs in r)
                    {
                        try
                        {
                            MessageTypes mt = (MessageTypes)Enum.Parse(typeof(MessageTypes), rs);
                            f.Add(mt);
                        }
                        catch { continue; }
                    }
                    if (f.Count > 0)
                    {
                        GotFeatures(f.ToArray());
                    }
                }
                return(true);
            }

            default:
                v("ignoring message: " + type + " " + request + " " + response);
                return(true);
            }
        }