Exemplo n.º 1
0
        internal bool IsEmptyOrderbook(Meta.Message source, string filter, ITarget target)
        {
            bool flag2;

            if ((source.Type == Meta.TableType.Boardbooks) ? (string.Compare(this.lastOrderbookBoard, this.currentTickerBoard, StringComparison.Ordinal) == 0) : ((string.Compare(this.lastOrderbookBoard, this.currentTickerBoard, StringComparison.Ordinal) == 0) && (string.Compare(this.lastOrderbookPaper, this.currentTickerPaper, StringComparison.Ordinal) == 0)))
            {
                return(false);
            }
            Reset(ref this.lastOrderbookBoard, ref this.lastOrderbookPaper);
            this.lastOrderbookBoard = this.currentTickerBoard;
            if (source.Type == Meta.TableType.Boardbooks)
            {
                flag2 = this.fldCount < 2;
            }
            else
            {
                this.lastOrderbookPaper = this.currentTickerPaper;
                flag2 = this.fldCount <= 2;
            }
            if (target != null)
            {
                target.SwitchOrderbook(source, filter, this.lastOrderbookBoard, this.lastOrderbookPaper);
            }
            return(flag2);
        }
Exemplo n.º 2
0
        public Parser Load(string table, IDictionary <string, object> param)
        {
            IntPtr ptr;
            Parser parser;

            this.CheckClosed();
            Meta.Message source = this.market.Tables[table];
            if (source == null)
            {
                throw new ClientException(-17, "Table " + table + " is not listed");
            }
            this.CheckScales(source);
            string parameters = source.Encode(param, this.scales);
            int    code       = this.module.MTEOpenTable(this.handle, table, parameters, 1, out ptr);

            this.CheckResult(code);
            try
            {
                int structure = Marshal.ReadInt32(ptr);
                ptr += Marshal.SizeOf(structure);
                byte[] destination = new byte[structure];
                Marshal.Copy(ptr, destination, 0, structure);
                parser = TableParser.Acquire(this, source, parameters, destination);
            }
            finally
            {
                this.module.MTECloseTable(this.handle, code);
            }
            return(parser);
        }
Exemplo n.º 3
0
 private void CheckScales(Meta.Message source)
 {
     if (source.IsScaleNeeded && this.scales.Empty)
     {
         Meta.Message message = this.market.Tables.Find(Meta.TableType.Securities);
         if (message != null)
         {
             IntPtr ptr;
             string parameters = message.Encode(null, this.scales);
             int    code       = this.module.MTEOpenTable(this.handle, message.Name, parameters, 1, out ptr);
             this.CheckResult(code);
             try
             {
                 int structure = Marshal.ReadInt32(ptr);
                 ptr += Marshal.SizeOf(structure);
                 byte[] destination = new byte[structure];
                 Marshal.Copy(ptr, destination, 0, structure);
                 TableParser.Acquire(this, message, parameters, destination).Execute(null);
             }
             finally
             {
                 this.module.MTECloseTable(this.handle, code);
             }
         }
     }
 }
Exemplo n.º 4
0
        private Request CreateRequest(int handle, Meta.Message source, string filter, string marker)
        {
            Request request = new Request(this, handle, source, filter, marker);

            this.requests.Add(marker, request);
            return(request);
        }
Exemplo n.º 5
0
        protected int Parse(BinaryReader reader, Meta.Message source, string filter, ITarget target)
        {
            int num3;
            int num = reader.ReadInt32();

            Reset(ref this.currentTickerBoard, ref this.currentTickerPaper);
            Reset(ref this.lastOrderbookBoard, ref this.lastOrderbookPaper);
            if (target != null)
            {
                target.InitTableUpdate(source, filter);
            }
            try
            {
                for (int i = 0; i < num; i++)
                {
                    this.ParseRow(reader, source, filter, target);
                }
                num3 = num;
            }
            finally
            {
                if (target != null)
                {
                    target.DoneTableUpdate(source, filter);
                }
            }
            return(num3);
        }
Exemplo n.º 6
0
 internal Request(MOEX.ASTS.Client.Client client, int handle, Meta.Message source, string filter, string marker)
 {
     this.client = client;
     this.Handle = handle;
     this.Source = source;
     this.Filter = filter;
     this.marker = marker;
 }
Exemplo n.º 7
0
        protected int GetRowDecimals(Meta.Message source, ITarget target)
        {
            if (!this.hasDecimals)
            {
                if (this.isNewRow)
                {
                    if (source.Output.HasSecCode)
                    {
                        if (!this.isPartialOrderbook)
                        {
                            int numDecimal = 0;
                            if (!(source.Output.HasSecBoard ? this.client.Scales.Find(this.currentTickerBoard, this.currentTickerPaper, out numDecimal) : this.client.Scales.Find(this.currentTickerPaper, out numDecimal)))
                            {
                                //var res = this.client.Scales.Find(this.currentTickerBoard, this.currentTickerPaper, out  numDecimal);

                                // Changed 2017-05-16 ot prevent problem with unknown SECs in
                                // TradeTimes table

                                if (!target.IsNullDecimal)
                                {
                                    throw new ClientException(-16, "Trying to parse data having not loaded/parsed SECURITIES (" + this.currentTickerBoard + "." + this.currentTickerPaper + ")");
                                }
                            }
                            this.SetRowDecimals(target, numDecimal);
                            if (source.IsOrderbook)
                            {
                                this.lastOrderbookScale = numDecimal;
                            }
                        }
                        else
                        {
                            this.SetRowDecimals(target, this.lastOrderbookScale);
                        }
                    }
                    else
                    {
                        this.SetRowDecimals(target, 0);
                        if (source.IsOrderbook)
                        {
                            this.lastOrderbookScale = 0;
                        }
                    }
                }
                else
                {
                    this.SetRowDecimals(target, (target == null) ? 0 : target.GetRecordDecimals());
                }
            }
            return(this.rowDecimals);
        }
Exemplo n.º 8
0
 protected override int Parse(IBinder binder)
 {
     if ((this.sources == null) || (base.buffer == null))
     {
         return(0);
     }
     using (BinaryReader reader = new BinaryReader(new MemoryStream(base.buffer, false), Parser.Win1251))
     {
         int num = 0;
         for (int i = reader.ReadInt32(); i > 0; i--)
         {
             int          index  = reader.ReadInt32();
             Meta.Message source = this.sources[index];
             ITarget      target = (binder == null) ? null : binder.Detect(source);
             num += base.Parse(reader, source, this.filters[index], target);
         }
         return(num);
     }
 }
Exemplo n.º 9
0
        private Parser Open(string table, IDictionary <string, object> param, bool complete, byte[] snapshot, out string marker)
        {
            this.CheckClosed();
            if ((snapshot != null) && (this.module.MTEOpenTableAtSnapshot == null))
            {
                throw new ClientException(-34, "MTEOpenTableAtSnapshot() not supported");
            }
            Meta.Message source = this.market.Tables[table];
            if (source == null)
            {
                throw new ClientException(-17, "Table " + table + " is not listed");
            }
            this.CheckScales(source);
            string parameters = source.Encode(param, this.scales);

            marker = source.Name + '@' + parameters;
            if (this.GetRequest(marker) == null)
            {
                IntPtr ptr;
                int    code = (snapshot == null) ? this.module.MTEOpenTable(this.handle, table, parameters, (complete || !source.IsUpdatable) ? 1 : 0, out ptr) : this.module.MTEOpenTableAtSnapshot(this.handle, table, parameters, snapshot, snapshot.Length, out ptr);
                this.CheckResult(code);
                try
                {
                    int structure = Marshal.ReadInt32(ptr);
                    ptr += Marshal.SizeOf(structure);
                    byte[] destination = new byte[structure];
                    Marshal.Copy(ptr, destination, 0, structure);
                    return(TableParser.Acquire(this, source, parameters, destination));
                }
                finally
                {
                    if (source.IsUpdatable)
                    {
                        this.CreateRequest(code, source, parameters, marker);
                    }
                    else
                    {
                        this.module.MTECloseTable(this.handle, code);
                    }
                }
            }
            return(Parser.Empty);
        }
Exemplo n.º 10
0
        public bool Execute(string transaction, IDictionary <string, object> param, out string report)
        {
            this.CheckClosed();
            Meta.Message source = this.market.Transactions[transaction];
            if (source == null)
            {
                throw new ClientException(-17, "Transaction " + transaction + " is not listed");
            }
            this.CheckScales(source);
            string        parameters = source.Encode(param, this.scales);
            StringBuilder builder    = new StringBuilder(0x400);
            int           code       = this.module.MTEExecTrans(this.handle, transaction, parameters, builder);

            report = builder.ToString();
            if ((code != 0) && (code != -18))
            {
                this.CheckResult(code, builder);
            }
            return(code == 0);
        }
Exemplo n.º 11
0
        public Parser Refresh(Sorter sorter)
        {
            IntPtr ptr;

            this.CheckClosed();
            if (this.requests.Count == 0)
            {
                return(Parser.Empty);
            }
            IList <Request> items = this.Prepare(this.GetRequests());

            if (sorter != null)
            {
                sorter(items);
            }
            if (items.Count == 0)
            {
                return(Parser.Empty);
            }
            Meta.Message[] sources = new Meta.Message[items.Count];
            string[]       filters = new string[items.Count];
            for (int i = 0; i < items.Count; i++)
            {
                Request request = items[i];
                if (request != null)
                {
                    sources[i] = request.Source;
                    filters[i] = request.Filter;
                    this.CheckResult(this.module.MTEAddTable(this.handle, request.Handle, i));
                }
            }
            this.CheckResult(this.module.MTERefresh(this.handle, out ptr));
            int structure = Marshal.ReadInt32(ptr);

            ptr += Marshal.SizeOf(structure);
            byte[] destination = new byte[structure];
            Marshal.Copy(ptr, destination, 0, structure);
            return(MultiParser.Acquire(this, sources, filters, destination));
        }
Exemplo n.º 12
0
 internal static TableParser Acquire(MOEX.ASTS.Client.Client client, Meta.Message source, string filter, byte[] buffer)
 {
     return(new TableParser(client, source, filter, buffer));
 }
Exemplo n.º 13
0
 internal TableParser(MOEX.ASTS.Client.Client client, Meta.Message source, string filter, byte[] buffer) : base(client, buffer)
 {
     this.source = source;
     this.filter = filter;
 }
Exemplo n.º 14
0
            internal Fields(Meta.Message owner, BinaryReader reader, int version, string language, bool input, Meta.EnumTypes enumerations)
            {
                Func <Meta.Field> loader = null;

                this.keys          = new List <Meta.Field>();
                this.varBlockFirst = -1;
                if (loader == null)
                {
                    loader = () => new Meta.Field(reader, version, language, input, enumerations);
                }
                Meta.LoadItems <Meta.Field>(reader, this, loader);
                for (int i = 0; i < base.Count; i++)
                {
                    Meta.Field item = base[i];
                    item.offset = this.size;
                    this.size  += item.Size;
                    item.isKey  = owner.CanHaveKeys && ((item.flags & 1) != 0);
                    if (item.isKey)
                    {
                        this.keys.Add(item);
                        if (!input)
                        {
                            owner.maxEssentialIndex = i;
                        }
                    }
                    if ((item.flags & 8) != 0)
                    {
                        if (this.varBlockCount == 0)
                        {
                            this.varBlockFirst = i;
                            this.varBlockCount++;
                        }
                        else
                        {
                            this.varBlockCount = (1 + i) - this.varBlockFirst;
                        }
                    }
                    if (item.IsSecCode)
                    {
                        this.fldSecCode = item;
                        if (!input)
                        {
                            owner.maxEssentialIndex = i;
                        }
                        for (int j = i - 1; j >= 0; j--)
                        {
                            if (BoardFieldNames.Contains(base[j].Name))
                            {
                                this.fldSecBoard        = base[j];
                                this.fldSecBoard.flags |= 0x200;
                                break;
                            }
                        }
                    }
                    if (MarketFieldNames.Contains(item.Name))
                    {
                        item.flags      |= 0x400;
                        this.fldMarketID = item;
                    }
                    if (ScaleFieldNames.Contains(item.Name))
                    {
                        item.flags      |= 0x100;
                        this.fldDecimals = item;
                        if (!input)
                        {
                            owner.maxEssentialIndex = i;
                        }
                    }
                }
                if (this.fldDecimals == null)
                {
                    for (int k = 0; k < base.Count; k++)
                    {
                        Meta.Field field2 = base[k];
                        if ((field2.Type == Meta.FieldType.Float) && (field2.Decimals < 0))
                        {
                            owner.flags |= 0x400;
                        }
                    }
                }
            }
Exemplo n.º 15
0
        protected object ParseData(BinaryReader reader, Meta.Message source, Meta.Field field, ITarget target)
        {
            object obj2;

            if (field.IsOneChar)
            {
                obj2 = reader.ReadChar();
            }
            else if (field.CanEscape && (reader.PeekChar() == 0x23))
            {
                obj2 = null;
                reader.ReadChar();
            }
            else
            {
                int size = field.Size;
                switch (field.Type)
                {
                case Meta.FieldType.Char:
                    obj2 = Read(reader, size);
                    break;

                case Meta.FieldType.Integer:
                    Int64?nullable = null;   //KAA
                    obj2 = SToL(reader, size);

                    /*
                     * if (size <= 9)
                     * {
                     *    nullable = SToI(reader, size);
                     * }
                     * //KAA
                     * obj2 = (nullable.HasValue ? SToL(reader, size) : null);
                     * //obj2 = nullable.HasValue ? nullable. : null;
                     * //obj2 = nullable.GetValueOrDefault();
                     */
                    break;

                case Meta.FieldType.Fixed:
                    obj2 = SToF(reader, size, (byte)field.Decimals);
                    break;

                case Meta.FieldType.Float:
                    obj2 = SToF(reader, size, (byte)this.GetRowDecimals(source, target));
                    break;

                case Meta.FieldType.Date:
                    obj2 = SToI(reader, size);
                    break;

                case Meta.FieldType.Time:
                    obj2 = SToI(reader, size);
                    break;

                case Meta.FieldType.FloatPoint:
                {
                    char[] chArray = reader.ReadChars(size);
                    int    length  = chArray.Length;
                    while ((length > 0) && (chArray[length - 1] == ' '))
                    {
                        length--;
                    }
                    while ((length > 0) && (chArray[length - 1] == '0'))
                    {
                        length--;
                    }
                    if (length == 0)
                    {
                        obj2 = null;
                    }
                    else
                    {
                        decimal num3;
                        if (decimal.TryParse(new string(chArray, 0, length), NumberStyles.Float, NumberFormatInfo.InvariantInfo, out num3))
                        {
                            obj2 = num3;
                        }
                        else
                        {
                            obj2 = null;
                        }
                    }
                    break;
                }

                default:
                    obj2 = null;
                    break;
                }
            }
            if (target != null)
            {
                if (this.parseKeyPhase)
                {
                    target.SetKeyValue(field, obj2);
                    return(obj2);
                }
                target.SetFieldValue(field, obj2);
            }
            return(obj2);
        }
Exemplo n.º 16
0
        protected void ParseRow(BinaryReader reader, Meta.Message source, string filter, ITarget target)
        {
            int num4;

            this.fldCount = reader.ReadByte();
            int num = reader.ReadInt32();

            if (this.fldCount == 0)
            {
                this.fldCount = source.Output.Count;
                this.fldIndex = everything;
            }
            else
            {
                this.fldIndex = this.projection;
                for (int i = 0; i < this.fldCount; i++)
                {
                    this.fldIndex[i] = reader.ReadByte();
                }
            }
            this.isPartialOrderbook = source.IsOrderbook && (this.fldIndex[0] != 0);
            this.parseKeyPhase      = true;
            try
            {
                if ((source.maxEssentialIndex < 0) || this.isPartialOrderbook)
                {
                    this.hasDecimals = false;
                    this.rowDecimals = 0;
                }
                else
                {
                    int num3 = this.ParseKeys(reader, source, target);
                    this.hasDecimals = num3 >= 0;
                    this.rowDecimals = this.hasDecimals ? num3 : 0;
                }
            }
            finally
            {
                this.parseKeyPhase = false;
            }
            if (((source.IsOrderbook && this.IsEmptyOrderbook(source, filter, target)) || ((source.Output.IsSecNoBoard && (this.currentTickerPaper.Length > 0)) && !this.client.Scales.Find(this.currentTickerPaper, out num4))) || (num == 0))
            {
                Stream baseStream = reader.BaseStream;
                baseStream.Position += num;
            }
            else
            {
                this.isNewRow = ((target == null) || target.InitRecordUpdate(source, filter)) || source.IsOrderbook;
                try
                {
                    int num7;
                    if (this.hasDecimals)
                    {
                        if (source.Output.HasSecCode)
                        {
                            this.client.Scales.Add(this.currentTickerBoard, this.currentTickerPaper, this.rowDecimals);
                        }
                        if ((target != null) && this.isNewRow)
                        {
                            target.SetRecordDecimals(this.rowDecimals);
                        }
                    }
                    else if (this.isNewRow)
                    {
                        this.GetRowDecimals(source, target);
                    }
                    if (source.IsOrderbook)
                    {
                        if (this.isPartialOrderbook)
                        {
                            long position = reader.BaseStream.Position;
                            try
                            {
                                reader.BaseStream.Position = this.orderbookHeadPos;
                                for (int j = 0; j < this.fldIndex[0]; j++)
                                {
                                    Meta.Field field = source.Output[j];
                                    this.ParseData(reader, source, field, target);
                                }
                                goto Label_0251;
                            }
                            finally
                            {
                                reader.BaseStream.Position = position;
                            }
                        }
                        this.orderbookHeadPos = reader.BaseStream.Position;
                    }
Label_0251:
                    num7 = 0;
                    while (num7 < this.fldCount)
                    {
                        Meta.Field field2 = source.Output[this.fldIndex[num7]];
                        this.ParseData(reader, source, field2, target);
                        num7++;
                    }
                }
                finally
                {
                    if (target != null)
                    {
                        target.DoneRecordUpdate(source, filter);
                    }
                }
            }
        }
Exemplo n.º 17
0
        protected int ParseKeys(BinaryReader reader, Meta.Message source, ITarget target)
        {
            int num = -1;

            Reset(ref this.currentTickerBoard, ref this.currentTickerPaper);
            int count = source.Output.Keys.Count;

            if (source.Output.HasDecimals)
            {
                count++;
            }
            if (source.Output.HasSecBoard)
            {
                count++;
            }
            if (source.Output.HasSecCode)
            {
                count++;
            }
            if (source.Output.HasMarketID)
            {
                count++;
            }
            long position = reader.BaseStream.Position;

            try
            {
                for (int i = 0; (i < this.fldCount) && (count > 0); i++)
                {
                    int num5 = this.fldIndex[i];
                    if (num5 > source.maxEssentialIndex)
                    {
                        return(num);
                    }
                    Meta.Field field = source.Output[num5];
                    bool       isKey = field.IsKey;
                    int        size  = field.Size;
                    object     obj2  = null;
                    if (isKey)
                    {
                        count--;
                        obj2 = this.ParseData(reader, source, field, target);
                        size = 0;
                    }
                    else if (field.CanEscape && (reader.PeekChar() == 0x23))
                    {
                        reader.ReadChar();
                        size = 0;
                    }
                    switch ((field.Flags & 0xff02))
                    {
                    case 2:
                        count--;
                        this.currentTickerPaper = Convert.ToString(isKey ? obj2 : Read(reader, size));
                        break;

                    case 0x100:
                        count--;
                        num = Convert.ToInt32(isKey ? obj2 : SToI(reader, size));
                        break;

                    case 0x200:
                        count--;
                        this.currentTickerBoard = Convert.ToString(isKey ? obj2 : Read(reader, size));
                        break;

                    case 0x400:
                        count--;
                        if (!isKey)
                        {
                            Stream baseStream = reader.BaseStream;
                            baseStream.Position += size;
                        }
                        break;

                    default:
                    {
                        Stream stream2 = reader.BaseStream;
                        stream2.Position += size;
                        break;
                    }
                    }
                }
            }
            finally
            {
                reader.BaseStream.Position = position;
            }
            return(num);
        }