public SourceQuotation(PrimitiveQuotation primitiveQuotation, double ask, double bid, string instrumentCode, bool inverted) { this._PrimitiveQuotation = primitiveQuotation; this._Quotation = new GeneralQuotation(); this._Quotation.InstrumentId = primitiveQuotation.InstrumentId; this._Quotation.SourceId = primitiveQuotation.SourceId; this._Quotation.OriginCode = instrumentCode; this._Quotation.Timestamp = primitiveQuotation.Timestamp; this._Quotation.Ask = ask; this._Quotation.Bid = bid; double price; if (PrimitiveQuotation.TryGetPriceValue(primitiveQuotation.Last, out price)) this._Quotation.Last = price; if (PrimitiveQuotation.TryGetPriceValue(primitiveQuotation.High, out price)) this._Quotation.High = price; if (PrimitiveQuotation.TryGetPriceValue(primitiveQuotation.Low, out price)) this._Quotation.Low = price; if (inverted) { this._Quotation.Ask = 1 / this._Quotation.Ask; this._Quotation.Bid = 1 / this._Quotation.Bid; if (this._Quotation.Last.HasValue) this._Quotation.Last = 1 / this._Quotation.Last; if (this._Quotation.High.HasValue) this._Quotation.High = 1 / this._Quotation.High; if (this._Quotation.Low.HasValue) this._Quotation.Low = 1 / this._Quotation.Low; } }
public void ProcessQuotation(PrimitiveQuotation primitiveQuotation) { Manager.ClientManager.Dispatch(new PrimitiveQuotationMessage() { Quotation = primitiveQuotation }); if (this._ConfigMetadata.IsFromActiveSource(primitiveQuotation)) { Quotation quotation = Quotation.Create(primitiveQuotation, this._ConfigMetadata); this._ConfigMetadata.Adjust(quotation); if (this._AbnormalQuotationProcessor.IsWaitForPreOutOfRangeConfirmed(primitiveQuotation)) { this._AbnormalQuotationProcessor.AddAndWait(primitiveQuotation); } else { if (this._AbnormalQuotationProcessor.IsNormalPrice(primitiveQuotation)) { this.EnablePrice(primitiveQuotation.InstrumentCode); List<PrimitiveQuotation> quotations = this._DerivativeController.Derive(primitiveQuotation); Manager.ExchangeManager.ProcessQuotation(quotations); } else { this._AbnormalQuotationProcessor.StartProcessAbnormalQuotation(primitiveQuotation); } } } }
public static Quotation Create(PrimitiveQuotation primitiveQuotation, ConfigMetadata metadata) { Quotation quotation = new Quotation(primitiveQuotation); quotation.SourceId = metadata.GetSourceId(primitiveQuotation.SourceName); quotation.InstrumentId = metadata.GetInstrumentId(primitiveQuotation.InstrumentCode); return quotation; }
private bool ProcessQuotation(string packet) { try { string[] priceData = packet.Split('\t'); PrimitiveQuotation quotation = new PrimitiveQuotation { SourceName = priceData[0], Symbol = priceData[1], Ask = priceData[4], Bid = priceData[3], Last = priceData[5], High = priceData[6], Low = priceData[7], Timestamp = DateTime.Parse(priceData[2]) // TODO: check Parse format: DateTime.Parse 只精确到秒级,对应于Feeder发送时精度也是到秒 }; this._QuotationManager.ProcessQuotation(quotation); } catch (Exception ex) { Logger.TraceEvent(TraceEventType.Error, "QuotationClient.ProcessQuotation packet:\r\n{0}\r\n{1})", packet, ex.ToString()); } return true; // Note: return false will suspend the RelayEngine, always return true will keep RelayEngine running. }
private bool ProcessQuotation(string packet) { string[] priceData = packet.Split('\t'); string sourceName = priceData[0]; string instrumentCode = priceData[1]; DateTime timestamp = DateTime.Parse(priceData[2]); string bid = priceData[3]; string ask = priceData[4]; string last = priceData[5]; string high = priceData[6]; string low = priceData[7]; PrimitiveQuotation quotation; if (this._LastPriceData[sourceName].TryGetValue(instrumentCode, out quotation)) { if (quotation.Ask != ask || quotation.Bid != bid || quotation.Last != last || quotation.High != high || quotation.Low != low || quotation.Timestamp != timestamp) { quotation.Ask = ask; quotation.Bid = bid; quotation.Last = last; quotation.High = high; quotation.Low = low; quotation.Timestamp = timestamp; } else { return true; } } else { quotation = new PrimitiveQuotation { SourceName = sourceName, InstrumentCode = instrumentCode, Ask = ask, Bid = bid, Last = last, High = high, Low = low, Timestamp = timestamp }; this._LastPriceData[sourceName].Add(instrumentCode, quotation); } this._QuotationManager.ProcessQuotation(quotation); return true; }
public List<PrimitiveQuotation> Derive(PrimitiveQuotation quotation) { throw new NotImplementedException(); }
private Quotation(PrimitiveQuotation primitiveQuotation) { this._PrimitiveQuotation = primitiveQuotation; }
public void ProcessQuotation(PrimitiveQuotation primitiveQuotation) { bool inverted; if (this._ConfigMetadata.EnsureIsKnownQuotation(primitiveQuotation, out inverted)) { double ask, bid; if (this._LastQuotationManager.LastReceived.Fix(primitiveQuotation, out ask, out bid)) { if (this._LastQuotationManager.LastReceived.IsNotSame(primitiveQuotation)) { MainService.ClientManager.Dispatch(new PrimitiveQuotationMessage() { Quotation = primitiveQuotation }); string instrumentCode = this._ConfigMetadata.Instruments[primitiveQuotation.InstrumentId].Code; SourceQuotation quotation = new SourceQuotation(primitiveQuotation, ask, bid, instrumentCode, inverted); if (this._SourceController.QuotationArrived(quotation)) { // quotation come from Active Source and adjusted if (this._AbnormalQuotationManager.SetQuotation(quotation)) { // quotation is normal this.ProcessNormalQuotation(quotation); } } this._LastQuotationManager.LastReceived.Set(quotation); } } } else { Logger.AddEvent(TraceEventType.Warning, "Discarded price:[ask={0}, bid={1}] got for {2} from {3}", primitiveQuotation.Ask, primitiveQuotation.Bid, primitiveQuotation.Symbol, primitiveQuotation.SourceName); } }
internal void SendQuotation(int instrumentSourceRelationId, double ask, double bid, out PrimitiveQuotation primitiveQuotation) { InstrumentSourceRelation relation = null; foreach (Dictionary<string, InstrumentSourceRelation> relations in this._ConfigMetadata.InstrumentSourceRelations.Values) { relation = relations.Values.SingleOrDefault(r => r.Id == instrumentSourceRelationId); if (relation != null) break; } primitiveQuotation = new PrimitiveQuotation(); primitiveQuotation.SourceId = relation.SourceId; primitiveQuotation.InstrumentId = relation.InstrumentId; primitiveQuotation.SourceName = this._ConfigMetadata.QuotationSources.Values.Single(s=>s.Id == relation.SourceId).Name; primitiveQuotation.Symbol = relation.SourceSymbol; primitiveQuotation.Ask = ask.ToString(); primitiveQuotation.Bid = bid.ToString(); primitiveQuotation.Timestamp = DateTime.Now; this.ProcessQuotation(primitiveQuotation); }
public bool IsFromActiveSource(PrimitiveQuotation quotation) { int sourceId = this._QuotationSources[quotation.SourceName].Id; return this._InstrumentSourceRelations.Values.Any(isr => isr.SourceId == sourceId && isr.IsActive == true); }
internal void StartProcessAbnormalQuotation(PrimitiveQuotation quotation) { throw new NotImplementedException(); }
internal bool IsNormalPrice(PrimitiveQuotation quotation) { throw new NotImplementedException(); }
internal void AddAndWait(PrimitiveQuotation quotation) { throw new NotImplementedException(); }
public bool IsWaitForPreOutOfRangeConfirmed(PrimitiveQuotation quotation) { throw new NotImplementedException(); }