Trivial change to introduce more type hints
This commit is contained in:
parent
d95269cf4f
commit
46ca62ac73
@ -1,7 +1,7 @@
|
|||||||
import pandas as pd
|
import pandas as pd
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from ib_insync import ComboLeg, Contract, IB, Index, Option, Order, Trade
|
from ib_insync import ComboLeg, Contract, IB, Index, Option, Order, Ticker, Trade
|
||||||
from ib_insync.util import isNan
|
from ib_insync.util import isNan
|
||||||
from random import randint
|
from random import randint
|
||||||
from typing import Callable, List
|
from typing import Callable, List
|
||||||
@ -14,17 +14,17 @@ from .order_action import BUY, SELL
|
|||||||
|
|
||||||
class Client:
|
class Client:
|
||||||
|
|
||||||
def __init__(self, host: str = '127.0.0.1', port: int = 7497, client_id = randint(1, 10000)) -> None:
|
def __init__(self, host: str = '127.0.0.1', port: int = 7497, client_id: int = randint(1, 10000)) -> None:
|
||||||
self.ib = IB()
|
self.ib = IB()
|
||||||
self.ib.connect(host, port, clientId = client_id)
|
self.ib.connect(host, port, clientId = client_id)
|
||||||
self.ib.reqMarketDataType(LIVE)
|
self.ib.reqMarketDataType(LIVE)
|
||||||
|
|
||||||
def get_ticker(self, symbol: str, exchange: str):
|
def get_ticker(self, symbol: str, exchange: str) -> Ticker:
|
||||||
underlying = Index(symbol, exchange)
|
underlying = Index(symbol, exchange)
|
||||||
self.ib.qualifyContracts(underlying)
|
self.ib.qualifyContracts(underlying)
|
||||||
return self.ib.reqTickers(underlying)[0]
|
return self.ib.reqTickers(underlying)[0]
|
||||||
|
|
||||||
def get_market_data(self, contract: Contract, streaming: bool = False):
|
def get_market_data(self, contract: Contract, streaming: bool = False) -> Ticker:
|
||||||
market_data = self.ib.reqMktData(contract, '',
|
market_data = self.ib.reqMktData(contract, '',
|
||||||
snapshot = not streaming, regulatorySnapshot = False)
|
snapshot = not streaming, regulatorySnapshot = False)
|
||||||
while isNan(market_data.bid) or isNan(market_data.ask):
|
while isNan(market_data.bid) or isNan(market_data.ask):
|
||||||
@ -79,7 +79,7 @@ class Client:
|
|||||||
self.ib.qualifyContracts(option_contract)
|
self.ib.qualifyContracts(option_contract)
|
||||||
return option_contract
|
return option_contract
|
||||||
|
|
||||||
def submit_option_order(self, leg: OptionLeg, quantity: int):
|
def submit_option_order(self, leg: OptionLeg, quantity: int) -> Trade:
|
||||||
option_contract = self.get_option_contract(leg)
|
option_contract = self.get_option_contract(leg)
|
||||||
contract = Contract()
|
contract = Contract()
|
||||||
contract.conId = option_contract.conId
|
contract.conId = option_contract.conId
|
||||||
|
Loading…
Reference in New Issue
Block a user