Type specification of callable types (including lambda expressions)
pyBTrade.py
#Callable object:func
#Argument 1:int
#Argument 2:float
#Return value:str
def test(func: Callable[[int, float], str]) -> None:
See official documentation for details https://docs.python.org/ja/3/library/typing.html#typing.Callable
Me and this implementation example
pyBTrade.py
async def order_limit(
self,
price: Decimal,
size: Decimal,
func: Callable[['TradeSim', COrderItem], bool] = None
) -> COrderItem:
order: COrderItem = self.book_keeper_fx.order_limit(price, size)
while True:
try:
await asyncio.sleep(0)
if order.is_finished:
break
if self.is_finished:
break
if callable(func):
if func(self, order):
raise asyncio.CancelledError
except asyncio.CancelledError:
await self.send_order_cancel(order)
break
return order
Recommended Posts