呼び出し可能型(lambda式含む)の型指定
pyBTrade.py
# 呼び出し可能オブジェクト:func
# 引数1:int
# 引数2:float
# 返り値:str
def test(func: Callable[[int, float], str]) -> None:
詳しくは公式ドキュメントを参照
https://docs.python.org/ja/3/library/typing.html#typing.Callable
自分とこの実装例
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