Trivial change to introduce more type hints
This commit is contained in:
parent
d95269cf4f
commit
46ca62ac73
@ -1,7 +1,7 @@
|
||||
import pandas as pd
|
||||
|
||||
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 random import randint
|
||||
from typing import Callable, List
|
||||
@ -14,17 +14,17 @@ from .order_action import BUY, SELL
|
||||
|
||||
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.connect(host, port, clientId = client_id)
|
||||
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)
|
||||
self.ib.qualifyContracts(underlying)
|
||||
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, '',
|
||||
snapshot = not streaming, regulatorySnapshot = False)
|
||||
while isNan(market_data.bid) or isNan(market_data.ask):
|
||||
@ -79,7 +79,7 @@ class Client:
|
||||
self.ib.qualifyContracts(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)
|
||||
contract = Contract()
|
||||
contract.conId = option_contract.conId
|
||||
|
Loading…
Reference in New Issue
Block a user