Пример #1
0
        /// <summary>
        /// Получить хранилище изменений инструмента.
        /// </summary>
        /// <param name="security">Инструмент.</param>
        /// <param name="drive">Хранилище. Если значение равно <see langword="null"/>, то будет использоваться <see cref="IStorageRegistry.DefaultDrive"/>.</param>
        /// <param name="format">Тип формата. По-умолчанию передается <see cref="StorageFormats.Binary"/>.</param>
        /// <returns>Хранилище изменений инструмента.</returns>
        public IMarketDataStorage <Level1ChangeMessage> GetLevel1MessageStorage(Security security, IMarketDataDrive drive = null, StorageFormats format = StorageFormats.Binary)
        {
            if (security == null)
            {
                throw new ArgumentNullException("security");
            }

            var securityId = security.ToSecurityId();

            return(_level1Storages.SafeAdd(Tuple.Create(securityId, (drive ?? DefaultDrive).GetStorageDrive(securityId, typeof(Level1ChangeMessage), null, format)), key =>
            {
                if (security.Board == ExchangeBoard.Associated)
                {
                    return new AllSecurityMarketDataStorage <Level1ChangeMessage>(security, null, md => md.ServerTime, md => ToSecurity(md.SecurityId), (s, d) => GetLevel1MessageStorage(s, d, format), key.Item2);
                }

                IMarketDataSerializer <Level1ChangeMessage> serializer;

                switch (format)
                {
                case StorageFormats.Binary:
                    serializer = new Level1Serializer(key.Item1);
                    break;

                case StorageFormats.Csv:
                    serializer = new CsvMarketDataSerializer <Level1ChangeMessage>(key.Item1);
                    break;

                default:
                    throw new ArgumentOutOfRangeException("format");
                }

                return new Level1Storage(security, key.Item2, serializer);
            }));
        }
Пример #2
0
        /// <summary>
        /// Получить хранилище новостей.
        /// </summary>
        /// <param name="drive">Хранилище. Если значение равно <see langword="null"/>, то будет использоваться <see cref="DefaultDrive"/>.</param>
        /// <param name="format">Тип формата. По-умолчанию передается <see cref="StorageFormats.Binary"/>.</param>
        /// <returns>Хранилище новостей.</returns>
        public IMarketDataStorage <NewsMessage> GetNewsMessageStorage(IMarketDataDrive drive = null, StorageFormats format = StorageFormats.Binary)
        {
            return(_newsStorages.SafeAdd((drive ?? DefaultDrive).GetStorageDrive(_newsSecurity.ToSecurityId(), typeof(NewsMessage), null, format), key =>
            {
                IMarketDataSerializer <NewsMessage> serializer;

                switch (format)
                {
                case StorageFormats.Binary:
                    serializer = new NewsSerializer();
                    break;

                case StorageFormats.Csv:
                    serializer = new CsvMarketDataSerializer <NewsMessage>();
                    break;

                default:
                    throw new ArgumentOutOfRangeException("format");
                }

                return new NewsStorage(_newsSecurity, serializer, key);
            }));
        }
Пример #3
0
 public MarketDepthCsvSerializer(SecurityId securityId)
     : base(securityId)
 {
     _quoteSerializer = new QuoteCsvSerializer(securityId);
 }
Пример #4
0
        /// <summary>
        /// Получить хранилище транзакций для заданного инструмента.
        /// </summary>
        /// <param name="security">Инструмент.</param>
        /// <param name="type">Тип данных, информация о которых содержится <see cref="ExecutionMessage"/>.</param>
        /// <param name="drive">Хранилище. Если значение равно <see langword="null"/>, то будет использоваться <see cref="IStorageRegistry.DefaultDrive"/>.</param>
        /// <param name="format">Тип формата. По-умолчанию передается <see cref="StorageFormats.Binary"/>.</param>
        /// <returns>Хранилище транзакций.</returns>
        public IMarketDataStorage <ExecutionMessage> GetExecutionStorage(Security security, ExecutionTypes type, IMarketDataDrive drive = null, StorageFormats format = StorageFormats.Binary)
        {
            if (security == null)
            {
                throw new ArgumentNullException("security");
            }

            var securityId = security.ToSecurityId();

            return(_executionStorages.SafeAdd(Tuple.Create(securityId, type, (drive ?? DefaultDrive).GetStorageDrive(securityId, typeof(ExecutionMessage), type, format)), key =>
            {
                var secId = key.Item1;
                var mdDrive = key.Item3;

                switch (type)
                {
                case ExecutionTypes.Tick:
                    {
                        if (security is ContinuousSecurity)
                        {
                            return new ConvertableContinuousSecurityMarketDataStorage <ExecutionMessage, Trade>((ContinuousSecurity)security, null, t => t.ServerTime, t => ToSecurity(t.SecurityId), t => t.ToMessage(), t => t.Time, (s, d) => GetExecutionStorage(s, type, d, format), mdDrive);
                        }
                        else if (security is IndexSecurity)
                        {
                            return new IndexSecurityMarketDataStorage <ExecutionMessage>((IndexSecurity)security, null, d => ToSecurity(d.SecurityId), (s, d) => GetExecutionStorage(s, type, d, format), mdDrive);
                        }
                        else if (security.Board == ExchangeBoard.Associated)
                        {
                            return new ConvertableAllSecurityMarketDataStorage <ExecutionMessage, Trade>(security, null, t => t.ServerTime, t => ToSecurity(t.SecurityId), t => t.Time, (s, d) => GetExecutionStorage(s, type, d, format), mdDrive);
                        }
                        else
                        {
                            IMarketDataSerializer <ExecutionMessage> serializer;

                            switch (format)
                            {
                            case StorageFormats.Binary:
                                serializer = new TradeSerializer(key.Item1);
                                break;

                            case StorageFormats.Csv:
                                serializer = new CsvMarketDataSerializer <ExecutionMessage>(key.Item1, ExecutionTypes.Tick);
                                break;

                            default:
                                throw new ArgumentOutOfRangeException("format");
                            }

                            return new TradeStorage(security, mdDrive, serializer);
                        }
                    }

                case ExecutionTypes.Order:
                case ExecutionTypes.Trade:
                    return new ExecutionStorage(security, mdDrive, new ExecutionSerializer(secId));

                case ExecutionTypes.OrderLog:
                    {
                        IMarketDataSerializer <ExecutionMessage> serializer;

                        switch (format)
                        {
                        case StorageFormats.Binary:
                            serializer = new OrderLogSerializer(secId);
                            break;

                        case StorageFormats.Csv:
                            serializer = new CsvMarketDataSerializer <ExecutionMessage>(secId, ExecutionTypes.OrderLog);
                            break;

                        default:
                            throw new ArgumentOutOfRangeException("format");
                        }

                        return new OrderLogStorage(security, mdDrive, serializer);
                    }

                default:
                    throw new ArgumentOutOfRangeException("type");
                }
            }));
        }
Пример #5
0
 public MarketDepthCsvSerializer(SecurityId securityId)
     : base(securityId)
 {
     _quoteSerializer = new CsvMarketDataSerializer <TimeQuoteChange>(securityId);
 }