public OnRspQryHistoricalBarsEventArgs(IntPtr pTicks, int size1, ref HistoricalDataRequestField request, int size2, bool bIsLast) { this.pTicks = pTicks; this.size1 = size1; this.request = request; this.size2 = size2; this.bIsLast = bIsLast; }
private void _OnRspQryHistoricalBars(IntPtr ptr1, int size1, IntPtr ptr2, int size2, double double1) { if (OnRspQryHistoricalBars == null) { return; } HistoricalDataRequestField obj = PInvokeUtility.GetObjectFromIntPtr <HistoricalDataRequestField>(ptr2); OnRspQryHistoricalBars(this, ptr1, size1, ref obj, size2, double1 != 0); }
public int ReqQryHistoricalBars(ref HistoricalDataRequestField request) { IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(HistoricalDataRequestField))); Marshal.StructureToPtr(request, ptr, false); IntPtr ret = proxy.XRequest((byte)RequestType.ReqQryHistoricalBars, Handle, IntPtr.Zero, 0, 0, ptr, 0, IntPtr.Zero, 0, IntPtr.Zero, 0); Marshal.FreeHGlobal(ptr); return ret.ToInt32(); }
public int ReqQryHistoricalBars(ref HistoricalDataRequestField request) { IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(HistoricalDataRequestField))); Marshal.StructureToPtr(request, ptr, false); IntPtr ret = proxy.XRequest((byte)RequestType.ReqQryHistoricalBars, Handle, IntPtr.Zero, 0, 0, ptr, 0, IntPtr.Zero, 0, IntPtr.Zero, 0); Marshal.FreeHGlobal(ptr); return(ret.ToInt32()); }
private HistoricalDataRequestField ToStruct(HistoricalDataRequest request) { string altSymbol; string altExchange; string apiSymbol; string apiExchange; double apiTickSize; string apiProductID; GetApi_Symbol_Exchange_TickSize(request.Instrument, this.id, out altSymbol, out altExchange, out apiSymbol, out apiExchange, out apiTickSize, out apiProductID); HistoricalDataRequestField field = new HistoricalDataRequestField(); field.Symbol = request.Instrument.Symbol; field.InstrumentID = apiSymbol; field.ExchangeID = apiExchange; field.Date1 = GetDate(request.DateTime1); field.Date2 = GetDate(request.DateTime2); field.Time1 = GetTime(request.DateTime1); field.Time2 = GetTime(request.DateTime2); field.DataType = (XAPI.DataObjetType)request.DataType; if (request.BarType.HasValue) { field.BarType = (XAPI.BarType)request.BarType.Value; } if (request.BarSize.HasValue) { field.BarSize = (int)request.BarSize.Value; } //field.RequestId; //field.Count; return(field); }
private void OnRspQryHistoricalBars_callback(object sender, IntPtr pTicks, int size1, ref HistoricalDataRequestField request, int size2, bool bIsLast) { if (null != OnRspQryHistoricalBars) { OnRspQryHistoricalBars(this, new OnRspQryHistoricalBarsEventArgs(pTicks, size1, ref request, size2, bIsLast)); } }
private int GetHistoricalBars(HistoricalDataRequestField request) { return(1); //return _HdApi.ReqQryHistoricalBars(ref request); }
private void OnRspQryHistoricalTicks_callback(object sender, IntPtr pTicks, int size1, ref HistoricalDataRequestField request, int size2, bool bIsLast) { int size = Marshal.SizeOf(typeof(TickField)); (sender as XApi).GetLog().Info("<--OnRspQryHistoricalTicks:{0},{1},{2},{3}条", request.CurrentDate, request.InstrumentID, request.ExchangeID, size1 / size); HistoricalDataRecord record; if (!historicalDataRecords.TryGetValue(request.RequestId, out record)) { return; } int day = -1; double volume = 0; DateTime datetime = DateTime.MinValue; DateTime updatetime = DateTime.MinValue; List <DataObject> list = new List <DataObject>(); for (int i = 0; i < size1 / size; ++i) { IntPtr ptr = (IntPtr)(pTicks + size * i); TickField obj = Marshal.PtrToStructure <TickField>(ptr); DateTime dt = GetDateTime(obj.Date, obj.Time, obj.Millisecond); if (datetime == dt) { updatetime = updatetime.AddMilliseconds(100); } else { updatetime = dt; } if (day != updatetime.Day) { volume = 0; } day = updatetime.Day; volume = obj.Volume - volume; // 这地方应当加历史数据另存的地方才好 if (SaveToCsv) { LogEventInfo logEvent = new LogEventInfo(NLog.LogLevel.Trace, tickLog.Name, TickFieldToString(obj, updatetime, volume)); // 用户可能需要按收到数据的合约与时间分目录或文件 logEvent.Properties[Symbol] = record.Request.Instrument.Symbol; logEvent.Properties[Date] = request.CurrentDate; tickLog.Log(logEvent); } if (FilterDateTime) { if (FilterDateTime_(record.Request, updatetime)) { DataObject o = null; if (EmitAllTickType) { // 全面保存数据 o = new Trade(updatetime, this.id, record.Request.Instrument.Id, obj.LastPrice, (int)volume); list.Add(o); o = new Quote(updatetime, this.id, record.Request.Instrument.Id, obj.BidPrice1, obj.BidSize1, obj.AskPrice1, obj.AskSize1); list.Add(o); } else { // 分别保存 switch (record.Request.DataType) { case DataObjectType.Tick: case DataObjectType.Bid: o = new Bid(updatetime, this.id, record.Request.Instrument.Id, obj.BidPrice1, obj.BidSize1); break; case DataObjectType.Ask: o = new Ask(updatetime, this.id, record.Request.Instrument.Id, obj.AskPrice1, obj.AskSize1); break; case DataObjectType.Trade: o = new Trade(updatetime, this.id, record.Request.Instrument.Id, obj.LastPrice, (int)volume); break; case DataObjectType.Quote: o = new Quote(updatetime, this.id, record.Request.Instrument.Id, obj.BidPrice1, obj.BidSize1, obj.AskPrice1, obj.AskSize1); break; } list.Add(o); } } } datetime = dt; volume = obj.Volume; } if (EmitHistoricalData) { HistoricalData data = new HistoricalData { RequestId = record.Request.RequestId, Objects = list.ToArray(), TotalNum = list.Count, }; //Console.WriteLine("============"); //Console.WriteLine(list.Count); base.EmitHistoricalData(data); } if (bIsLast) { EmitHistoricalDataEnd(record.Request.RequestId, RequestResult.Completed, ""); } }
private void OnRspQryHistoricalBars_callback(object sender, IntPtr pBars, int size1, ref HistoricalDataRequestField request, int size2, bool bIsLast) { int size = Marshal.SizeOf(typeof(BarField)); (sender as XApi).GetLog().Info("<--OnRspQryHistoricalBars:{0},{1},{2},{3}条", request.CurrentDate, request.InstrumentID, request.ExchangeID, size1 / size); HistoricalDataRecord record; if (!historicalDataRecords.TryGetValue(request.RequestId, out record)) { return; } List <Bar> list = new List <Bar>(); for (int i = 0; i < size1 / size; ++i) { IntPtr ptr = (IntPtr)(pBars + size * i); BarField obj = PInvokeUtility.GetObjectFromIntPtr <BarField>(ptr); int Millisecond = 0; DateTime dt = GetDateTime(obj.Date, obj.Time, Millisecond); // 这地方应当加历史数据另存的地方才好 if (SaveToCsv) { LogEventInfo logEvent = new LogEventInfo(NLog.LogLevel.Trace, tickLog.Name, BarFieldToString(obj, dt)); // 用户可能需要按收到数据的合约与时间分目录或文件 logEvent.Properties[Symbol] = record.Request.Instrument.Symbol; logEvent.Properties[Date] = request.CurrentDate.ToString(); logEvent.Properties[BarSize] = request.BarSize.ToString(); barLog.Log(logEvent); } if (FilterDateTime) { if (FilterDateTime_(record.Request, dt)) { Bar b = new Bar(dt, dt.AddSeconds(record.Request.BarSize.Value), record.Request.Instrument.Id, record.Request.BarType.Value, record.Request.BarSize.Value, obj.Open, obj.High, obj.Low, obj.Close, (long)obj.Volume, (long)obj.OpenInterest); list.Add(b); } } } if (EmitHistoricalData) { HistoricalData data = new HistoricalData { RequestId = record.Request.RequestId, Objects = list.ToArray(), TotalNum = list.Count, }; base.EmitHistoricalData(data); } if (bIsLast) { EmitHistoricalDataEnd(record.Request.RequestId, RequestResult.Completed, ""); } }