|
樓主 |
發表於 16-8-25 19:21
|
顯示全部樓層
本帖最後由 kfckfc3000 於 16-8-25 19:45 編輯
- static Quotation quote = new Quotation();
- // 這是call back method
- public static void SPTickerCallBack(ref SPApiTicker ticker)
- {
- Queue<Quotation> priceq;
- if (!PriceDict.ContainsKey(ticker.ProdCode))
- PriceDict.Add(ticker.ProdCode, new Queue<Quotation>());
- priceq = PriceDict[ticker.ProdCode];
-
- UpdateQuote(out quote, ref ticker);
- priceq.Enqueue(quote);
- <font color="#ff0000">//inform AB price updated</font>
- Plugin.NotifyStreamingUpdate();
- }
- public static void UpdateQuote(out Quotation quote, ref SPApiTicker ticker)
- {
- Debug.WriteLine("UpdateQuote(DateTime: " + ticker.TickerTime +
- ", ticker.Price: " + ticker.Price +
- ", ticker.Qty: " + ticker.Qty + ", ...)");
- quote.DateTime = Convert.ToUInt64(ticker.TickerTime);
- quote.Price = Convert.ToSingle(ticker.Price);
- quote.Open = 0;
- quote.High = 0;
- quote.Low = 0;
- quote.Volume = ticker.Qty;
- quote.OpenInterest = 0;
- quote.AuxData1 = 0;
- quote.AuxData2 = 0;
- }
- public static void NotifyStreamingUpdate()
- {
- NativeMethods.SendMessage(DataSource.MainWnd, 0x0400 + 13000, IntPtr.Zero, IntPtr.Zero);
- }
- [DllExport(CallingConvention = CallingConvention.Cdecl)]
- public static unsafe int GetQuotesEx(string ticker, Periodicity periodicity, int lastValid, int size, Quotation* quotes, GQEContext* context)
- {
- Debug.WriteLine("GetQuotesEx(ticker: " + ticker + ", periodicity: " + periodicity + ", lastValid: " + lastValid + ", size: " + size + ", ...)");
- Queue<Quotation> priceq;
- if (!PriceDict.ContainsKey(ticker))
- {
- PriceDict.Add(ticker, new Queue<Quotation>());
- //如果沒有就subscript 那個symbol
- Spcommon.APIDLL.R_SPAPI_SubscribePrice(ticker, 1);
- }
- else
- {
- priceq = PriceDict[ticker];
-
- quotes[lastValid + 1].DateTime = priceq.Dequeue().DateTime;
- quotes[lastValid + 1].Open = priceq.Dequeue().Open;
- quotes[lastValid + 1].High = priceq.Dequeue().High;
- quotes[lastValid + 1].Low = priceq.Dequeue().Low;
- quotes[lastValid + 1].Price = priceq.Dequeue().Price;
- quotes[lastValid + 1].Volume = priceq.Dequeue().Volume;
- quotes[lastValid + 1].OpenInterest = priceq.Dequeue().OpenInterest;
- quotes[lastValid + 1].AuxData1 = priceq.Dequeue().AuxData1;
- quotes[lastValid + 1].AuxData2 = priceq.Dequeue().AuxData2;
- return lastValid + 1;
- }
- return lastValid;
- }
複製代碼
這是我的寫法,可以給給意見嗎?
同一時間subscript 多個symbol 會有問題嗎?
謝謝!! |
|