Skip to content

Commit 82ad3f2

Browse files
api: add examples for insert_order
1 parent 17e3089 commit 82ad3f2

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

tqsdk/api.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ def insert_order(self, symbol: str, direction: str, offset: str, volume: int, li
599599
Returns:
600600
:py:class:`~tqsdk.objs.Order`: 返回一个委托单对象引用. 其内容将在 :py:meth:`~tqsdk.api.TqApi.wait_update` 时更新.
601601
602-
Example::
602+
Example1::
603603
604604
# 市价开3手 DCE.m1809 多仓
605605
from tqsdk import TqApi
@@ -615,6 +615,39 @@ def insert_order(self, symbol: str, direction: str, offset: str, volume: int, li
615615
单状态: ALIVE, 已成交: 0 手
616616
单状态: FINISHED, 已成交: 3 手
617617
...
618+
619+
Example2::
620+
621+
# 限价开多3手 DCE.m1901
622+
from tqsdk import TqApi
623+
with TqApi() as api:
624+
order = api.insert_order(symbol="DCE.m2009", direction="BUY", offset="OPEN", volume=3, limit_price=3000)
625+
while True:
626+
api.wait_update()
627+
print("单状态: %s, 已成交: %d 手" % (order.status, order.volume_orign - order.volume_left))
628+
629+
# 预计的输出是这样的:
630+
单状态: ALIVE, 已成交: 0 手
631+
单状态: ALIVE, 已成交: 0 手
632+
单状态: FINISHED, 已成交: 3 手
633+
...
634+
635+
Example3::
636+
637+
# 市价开多3手 DCE.m1901 FAK
638+
from tqsdk import TqApi
639+
with TqApi() as api:
640+
order = api.insert_order(symbol="DCE.m2009", direction="BUY", offset="OPEN", volume=3, advanced="FAK")
641+
while True:
642+
api.wait_update()
643+
print("单状态: %s, 已成交: %d 手" % (order.status, order.volume_orign - order.volume_left))
644+
645+
# 预计的输出是这样的:
646+
单状态: ALIVE, 已成交: 0 手
647+
单状态: ALIVE, 已成交: 0 手
648+
单状态: FINISHED, 已成交: 3 手
649+
...
650+
618651
"""
619652
if symbol not in self._data.get("quotes", {}):
620653
raise Exception("合约代码 %s 不存在, 请检查合约代码是否填写正确" % (symbol))

0 commit comments

Comments
 (0)