元富 API產品介紹

商品種類

國內期貨

國內選擇權

產品特色

cor logo
多種版本
提供C# Python VBA VBA.NET

cor logo
回補功能
提供即時、回補、即時開高低等函數,並能自動取得歷史資料並動態更新最新報價

cor logo
資料詳細度
來自交易所揭示表格欄位,完整揭示逐筆資訊,期權逐筆資料包含成交、委託資訊、上下五檔價量

cor logo
資料完整度
提供完整商品基本資料,其中包含個股期對應標的、中英對照表、結算日等

範例程式碼

報價範例程式

◆ 安裝套件說明

       開啟Windows 命令提示字元(CMD)載入套件,指令如下:  

pip install MicroQuote

        執行操作過程如下:

>>> pip install MicroQuote

Requirement already satisfied: pika>=1.0.0 in c:\users\peter\appdata\local\programs\python\python39\lib\site-packages (from MicroQuote) (1.2.0)
Requirement already satisfied: requests in c:\users\peter\appdata\local\programs\python\python39\lib\site-packages (from MicroQuote) (2.26.0)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in c:\users\peter\appdata\local\programs\python\python39\lib\site-packages (from requests->MicroQuote) (1.26.6)
Requirement already satisfied: charset-normalizer~=2.0.0 in c:\users\peter\appdata\local\programs\python\python39\lib\site-packages (from requests->MicroQuote) (2.0.4)
Requirement already satisfied: idna<4,>=2.5 in c:\users\peter\appdata\local\programs\python\python39\lib\site-packages (from requests->MicroQuote) (3.2)
Requirement already satisfied: certifi>=2017.4.17 in c:\users\peter\appdata\local\programs\python\python39\lib\site-packages (from requests->MicroQuote) (2021.5.30)
Installing collected packages: MicroQuote
Successfully installed MicroQuote-0.9.59

  MicroQuote 套件只有支援python3.7版本

◆ 報價API函數介紹

  1. 取得即時報價
    範例程式碼檔名:Sample.py

    import MicroQuote

    s = MicroQuote.MicroQuote_Login('帳號', '密碼', '登入IP','即時報價IP','報價回補IP','其他靜態資料IP')

    a = MicroQuote.MicroQuote_Set('2330','Stock','', True)

    for i in a.quote_on_notify():

        print(i)

            執行操作過程如下:

    >>> C:\Users\User\Desktop>Sample.py

    ['2330', '10:40:42.217532', '23631', 'NaN', 'NaN', '612.0000', '963', '611.0000', '1209', '610.0000', '1295', '609.0000', '230', '608.0000', '432', '613.0000', '807', '614.0000', '690', '615.0000', '1624', '616.0000', '1173', '617.0000', '1898']

    ['2330', '10:40:42.235476', '23633', '613.0000', '2', '612.0000', '963', '611.0000', '1209', '610.0000', '1295', '609.0000', '230', '608.0000', '432', '613.0000', '805', '614.0000', '690', '615.0000', '1624', '616.0000', '1173', '617.0000', '1898']

    ['2330', '10:40:42.792906', '23633', 'NaN', 'NaN', '612.0000', '964', '611.0000', '1209', '610.0000', '1295', '609.0000', '230', '608.0000', '432', '613.0000', '805', '614.0000', '690', '615.0000', '1624', '616.0000', '1173', '617.0000', '1898']

    ['2330', '10:40:43.382231', '23634', '613.0000', '1', '612.0000', '964', '611.0000', '1209', '610.0000', '1295', '609.0000', '230', '608.0000', '432', '613.0000', '804', '614.0000', '690', '615.0000', '1624', '616.0000', '1173', '617.0000', '1898']

  2. 取得回補資料
    範例程式碼檔名:Sample.py

    import MicroQuote

    s = MicroQuote.MicroQuote_Login('帳號', '密碼', '登入IP','即時報價IP','報價回補IP','其他靜態資料IP')

    a = MicroQuote.MicroQuote_Set('2330','Stock','', True)

    for i in a.get_history_data('09:00:00', '10:00:00'):

        print(i)

            執行操作過程如下:

    >>> C:\Users\User\Desktop>Sample.py

    ['2330', '09:00:05.450830', '3493', '611.0000', '3493', '610.0000', '110', '609.0000', '172', '608.0000', '329', '607.0000', '59', '606.0000', '259', '611.0000', '422', '612.0000', '411', '613.0000', '242', '614.0000', '283', '615.0000', '588']

    ['2330', '09:00:05.519235', '3494', '610.0000', '1', '610.0000', '109', '609.0000', '172', '608.0000', '329', '607.0000', '59', '606.0000', '259', '611.0000', '422', '612.0000', '411', '613.0000', '242', '614.0000', '283', '615.0000', '588']

    ['2330', '09:00:05.555253', '3497', '611.0000', '3', '610.0000', '111', '609.0000', '81', '608.0000', '329', '607.0000', '59', '606.0000', '265', '611.0000', '422', '612.0000', '411', '613.0000', '243', '614.0000', '283', '615.0000', '588']

    ['2330', '09:00:05.556940', '3499', '611.0000', '2', '610.0000', '111', '609.0000', '81', '608.0000', '329', '607.0000', '59', '606.0000', '265', '611.0000', '420', '612.0000', '411', '613.0000', '243', '614.0000', '283', '615.0000', '588']

  3. 取得最後一筆報價
    範例程式碼檔名:Sample.py

    import MicroQuote

    s = MicroQuote.MicroQuote_Login('帳號', '密碼', '登入IP','即時報價IP','報價回補IP','其他靜態資料IP')

    a = MicroQuote.MicroQuote_Set('2330','Stock','', True)

    b=a.get_last_data('Stock', '2330', '')

    print(b)

            執行操作過程如下:

    >>> C:\Users\User\Desktop>Sample.py

    ['2330,11:07:46.401635,25792,NaN,NaN,612.0000,898,611.0000,1179,610.0000,1209,609.0000,241,608.0000,412,613.0000,295,614.0000,1053,615.0000,1994,616.0000,1387,617.0000,2050']

下單範例程式

◆ 安裝套件說明

       開啟Windows 命令提示字元(CMD),請先移動至whl檔所在的目錄,並載入套件,指令如下:  

cd masterlinkapi-1.0.12-py3-none-any.whl所在的目錄\

pip install masterlinkapi-1.0.12-py3-none-any.whl

        執行操作過程如下:

>>> pip install masterlinkapi-1.0.12-py3-none-any.whl

Processing c:\Users\User\Desktop\masterlinkapi-1.0.12-py3-none-any.whl
Collecting websocket-client==0.56.0
   Using cached websocket_client-0.56.0-py2.py3-none-any.whl (200 kB)
Requirement already satisfied: requests in c:\users\peter\appdata\local\programs\python\python39\lib\site-packages (from masterlinkapi==1.0.12) (2.26.0)
Requirement already satisfied: six in c:\users\peter\appdata\local\programs\python\python39\lib\site-packages (from websocket-client==0.56.0->masterlinkapi==1.0.12) (1.16.0)
Requirement already satisfied: idna<4,>=2.5 in c:\users\peter\appdata\local\programs\python\python39\lib\site-packages (from requests->masterlinkapi==1.0.12) (3.2)
Requirement already satisfied: charset-normalizer~=2.0.0 in c:\users\peter\appdata\local\programs\python\python39\lib\site-packages (from requests->masterlinkapi==1.0.12) (2.0.4)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in c:\users\peter\appdata\local\programs\python\python39\lib\site-packages (from requests->masterlinkapi==1.0.12) (1.26.6)
Requirement already satisfied: certifi>=2017.4.17 in c:\users\peter\appdata\local\programs\python\python39\lib\site-packages (from requests->masterlinkapi==1.0.12) (2021.5.30)
Installing collected packages: websocket-client, masterlinkapi
Successfully installed masterlinkapi-1.0.12 websocket-client-0.56.0

  masterlinkapi 套件只有支援python3.7版本

◆ 下單API函數介紹

  1. 下單
    範例程式碼檔名:Sample.py

    from masterlinkapi import mapp

    import threading

    order_account = None

    event = threading.Event()

    #登入回傳

    def A(msg):

      global order_account

      print('msgA ' + msg)

      if msg == 'finish':

        event.set()

      row = msg.strip('|').split('|')

      for s in row:

        if(len(s) > 7):

          if s[0:2] == "0,":

            order_account = s[-7:]

    #下單回傳

    def B(msg):

      print('msgB' + msg)

    #查詢回傳

    def C(msg):

      print('msgC ' + msg)

    #即時委託回傳

    def D(msg):

      print('msgD ' + msg)

    #即時成交回傳

    def E(msg):

      print('msgE ' + msg)

    #紀錄回傳

    def F(msg):

      print('msgF ' + msg)

    #公告回傳

    def G(msg):

      print('msgG ' + msg)

    #斷線回傳

    def H(msg):

      print('msgH ' + msg)

    mp = mapp.MAPI('IP', '下單Port', '即時帳務Port')

    #登入

    print(mp.Login('帳號', '密碼', A, B, C, D, E, F, G, H))

    #下單

    #參數:下單帳號,Y/N(當沖/非當沖),商品名,月份,數量,價格,買賣,1/2(市價/限價),0/1(新倉/平倉),履約價(期貨0),C/P/N(買權/賣權/期貨),0/1/2(ROD/FOK/IOC)

    a=mp.Order(order_account, 'N', 'FIMTX', '202109', '1', "16000", "B", "2", "0", "0", "N", "0", "9", "userkey")

    print(a)

    mp.KeepAlive()

            執行操作過程如下:

    >>> C:\Users\User\Desktop>Sample.py

    received 000a4711d30-ca73-4197-9d05-abe006683d6700-000,INTEN9617686,OVERN9617686,200,201000006,202010000,203000004,121NNNN,100211.75.151.194,902b1005:,902x6001:

    msgA |0,9617686|1,9617686|F |0,9617686|1,9617686|F ProductOut| F received 117|ICESG|SDX

    ICESG|TM NYB|CC NYB|CT NYB|DX NYB|KC NYB|OJ NYB|SB EUX|DAX EUX|FDXM EUX|FESX EUX|FGBL EUX|FGBM EUX|FGBS EUX|FGBX HKE|HHI HKE|HMTW HKE|HSI HKE|HTI HKE|MCH HKE|MHI TCE|JAM TCE|JAS TCE|JAU TCE|JCO TCE|JCR TCE|JGL TCE|JKE TCE|JPA TCE|JPL TCE|JPM TCE|JRB TCE|JRU TCE|JSV CME|AD CME|BP CME|CD CME|EC CME|ECM CME|ED CME|ES CME|FC CME|JY CME|LC CME|LH CME|M2K CME|MAD CME|MBP CME|MCD CME|MES CME|MJY CME|MNQ CME|MP CME|NE CME|NK CME|NQ CME|RTY CME|SF CME|UROM NYM|GC NYM|HG NYM|MGC NYM|QM NYM|RB NYM|SI NYM|SIL NYM|CL NYM|HO NYM|NG NYM|PA NYM|PL SGX|SCN SGX|SIN SGX|SSG SGX|SSI SGX|TWN LIF|FFI OSE|JGB OSE|JNI OSE|JNK OSE|JNM OSE|JTI OSE|JTM CME_CBT|BO CME_CBT|C CME_CBT|FV CME_CBT|MYM CME_CBT|O CME_CBT|RR CME_CBT|S CME_CBT|SM CME_CBT|TU CME_CBT|TY CME_CBT|US CME_CBT|W CME_CBT|YC CME_CBT|YK CME_CBT|YM CBT|YG CBT|YI CBT|ZG CBT|ZI

    received! Setuka1002userkey

    received 001|a1002|買進FIMTX202109新倉1口委價16000.0000||userkey

    received! 9617686!13:39:40|serverkey|userkey|21,20210914,F018000,a1,002,9617686,7,MXFI1,B,L,+,016000000000,0001,R,0,F018,0000,0001,13393997,30500017,01,00,,0,00,,13393997,A02,9,00,000000000000,0000,02190299,,FIMTX,202109,000000000,B,,000000,000000000,,,,

立即成為會員

我們有多樣金融科技產品及精心準備的範例說明,馬上加入會員並取得最新消息.
加入會員

電子信箱:haohanservice@haohaninfo.com
地址:高雄市苓雅區 中山二路461號10樓之12
電話:07 - 5361962

© 2022 昊瀚資訊 版權所有