Expose "proxy" api a little better

basic_orders
Tyler Goodlet 2021-01-11 21:22:03 -05:00
parent e51670a573
commit 12aebcc89c
1 changed files with 31 additions and 29 deletions

View File

@ -1,5 +1,5 @@
# piker: trading gear for hackers
# Copyright (C) 2018-present Tyler Goodlet (in stewardship of piker0)
# Copyright (C) Tyler Goodlet (in stewardship for piker0)
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
@ -423,23 +423,26 @@ class Client:
ticker = await ticker.updateEvent
return contract, ticker
async def submit_limit(
def submit_limit(
self,
contract: Contract,
price: float,
action: str = 'BUY',
quantity: int = 100,
) -> None:
self.ib.placeOrder(
) -> int:
"""Place an order and return integer request id provided by client.
"""
trade = self.ib.placeOrder(
Order(
self,
orderType='LMT',
action=action,
totalQuantity=quantity,
lmtPrice=price,
# **kwargs
)
)
return trade.order.orderId
async def recv_trade_updates(
self,
@ -611,7 +614,7 @@ class _MethodProxy:
)
def get_method_proxy(portal, target) -> _MethodProxy:
def get_client_proxy(portal, target=Client) -> _MethodProxy:
proxy = _MethodProxy(portal)
@ -635,11 +638,10 @@ async def get_client(
"""
async with maybe_spawn_brokerd(
brokername='ib',
expose_mods=[__name__],
infect_asyncio=True,
**kwargs
) as portal:
yield get_method_proxy(portal, Client)
yield get_client_proxy(portal)
# https://interactivebrokers.github.io/tws-api/tick_types.html
@ -892,8 +894,9 @@ async def stream_quotes(
calc_price = False # should be real volume for contract
with trio.move_on_after(10) as cs:
# with trio.move_on_after(10) as cs:
# wait for real volume on feed (trading might be closed)
async for ticker in stream:
# for a real volume contract we rait for the first
@ -915,9 +918,8 @@ async def stream_quotes(
# ``aclosing()`` above?
break
if cs.cancelled_caught:
await tractor.breakpoint()
# if cs.cancelled_caught:
# await tractor.breakpoint()
# real-time stream
async for ticker in stream: