feat
This commit is contained in:
25
py-client/test.py
Normal file
25
py-client/test.py
Normal file
@@ -0,0 +1,25 @@
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
from sdk import Client
|
||||
|
||||
BASE_URL = "http://127.0.0.1:10086"
|
||||
TOKEN = "QMTbyYanweidong"
|
||||
|
||||
|
||||
def main():
|
||||
client = Client(BASE_URL, TOKEN).set_account_type("stock")
|
||||
assets = client.assets();
|
||||
_, positions = client.positions()
|
||||
print(f"总资产:{assets.total:.2f}元,可用资金:{assets.available:.2f}元")
|
||||
for p in sorted(positions, key=lambda item: item.stock_code):
|
||||
if p.volume > 0: print(f"{p.stock_code} {p.stock_name} 持仓={p.volume} 可用={p.can_use_volume} 成本={p.open_price:.3f} 现价={p.last_price:.3f}")
|
||||
data_dir = os.environ.get("QMT_DATA_DIR", "").strip()
|
||||
if not data_dir: raise SystemExit("环境变量 QMT_DATA_DIR 为空")
|
||||
codes = json.loads((Path(data_dir) / "pass_codes.json").read_text(encoding="utf-8"))
|
||||
for code, tick in sorted(client.full_tick(codes).items()):
|
||||
print(f"{code} last={tick.last_price:.3f} close={tick.last_close:.3f}")
|
||||
|
||||
|
||||
if __name__ == "__main__": main()
|
||||
Reference in New Issue
Block a user