private void SessionHolderOnOrderBook(OrderBookInfo info)
        {
            if (!ProcessErrorCode(info.RpCode))
            {
                return;
            }

            SendOutMessage(new QuoteChangeMessage
            {
                SecurityId = new SecurityId
                {
                    SecurityCode = info.Symbol,
                    BoardCode    = info.Exchange ?? AssociatedBoardCode
                },
                Bids = info.Bids.Select(b => new QuoteChange(Sides.Buy, b.Price.ToDecimal() ?? 0, b.Size)
                {
                    BoardCode = b.Exchange
                }).ToArray(),
                Asks = info.Asks.Select(b => new QuoteChange(Sides.Sell, b.Price.ToDecimal() ?? 0, b.Size)
                {
                    BoardCode = b.Exchange
                }).ToArray(),
                ServerTime = RithmicUtils.ToTime(info.Ssboe, info.Usecs),
            });
        }
Exemple #2
0
        private void Handle(OrderBookInfo orderBookInfo)
        {
            if (orderBookInfo.SellLimitOrders != null && orderBookInfo.BuyLimitOrders != null)
            {
                var isValid = true;

                if (orderBookInfo.SellLimitOrders.Any() && orderBookInfo.BuyLimitOrders.Any())
                {
                    isValid = orderBookInfo.SellLimitOrders.Min(o => o.Price) >
                              orderBookInfo.BuyLimitOrders.Max(o => o.Price);
                }

                if (isValid)
                {
                    _orderBooksService.Update(new OrderBook
                    {
                        AssetPairId = orderBookInfo.AssetPairId,
                        Timestamp   = orderBookInfo.Timestamp,
                        LimitOrders = orderBookInfo.SellLimitOrders
                                      .OrderByDescending(o => o.Price)
                                      .Union(orderBookInfo.BuyLimitOrders.OrderBy(o => o.Price))
                                      .ToList()
                    });
                }
            }
        }
Exemple #3
0
        public override void LimitOrderBook(OrderBookInfo oInfo)
        {
            StringBuilder sb = new StringBuilder();

            oInfo.Dump(sb);
            Console.Out.Write(sb);
        }
Exemple #4
0
        public override void EndElement(string endElement)
        {
            if ("instrument" == endElement)
            {
                long   id   = GetLongValue(Id, 0L);
                String name = GetStringValue(Name);

                string symbol     = GetStringValue(Symbol);
                string isin       = GetStringValue(UnderlyingIsin);
                string assetClass = GetStringValue(AssetClass);

                UnderlyingInfo underlying = new UnderlyingInfo(symbol, isin, assetClass);

                DateTime         startTime   = GetDateTime(StartTime, DateTime.MinValue);
                DateTime?        expiryTime  = GetDateTime(EndTime);
                TimeSpan         openOffset  = GetTimeSpan(OpeningOffset, TimeSpan.MinValue);
                TimeSpan         closeOffset = GetTimeSpan(ClosingOffset, TimeSpan.MinValue);
                string           timeZone    = GetStringValue(Timezone);
                List <DayOfWeek> daysOfWeek  = GetDaysOfWeek();

                CalendarInfo calendarInfo = new CalendarInfo(startTime, expiryTime, openOffset, closeOffset, timeZone, daysOfWeek);

                decimal marginRate      = GetDecimalValue(Margin, 0);
                decimal maximumPosition = GetDecimalValue(MaximumPositionThreshold, 0);

                RiskInfo riskInfo = new RiskInfo(marginRate, maximumPosition);

                decimal priceIncrement           = GetDecimalValue(PriceIncrement, 0);
                decimal quantityIncrement        = GetDecimalValue(OrderQuantityIncrement, 0);
                decimal volatilityBandPercentage = GetDecimalValue(RetailVolatilityBandPercentage, 0);

                OrderBookInfo orderBookInfo = new OrderBookInfo(priceIncrement, quantityIncrement, volatilityBandPercentage);

                string  currency      = GetStringValue(Currency);
                decimal unitPrice     = GetDecimalValue(UnitPrice, 0);
                string  unitOfMeasure = GetStringValue(ContractUnitMeasure);
                decimal contractSize  = GetDecimalValue(ContractSize, 0);

                ContractInfo contractInfo = new ContractInfo(currency, unitPrice, unitOfMeasure, contractSize);

                decimal minimumCommission               = GetDecimalValue(MinimumCommission, 0);
                decimal?aggressiveCommissionRate        = GetDecimalValue(AggressiveCommisionRate);
                decimal?passiveCommissionRate           = GetDecimalValue(PassiveCommissionRate);
                decimal?aggressiveCommissionPerContract = GetDecimalValue(AggressiveCommissionPerContract);
                decimal?passiveCommissionPerContract    = GetDecimalValue(PassiveCommissionPerContract);
                string  fundingBaseRate            = GetStringValue(FundingBaseRate);
                int     dailyInterestRateBasis     = GetIntValue(DailyInteresetRateBasis, 0);
                decimal?fundingPremiumPercentage   = GetDecimalValue(FundingPremiumPercentage);
                decimal?fundingReductionPercentage = GetDecimalValue(FundingReductionPercentage);
                decimal?longSwapPoints             = GetDecimalValue(LongSwapPoints);
                decimal?shortSwapPoints            = GetDecimalValue(ShortSwapPoints);

                CommercialInfo commercialInfo = new CommercialInfo(minimumCommission, aggressiveCommissionRate, passiveCommissionRate,
                                                                   aggressiveCommissionPerContract, passiveCommissionPerContract,
                                                                   fundingBaseRate, dailyInterestRateBasis,
                                                                   fundingPremiumPercentage, fundingReductionPercentage, longSwapPoints, shortSwapPoints);

                _instruments.Add(new Instrument(id, name, underlying, calendarInfo, riskInfo, orderBookInfo, contractInfo, commercialInfo));
            }
        }
Exemple #5
0
        /*   -----------------------------------------------------------   */

        public override void LimitOrderBook(OrderBookInfo oInfo)
        {
            StringBuilder sb = new StringBuilder();

            oInfo.Dump(sb);
            debug(sb);
        }
 public Instrument(long id, string name, UnderlyingInfo underlying, CalendarInfo calendar, RiskInfo risk, OrderBookInfo orderBook, ContractInfo contract, CommercialInfo commercial)
 {
     this._id         = id;
     this._name       = name;
     this._underlying = underlying;
     this._calendar   = calendar;
     this._risk       = risk;
     this._orderBook  = orderBook;
     this._contract   = contract;
     this._commercial = commercial;
 }
Exemple #7
0
        public void Handle(string brokerId, string symbol, bool isBuy, DateTime timestamp, IReadOnlyList <LimitOrder> limitOrders)
        {
            lock (_sync)
            {
                var existed = _dirtyOrderBooks.Get(brokerId, symbol);

                if (existed != null)
                {
                    existed.Timestamp = timestamp;

                    if (isBuy)
                    {
                        existed.BuyLimitOrders = limitOrders;
                    }
                    else
                    {
                        existed.SellLimitOrders = limitOrders;
                    }

                    UpdateInOrderBookService(brokerId, existed);
                    UpdateInPricingService(brokerId, existed);
                }
                else
                {
                    var newOrderBookInfo = new OrderBookInfo
                    {
                        Symbol    = symbol,
                        Timestamp = timestamp
                    };

                    if (isBuy)
                    {
                        newOrderBookInfo.BuyLimitOrders = limitOrders;
                    }
                    else
                    {
                        newOrderBookInfo.SellLimitOrders = limitOrders;
                    }

                    _dirtyOrderBooks.Update(brokerId, symbol, newOrderBookInfo);


                    //todo: на инициализации надо сделать подругому - не надо записыват в кеш промежуточные данные, надо пройти всю инициализацию и тока потом записать в кеш все
                    // да и вообще надо отказаться от локального кеша и исползовать тока mynosql
                    UpdateInOrderBookService(brokerId, newOrderBookInfo);
                    UpdateInPricingService(brokerId, newOrderBookInfo);
                }
            }
        }
Exemple #8
0
        private void UpdateInPricingService(string brokerId, OrderBookInfo orderBookInfo)
        {
            decimal?ask = null;
            decimal?bid = null;

            if (orderBookInfo.SellLimitOrders != null && orderBookInfo.SellLimitOrders.Any())
            {
                ask = orderBookInfo.SellLimitOrders.Min(o => o.Price);
            }

            if (orderBookInfo.BuyLimitOrders != null && orderBookInfo.BuyLimitOrders.Any())
            {
                bid = orderBookInfo.BuyLimitOrders.Max(o => o.Price);
            }


            if (ask.HasValue && bid.HasValue && ask.Value <= bid.Value)
            {
                return;
            }

            _pricingService.Update(brokerId, orderBookInfo.Symbol, orderBookInfo.Timestamp, ask, bid);
        }
Exemple #9
0
        private void UpdateInOrderBookService(string brokerId, OrderBookInfo orderBookInfo)
        {
            if (orderBookInfo.SellLimitOrders != null && orderBookInfo.BuyLimitOrders != null)
            {
                var isValid = true;

                if (orderBookInfo.SellLimitOrders.Any() && orderBookInfo.BuyLimitOrders.Any())
                {
                    isValid = orderBookInfo.SellLimitOrders.Min(o => o.Price) >
                              orderBookInfo.BuyLimitOrders.Max(o => o.Price);
                }

                if (!isValid)
                {
                    return;
                }
            }

            var orders = new List <LimitOrder>();

            if (orderBookInfo.SellLimitOrders != null && orderBookInfo.SellLimitOrders.Any())
            {
                orders.AddRange(orderBookInfo.SellLimitOrders.OrderByDescending(o => o.Price));
            }

            if (orderBookInfo.BuyLimitOrders != null && orderBookInfo.BuyLimitOrders.Any())
            {
                orders.AddRange(orderBookInfo.BuyLimitOrders.OrderBy(o => o.Price));
            }

            _orderBooksService.Update(brokerId, new OrderBook
            {
                Symbol      = orderBookInfo.Symbol,
                Timestamp   = orderBookInfo.Timestamp,
                LimitOrders = orders
            });
        }
			public override void LimitOrderBook(OrderBookInfo info)
			{
				_client.OrderBook.WithDump(_receiver).WithError(MarketDataError).SafeInvoke(info);
			}
		private void SessionHolderOnOrderBook(OrderBookInfo info)
		{
			if (!ProcessErrorCode(info.RpCode))
				return;

			SendOutMessage(new QuoteChangeMessage
			{
				SecurityId = new SecurityId
				{
					SecurityCode = info.Symbol,
					BoardCode = info.Exchange ?? AssociatedBoardCode
				},
				Bids = info.Bids.Select(b => new QuoteChange(Sides.Buy, b.Price.ToDecimal() ?? 0, b.Size) { BoardCode = b.Exchange }).ToArray(),
				Asks = info.Asks.Select(b => new QuoteChange(Sides.Sell, b.Price.ToDecimal() ?? 0, b.Size) { BoardCode = b.Exchange }).ToArray(),
				ServerTime = RithmicUtils.ToTime(info.Ssboe, info.Usecs),
			});
		}
Exemple #12
0
 public override void LimitOrderBook(OrderBookInfo oInfo)
 {
 }
Exemple #13
0
 public override void LimitOrderBook(OrderBookInfo oInfo)
      {
      StringBuilder sb = new StringBuilder();
      oInfo.Dump(sb);
      Console.Out.Write(sb);
      }
Exemple #14
0
          public override void LimitOrderBook(OrderBookInfo oInfo)
               {

               }
 public override void LimitOrderBook(OrderBookInfo info)
 {
     _client.OrderBook.WithDump(_receiver).WithError(MarketDataError).SafeInvoke(info);
 }
Exemple #16
0
          /*   -----------------------------------------------------------   */

          public override void LimitOrderBook(OrderBookInfo oInfo)
               {
               StringBuilder sb = new StringBuilder();
               oInfo.Dump(sb);
               debug(sb);
               }