請選擇 進入手機版 | 繼續訪問電腦版

COCO研究院

 找回密碼
 註冊
搜索
查看: 8498|回復: 11

用C# 寫 Amibroker Data Plugin

[複製鏈接]
發表於 16-8-23 21:11 | 顯示全部樓層 |閱讀模式
怎樣把Callback Function TickerCallBack() 和 Amibroker GetquoteEx() 聯繫在一起嗎?
就是有Ticker 到了,會自動Call Amibroker GetquoteEx() ,
好像可以subscript 這個方法,但如何把Ticker pass 給GetquoteEx() ?

static void NotifyStreamingUpdate()
{
      NativeMethods.SendMessage(DataSource.MainWnd, 0x0400 + 13000, IntPtr.Zero, IntPtr.Zero);
}

我的Ticker 來自SP Trader API,
C# plugin 是參考Github
有高手知道怎樣寫嗎, 謝謝!!

發表於 16-12-30 12:07 | 顯示全部樓層
我也是用凱基的QuoteCom,最近想要把他的資料用PlugIn的方式導到Amibroker的資料裡面,請問可以交流嗎?
回復 支持 1 反對 0

使用道具 舉報

發表於 16-8-24 20:33 | 顯示全部樓層
本帖最後由 lwhuang 於 16-8-24 20:36 編輯

你這個問題跟C#無關,因為c也是一樣的,沒看過SP,以下以凱基為例,我相信你找的github跟我一樣,因為就只有一個
做一個dictionary
  1. public Dictionary<string, Queue<PI20020>> PriceDict = new Dictionary<string, Queue<PI20020>>();
複製代碼

每次tick callback時就把價格存到裡面
  1. Queue<PI20020> priceq;
  2. if (!PriceDict.ContainsKey(ticker))
  3.           PriceDict.Add(ticker, new Queue<PI20020>());

  4. priceq = PriceDict[ticker];
  5. priceq.Enqueue(i20020);
  6. //inform AB price updated
  7. Plugin.NotifyStreamingUpdate();
複製代碼

GetQuotesEx發生時,去那個dictionary撈資料
回復 支持 1 反對 0

使用道具 舉報

 樓主| 發表於 16-8-24 22:03 | 顯示全部樓層
非常感謝你的回覆!!!

我們的Github是同一個,我用sp trader 作報價來源
但我還有問題關於plugin完整整合,
大哥,可以方便分享完整代碼作學習交流嗎? 謝謝!!!
 樓主| 發表於 16-8-25 19:21 | 顯示全部樓層
本帖最後由 kfckfc3000 於 16-8-25 19:45 編輯
  1.         static Quotation quote = new Quotation();

  2.       // 這是call back method
  3.         public static void SPTickerCallBack(ref SPApiTicker ticker)
  4.         {
  5.             Queue<Quotation> priceq;
  6.             if (!PriceDict.ContainsKey(ticker.ProdCode))
  7.                 PriceDict.Add(ticker.ProdCode, new Queue<Quotation>());

  8.             priceq = PriceDict[ticker.ProdCode];
  9.             
  10.             UpdateQuote(out quote, ref ticker);
  11.             priceq.Enqueue(quote);
  12.             <font color="#ff0000">//inform AB price updated</font>
  13.             Plugin.NotifyStreamingUpdate();
  14.         }

  15.         public static void UpdateQuote(out Quotation quote, ref SPApiTicker ticker)
  16.         {
  17.             Debug.WriteLine("UpdateQuote(DateTime: " + ticker.TickerTime +
  18.                 ", ticker.Price: " + ticker.Price +
  19.                 ", ticker.Qty: " + ticker.Qty + ", ...)");

  20.             quote.DateTime = Convert.ToUInt64(ticker.TickerTime);
  21.             quote.Price = Convert.ToSingle(ticker.Price);
  22.             quote.Open = 0;
  23.             quote.High = 0;
  24.             quote.Low = 0;
  25.             quote.Volume = ticker.Qty;
  26.             quote.OpenInterest = 0;
  27.             quote.AuxData1 = 0;
  28.             quote.AuxData2 = 0;
  29.         }

  30.         public static void NotifyStreamingUpdate()
  31.         {
  32.             NativeMethods.SendMessage(DataSource.MainWnd, 0x0400 + 13000, IntPtr.Zero, IntPtr.Zero);
  33.         }

  34.         [DllExport(CallingConvention = CallingConvention.Cdecl)]
  35.         public static unsafe int GetQuotesEx(string ticker, Periodicity periodicity, int lastValid, int size, Quotation* quotes, GQEContext* context)
  36.         {
  37.             Debug.WriteLine("GetQuotesEx(ticker: " + ticker + ", periodicity: " + periodicity + ", lastValid: " + lastValid + ", size: " + size + ", ...)");

  38.             Queue<Quotation> priceq;

  39.             if (!PriceDict.ContainsKey(ticker))
  40.             {
  41.                 PriceDict.Add(ticker, new Queue<Quotation>());
  42.                  //如果沒有就subscript 那個symbol
  43.                 Spcommon.APIDLL.R_SPAPI_SubscribePrice(ticker, 1);
  44.             }
  45.             else
  46.             {
  47.                 priceq = PriceDict[ticker];
  48.                  
  49.                 quotes[lastValid + 1].DateTime = priceq.Dequeue().DateTime;
  50.                 quotes[lastValid + 1].Open = priceq.Dequeue().Open;
  51.                 quotes[lastValid + 1].High = priceq.Dequeue().High;
  52.                 quotes[lastValid + 1].Low = priceq.Dequeue().Low;
  53.                 quotes[lastValid + 1].Price = priceq.Dequeue().Price;
  54.                 quotes[lastValid + 1].Volume = priceq.Dequeue().Volume;
  55.                 quotes[lastValid + 1].OpenInterest = priceq.Dequeue().OpenInterest;
  56.                 quotes[lastValid + 1].AuxData1 = priceq.Dequeue().AuxData1;
  57.                 quotes[lastValid + 1].AuxData2 = priceq.Dequeue().AuxData2;

  58.                 return lastValid + 1;
  59.             }

  60.             return lastValid;
  61.         }
複製代碼


這是我的寫法,可以給給意見嗎?
同一時間subscript 多個symbol 會有問題嗎?
謝謝!!
發表於 16-8-27 10:22 | 顯示全部樓層
本帖最後由 lwhuang 於 16-8-27 10:26 編輯

如果是tick資料的話,把open, high, low寫進去一樣的資料

拿完資料後要刪掉這筆
同一時間subscript 多個symbol是 sp api的能力,我不知道,但是要是沒有就太誇張了
 樓主| 發表於 16-8-27 10:40 | 顯示全部樓層
SP 可以subscript 多個symbol, 我只昰擔心把tick data 接過來時,
feed 給Amibroker 做得不好, 當call GetQuoteEx, 我應該要lock dictionary 嗎?
如果lock dictionary, 會不會延遲了,我是編程新手, 謝謝!!
發表於 16-8-27 12:41 | 顯示全部樓層
不用 lock 因為 producer & consumer 都只有一個
Dequeue 就會移除了,這樣你每一行都在移除,當然會是錯的。我會把那個 symbol 的所有資料都取出來
建議你先看官方的 ADK 說明,再對照官方的範例,看懂後再寫成 C#
 樓主| 發表於 16-8-27 23:47 | 顯示全部樓層
就是把 Queue copy 到一個新的Array? 再把Array assign 給 quote
因為我不會C++,而且找不到一些C# real time plugin 的example,
historical 的有一些例子,所以不知道怎做,我會再看一下,謝謝!!
發表於 16-10-23 09:24 | 顯示全部樓層
可否SHARE給我.
我找不到PLUGIN, AMIBROKDER SP TRADER用來睇即時香港期指.
發表於 17-1-24 15:57 | 顯示全部樓層
antony 發表於 16-12-30 12:07
我也是用凱基的QuoteCom,最近想要把他的資料用PlugIn的方式導到Amibroker的資料裡面,請問可以交流嗎?
...

請問一下,你用的PlugIn的Open Source 可以載入QuoteCom.com 嗎?

如: quoteCom = new Intelligence.QuoteCom(strQuoteServerHost, 8000, "API", "b6eb");

 樓主| 發表於 17-4-9 20:29 | 顯示全部樓層
andrewhlleung 發表於 16-10-23 09:24
可否SHARE給我.
我找不到PLUGIN, AMIBROKDER SP TRADER用來睇即時香港期指.

不好意思,一段時間沒上來,我最後直接用DDE, 沒再折騰,謝謝!
您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則

手機版|Archiver|站長信箱|廣告洽詢|COCO研究院

GMT+8, 24-3-28 20:38

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

快速回復 返回頂部 返回列表
理財討論網站 | AI繪圖AI超擬真美女AI beauty AI Stable DiffusionAI正妹AI Lookbook