internal void OnMarketChange(MarketChange marketChange) { //initial image means we need to wipe our data bool isImage = marketChange.Img == true; if (marketChange.MarketDefinition != null) { //market definition changed OnMarketDefinitionChange(marketChange.MarketDefinition); } if (marketChange.Rc != null) { //runners changed foreach (RunnerChange runnerChange in marketChange.Rc) { OnPriceChange(isImage, runnerChange); } } MarketSnap newSnap = new MarketSnap(); newSnap.MarketId = MarketId; newSnap.MarketDefinition = _marketDefinition; newSnap.MarketRunners = _marketRunners.Values.Select(runner => runner.Snap).ToList(); newSnap.TradedVolume = Utils.SelectPrice(isImage, ref _tv, marketChange.Tv); Snap = newSnap; }
public override List <LimitOrder> GetOrders( MarketChange marketChange, double stake) { MarketUpdateCount += 1; LastMarketChange = marketChange; Stake = stake; return(_orders); }
public ChangeMessageStub WithMarketChange(MarketChange mc) { _change.MarketChanges ??= new List <MarketChange>(); _change.OrderChanges = null; _change.Operation = "mcm"; _change.MarketChanges.Add(mc); return(this); }
private void OnMarketChange(MarketChange marketChange, long?publishTime) { if (marketChange?.MarketId != MarketId) { return; } LastPublishedTime = publishTime; ProcessMarketChange(marketChange); }
private Market OnMarketChange(MarketChange marketChange) { if (marketChange.Con == true) { ConflatedCount++; } Market market = _markets.GetOrAdd(marketChange.Id, id => new Market(this, id)); market.OnMarketChange(marketChange); return(market); }
public SubscriptionSpy WithMarketChange(MarketChange marketChange) { var change = new ChangeMessage { Operation = "mcm", ChangeType = "mc", MarketChanges = new List <MarketChange> { marketChange }, PublishTime = PublishTime, }; Messages.Add(change); return(this); }
public void IfChangeDoesNotContainMarketDefinitionAnyPreviousMarketDefinitionShouldNotBeCleared() { var mc1 = new MarketChangeStub().WithMarketDefinition(new MarketDefinition { Venue = "Test Venue" }); var c1 = new ChangeMessageStub().WithMarketChange(mc1).Build(); _market.OnChange(c1); var mc = new MarketChange { MarketId = "1.2345" }; var c2 = _change.WithMarketChange(mc).Build(); _market.OnChange(c2); Assert.Equal("Test Venue", _market.MarketDefinition.Venue); }
private void ProcessMarketChange(MarketChange marketChange) { if (ClearCache(marketChange)) { NewCache(); } if (marketChange.MarketDefinition != null) { MarketDefinition = marketChange.MarketDefinition; } if (marketChange.TotalAmountMatched > 0) { TotalAmountMatched = marketChange.TotalAmountMatched; } ProcessRunnerChanges(marketChange.RunnerChanges); ProcessRunnerDefinitions(marketChange.MarketDefinition?.Runners); }
private void OnMarketChangeHandler(MarketDepthSocket marketDepthSocket, MarketChange marketChange) { _marketSnapshotBuilder.Build(ref marketChange); Interlocked.Increment(ref _countOfDimensions); if (AddMessageToFileLog != null) { string marketChangeType = "??"; switch (marketChange.MarketChangeType) { case MarketChangeTypeCode.AskPriceByAddedOrder: marketChangeType = "AA"; break; case MarketChangeTypeCode.AskPriceByCanceledOrder: marketChangeType = "AC"; break; case MarketChangeTypeCode.AskPriceByExecutedOrder: marketChangeType = "AE"; break; case MarketChangeTypeCode.BidPriceByAddedOrder: marketChangeType = "BA"; break; case MarketChangeTypeCode.BidPriceByCanceledOrder: marketChangeType = "BC"; break; case MarketChangeTypeCode.BidPriceByExecutedOrder: marketChangeType = "BE"; break; case MarketChangeTypeCode.BidVolumeByAddedOrder: case MarketChangeTypeCode.BuyingVolumeByAddedOrder: marketChangeType = "VABuy"; break; case MarketChangeTypeCode.BidVolumeByCanceledOrder: case MarketChangeTypeCode.BuyingVolumeByCanceledOrder: marketChangeType = "VCB"; break; case MarketChangeTypeCode.BidVolumeByExecutedOrder: marketChangeType = "VEB"; break; case MarketChangeTypeCode.BuyingVolumeInfoAdded: marketChangeType = "IVB"; break; case MarketChangeTypeCode.AskVolumeByAddedOrder: case MarketChangeTypeCode.SellingVolumeByAddedOrder: marketChangeType = "VAS"; break; case MarketChangeTypeCode.AskVolumeByCanceledOrder: case MarketChangeTypeCode.SellingVolumeByCanceledOrder: marketChangeType = "VCS"; break; case MarketChangeTypeCode.AskVolumeByExecutedOrder: marketChangeType = "VEA"; break; case MarketChangeTypeCode.SellingVolumeInfoAdded: marketChangeType = "IVS"; break; } AddMessageToFileLog?.Invoke($"{DateTime.Now.ToString("mm:ss.fff")} P={marketChange.Price.ToString("F11")} V={marketChange.Volume.ToString("F11")} {marketChangeType}{Environment.NewLine}"); } }
public abstract List <LimitOrder> GetOrders(MarketChange marketChange, double stake);
private static bool ClearCache(MarketChange marketChange) { return(marketChange.ReplaceCache != null && (bool)marketChange.ReplaceCache); }
public void Build(ref MarketChange change) { Debug.Assert(change.Price != 0, $"Price={change.Price} Volume={change.Volume} Type={change.MarketChangeType.ToString()}"); var volume = new PriceVolumePair(change.Price, change.Volume); lock (_syncRoot) { switch (change.MarketChangeType) { case MarketChangeTypeCode.BidPriceByAddedOrder: case MarketChangeTypeCode.BidPriceByExecutedOrder: case MarketChangeTypeCode.BidPriceByCanceledOrder: Debug.Assert(change.Volume != 0, $"Price={change.Price} Volume={change.Volume} Type={change.MarketChangeType.ToString()}"); if (!_bids.Add(volume)) { _bids.Remove(volume); _bids.Add(volume); } break; case MarketChangeTypeCode.AskPriceByAddedOrder: case MarketChangeTypeCode.AskPriceByExecutedOrder: case MarketChangeTypeCode.AskPriceByCanceledOrder: Debug.Assert(change.Volume != 0, $"Price={change.Price} Volume={change.Volume} Type={change.MarketChangeType.ToString()}"); if (!_asks.Add(volume)) { _asks.Remove(volume); _asks.Add(volume); } break; case MarketChangeTypeCode.BuyingVolumeByAddedOrder: case MarketChangeTypeCode.BidVolumeByExecutedOrder: case MarketChangeTypeCode.BidVolumeByAddedOrder: case MarketChangeTypeCode.BidVolumeByCanceledOrder: case MarketChangeTypeCode.BuyingVolumeByCanceledOrder: if (change.Volume == 0) { _bids.Remove(volume); } else { if (!_bids.Add(volume)) { _bids.Remove(volume); _bids.Add(volume); } } break; case MarketChangeTypeCode.SellingVolumeByAddedOrder: case MarketChangeTypeCode.AskVolumeByExecutedOrder: case MarketChangeTypeCode.AskVolumeByAddedOrder: case MarketChangeTypeCode.AskVolumeByCanceledOrder: case MarketChangeTypeCode.SellingVolumeByCanceledOrder: if (change.Volume == 0) { _asks.Remove(volume); } else { if (!_asks.Add(volume)) { _asks.Remove(volume); _asks.Add(volume); } } break; case MarketChangeTypeCode.BuyingVolumeInfoAdded: if (!_bids.Add(volume)) { _bids.Remove(volume); _bids.Add(volume); } break; case MarketChangeTypeCode.SellingVolumeInfoAdded: if (!_asks.Add(volume)) { _asks.Remove(volume); _asks.Add(volume); } break; default: throw new NotSupportedException($"Not supported type: '{change.MarketChangeType}'."); } } }
public override List <LimitOrder> GetOrders(MarketChange marketChange, double stake) { _mChange = marketChange; return(new List <LimitOrder>()); }