3

Python は初めてで、ネイティブの TWS Python API (Interactive Brokers API) を使用して、証券リストの価格スナップショットを変数で取得したいと考えています。たとえば、株式 APPL、AMZN、および NFLX の場合、snaphot = ['APPL', 195.2, 'AMZN', 1771.5, 'NFLX', 306] のようなものを取得したいと考えています。

よろしくお願いいたします。

Interactive Brokers のガイドは理解しにくく、例が不足していました。彼らが提供する1つの例は、1つの株のみであり、実行が停止することはありません.

from ibapi.client import EClient
from ibapi.wrapper import EWrapper
from ibapi.contract import Contract
from ibapi.ticktype import TickTypeEnum

import time

class TestApp(EWrapper, EClient):
    def __init__(self):
        EClient.__init__(self, self)

    def error(self, reqId, errorCode, errorString):
        print("Error: ", reqId, " ", errorCode, " ", errorString)

    def tickPrice(self, reqId, tickType, price, attrib):
        print("Tick Price. Ticker Id:", reqId, "tickType:",
TickTypeEnum.to_str(tickType), "Price:", price, end=' ')

    def tickSize(self, reqId, tickType, size):
        print("Tick Size. Ticker Id:", reqId, "tickType:",
TickTypeEnum.to_str(tickType), "Size:", size)

def main():
    app = TestApp()

    app.connect("127.0.0.1", 7496, 0)


    time.sleep(0.1)

    contract = Contract()
    contract.secType = "FUT"
    contract.exchange = "DTB"
    contract.currency = "EUR"
    contract.localSymbol = "FDXM SEP 19"

    app.reqMarketDataType(4) # 1 for live, 4 for delayed-frozen data if live is not available
    app.reqMktData(1, contract, "", True, False, [])

    app.run()

if __name__ == "__main__":
    main()
4

1 に答える 1