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), }); }
private void ProcessTick(TradeInfo info) { var secId = new SecurityId { SecurityCode = info.Symbol, BoardCode = info.Exchange }; SendOutMessage(new ExecutionMessage { ExecutionType = ExecutionTypes.Tick, SecurityId = secId, ServerTime = RithmicUtils.ToTime(info.SourceSsboe, info.SourceUsecs), LocalTime = RithmicUtils.ToTime(info.Ssboe, info.Usecs), TradePrice = info.Price.ToDecimal(), Volume = info.Size, OriginSide = RithmicUtils.ToOriginSide(info.AggressorSide) }); SendOutMessage(new Level1ChangeMessage { SecurityId = secId, ServerTime = RithmicUtils.ToTime(info.Ssboe, info.Usecs), }.TryAdd(Level1Fields.Change, info.NetChange.ToDecimal())); }
private void SessionHolderOnSettlementPrice(SettlementPriceInfo info) { var price = info.Price.ToDecimal(); if (price == null) { return; } Level1Fields field; if (info.PriceType == Constants.SETTLEMENT_PRICE_TYPE_FINAL) { field = Level1Fields.SettlementPrice; } else if (info.PriceType == Constants.SETTLEMENT_PRICE_TYPE_THEORETICAL) { field = Level1Fields.TheorPrice; } else { field = Level1Fields.LastTradePrice; } SendOutMessage(new Level1ChangeMessage { SecurityId = new SecurityId { SecurityCode = info.Symbol, BoardCode = info.Exchange }, ServerTime = RithmicUtils.ToTime(info.Ssboe, info.Usecs), }.TryAdd(field, price.Value)); }
private void SessionHolderOnAccountSodUpdate(SodReport report) { ProcessAccount(report.Account); SendOutMessage(new PositionChangeMessage { PortfolioName = report.Account.AccountId, SecurityId = new SecurityId { SecurityCode = report.Symbol, BoardCode = report.Exchange, }, ServerTime = RithmicUtils.ToTime(report.Ssboe) } .Add(PositionChangeTypes.CurrentValue, (decimal)report.CarriedSize) .TryAdd(PositionChangeTypes.CurrentPrice, report.PrevClosePrice.ToDecimal())); }
private void SessionHolderOnTradeVolume(TradeVolumeInfo info) { if (!info.TotalVolumeFlag) { return; } SendOutMessage(new Level1ChangeMessage { SecurityId = new SecurityId { SecurityCode = info.Symbol, BoardCode = info.Exchange }, ServerTime = RithmicUtils.ToTime(info.Ssboe, info.Usecs), }.TryAdd(Level1Fields.LastTradeVolume, (decimal)info.TotalVolume)); }
private void ProcessRefData(RefDataInfo info, long?originalTransactionId) { SendOutMessage(new SecurityMessage { SecurityId = new SecurityId { SecurityCode = info.Symbol, BoardCode = info.Exchange, }, ExpiryDate = RithmicUtils.ToDateTime(info.Expiration, info.ExpirationTime), Currency = info.Currency.To <CurrencyTypes?>(), Strike = info.StrikePrice.ToDecimal(), OptionType = RithmicUtils.ToOptionType(info.PutCallIndicator), BinaryOptionType = info.BinaryContractType, Name = info.Description, SecurityType = RithmicUtils.ToSecurityType(info.InstrumentType), UnderlyingSecurityCode = info.Underlying, LocalTime = RithmicUtils.ToTime(info.Ssboe), Class = info.ProductCode, PriceStep = info.SinglePointValue.ToDecimal(), OriginalTransactionId = originalTransactionId ?? 0, }); }
private void SessionHolderOnTimeBar(TimeBarInfo info) { SendOutMessage(new TimeFrameCandleMessage { SecurityId = new SecurityId { SecurityCode = info.Symbol, BoardCode = info.Exchange }, OriginalTransactionId = (long?)info.Context ?? 0, OpenPrice = info.OpenPrice.ToDecimal() ?? 0, OpenVolume = info.OpenSize, HighPrice = info.HighPrice.ToDecimal() ?? 0, HighVolume = info.HighVolume, LowPrice = info.LowPrice.ToDecimal() ?? 0, LowVolume = info.LowVolume, ClosePrice = info.ClosePrice.ToDecimal() ?? 0, CloseVolume = info.CloseSize, CloseTime = RithmicUtils.ToTime(info.Ssboe), TotalTicks = info.NumTrades, UpTicks = info.HighNumTrades, DownTicks = info.LowNumTrades }); }
private void ProcessBestQuote(string symbol, string exchange, double price, int size, int numOfOrders, UpdateType updateType, int ssboe, int usecs, Level1Fields priceField, Level1Fields volumeField) { var secId = new SecurityId { SecurityCode = symbol, BoardCode = exchange }; var time = RithmicUtils.ToTime(ssboe, usecs); SendOutMessage(new Level1ChangeMessage { SecurityId = secId, ServerTime = time, } .TryAdd(priceField, price.ToDecimal()) .TryAdd(volumeField, (decimal)size)); switch (updateType) { // [gene.sato] For best bid/ask the update type does not apply. // The update type is for market depth/level 2 updates. case UpdateType.Undefined: // break; case UpdateType.Solo: { //SendOutMessage(new Level1ChangeMessage //{ // SecurityId = secId, // ServerTime = time, //} //.TryAdd(priceField, price.ToDecimal()) //.TryAdd(volumeField, (decimal)size)); break; } case UpdateType.Begin: case UpdateType.Middle: case UpdateType.Aggregated: { var pair = _quotes .SafeAdd(secId) .SafeAdd(time, key => new RefPair <BidInfo, AskInfo>()); pair.Second = new AskInfo { Price = price, NumOrders = numOfOrders, Size = size, }; break; } case UpdateType.End: FlushQuotes(secId); break; case UpdateType.Clear: break; default: throw new ArgumentOutOfRangeException(); } }
private ExecutionMessage ProcessOrderReport(OrderReport report, ExecutionMessage message) { ProcessAccount(report.Account); long transactionId; if (!long.TryParse(report.Tag, out transactionId)) { return(null); } message.PortfolioName = report.Account.AccountId; message.SecurityId = new SecurityId { SecurityCode = report.Symbol, BoardCode = report.Exchange, }; message.OrderStringId = report.OrderNum; message.OrderBoardId = report.ExchOrdId; message.OriginalTransactionId = transactionId; message.Comment = report.UserMsg; message.OrderPrice = report.PriceToFill.ToDecimal() ?? 0; message.OrderVolume = report.TotalFilled + report.TotalUnfilled; message.OrderType = RithmicUtils.ToOrderType(report.OrderType); message.Side = RithmicUtils.ToSide(report.BuySellType); message.ServerTime = RithmicUtils.ToTime(report.GatewaySsboe, report.GatewayUsecs); message.LocalTime = RithmicUtils.ToTime(report.Ssboe, report.Usecs); message.TimeInForce = RithmicUtils.ToTif(report.OrderDuration); if (report.OrderDuration == Constants.ORDER_DURATION_DAY) { message.ExpiryDate = DateTime.Today.ApplyTimeZone(TimeZoneInfo.Utc); } if (report.ReportType == Constants.REPORT_TYPE_BUST) { } else if (report.ReportType == Constants.REPORT_TYPE_CANCEL) { message.OrderState = OrderStates.Done; } else if (report.ReportType == Constants.REPORT_TYPE_COMMISSION) { message.OrderState = report.TotalUnfilled > 0 ? OrderStates.Active : OrderStates.Done; } else if (report.ReportType == Constants.REPORT_TYPE_FAILURE) { message.OrderState = OrderStates.Failed; message.Error = new InvalidOperationException(((OrderFailureReport)report).Status); } else if (report.ReportType == Constants.REPORT_TYPE_FILL) { message.OrderState = report.TotalUnfilled > 0 ? OrderStates.Active : OrderStates.Done; } else if (report.ReportType == Constants.REPORT_TYPE_MODIFY) { message.OrderState = report.TotalUnfilled > 0 ? OrderStates.Active : OrderStates.Done; } else if (report.ReportType == Constants.REPORT_TYPE_NOT_CNCLLD) { message.OrderState = OrderStates.Failed; message.Error = new InvalidOperationException(LocalizedStrings.Str3496); } else if (report.ReportType == Constants.REPORT_TYPE_NOT_MODIFIED) { message.OrderState = OrderStates.Failed; message.Error = new InvalidOperationException(LocalizedStrings.Str3497); } else if (report.ReportType == Constants.REPORT_TYPE_REJECT) { message.OrderState = OrderStates.Failed; message.Error = new InvalidOperationException(LocalizedStrings.Str3498); } else if (report.ReportType == Constants.REPORT_TYPE_SOD) { } else if (report.ReportType == Constants.REPORT_TYPE_SOD_MODIFY) { } else if (report.ReportType == Constants.REPORT_TYPE_STATUS) { message.OrderState = report.TotalUnfilled > 0 ? OrderStates.Active : OrderStates.Done; } else if (report.ReportType == Constants.REPORT_TYPE_TRADE_CORRECT) { message.OrderState = report.TotalUnfilled > 0 ? OrderStates.Active : OrderStates.Done; } else if (report.ReportType == Constants.REPORT_TYPE_TRIGGER) { } else if (report.ReportType == Constants.REPORT_TYPE_TRIGGER_PULLED) { } return(message); }
public override void OpenInterest(OpenInterestInfo info) { if (!info.QuantityFlag) { return; } _client.Level1.SafeInvoke(info.Symbol, info.Exchange, Level1Fields.OpenInterest, info.Quantity, RithmicUtils.ToTime(info.Ssboe, info.Usecs)); }
public override void ClosePrice(ClosePriceInfo info) { _receiver.AddLog(LogLevels.Debug, info.DumpableToString); _client.Level1.SafeInvoke(info.Symbol, info.Exchange, Level1Fields.ClosePrice, (decimal)info.Price, RithmicUtils.ToTime(info.Ssboe, info.Usecs)); }