26 lines
997 B
Python
26 lines
997 B
Python
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()
|