Esempio n. 1
0
        protected override CMState ProcessMarketDataOrderBookRequest(Wrapper wrapper)
        {
            try
            {
                MarketDataRequest mdr = MarketDataRequestConverter.GetMarketDataRequest(wrapper);

                if (mdr.SubscriptionRequestType == SubscriptionRequestType.Snapshot)
                {
                    throw new Exception(string.Format("@{0}: Market Data Order Book snaphsot not implemented for symbol {1}", BitmexConfiguration.Name, mdr.Security.Symbol));
                }
                else if (mdr.SubscriptionRequestType == SubscriptionRequestType.SnapshotAndUpdates)
                {
                    return(ProcessMarketDataRequestOrderBook(wrapper));
                }
                else if (mdr.SubscriptionRequestType == SubscriptionRequestType.Unsuscribe)
                {
                    CancelMarketDataOrderBook(mdr.Security);

                    return(CMState.BuildSuccess());
                }
                else
                {
                    throw new Exception(string.Format("@{0}: Value not recognized for subscription type {1} for symbol {2}", BitmexConfiguration.Name, mdr.SubscriptionRequestType.ToString(), mdr.Security.Symbol));
                }
            }
            catch (Exception ex)
            {
                return(CMState.BuildFail(ex));
            }
        }
Esempio n. 2
0
        protected override CMState ProcessMarketDataTradeListRequest(Wrapper wrapper)
        {
            try
            {
                MarketDataRequest mdr = MarketDataRequestConverter.GetMarketDataRequest(wrapper);

                int i = 1;
                if (mdr.SubscriptionRequestType == SubscriptionRequestType.Snapshot)
                {
                    List <zHFT.InstructionBasedMarketClient.BitMex.Common.DTO.Trade> trades = RESTMarketDataManager.GetTrades(mdr.Security.Symbol);

                    foreach (zHFT.InstructionBasedMarketClient.BitMex.Common.DTO.Trade trade in trades.Where(x => x.symbol == mdr.Security.Symbol)
                             .OrderByDescending(x => x.timestamp).Take(100).ToList())
                    {
                        BitMexTradeWrapper tradeWrapper = new BitMexTradeWrapper(trade, i == trades.Count);

                        OnMessageRcv(tradeWrapper);

                        if (i % 20 == 0)
                        {
                            Thread.Sleep(1000);
                        }

                        i++;
                    }

                    return(CMState.BuildSuccess());
                }
                else if (mdr.SubscriptionRequestType == SubscriptionRequestType.SnapshotAndUpdates)
                {
                    throw new Exception(string.Format("@{0}: Market Data trade List SnapshotAndUpdates not implemented for symbol {1}", BitmexConfiguration.Name, mdr.Security.Symbol));
                }
                else if (mdr.SubscriptionRequestType == SubscriptionRequestType.Unsuscribe)
                {
                    throw new Exception(string.Format("@{0}: Market Data trade List Unsuscribe not implemented for symbol {1}", BitmexConfiguration.Name, mdr.Security.Symbol));

                    return(CMState.BuildSuccess());
                }
                else
                {
                    throw new Exception(string.Format("@{0}: Value not recognized for subscription type {1} for symbol {2}", BitmexConfiguration.Name, mdr.SubscriptionRequestType.ToString(), mdr.Security.Symbol));
                }
            }
            catch (Exception ex)
            {
                return(CMState.BuildFail(ex));
            }
        }