PPysolate SpineREAD THE CODE · UNDERSTAND THE SYSTEM
课程与章节
源码索引 / CURRENT IMPLEMENTATION

examples/trading.py

14 行 · 点击行号可定位;函数链接随声明位置更新,不手填行号。

price = quote(symbol=inputs["symbol"])
cash_balance = cash()
if price <= inputs["limit"]:
    cost = price * inputs["quantity"]
    if cash_balance >= cost:
        try:
            order = buy(symbol=inputs["symbol"], quantity=inputs["quantity"])
            result = {"decision": "bought", "price": price, "cash_snapshot": cash_balance, "order": order}
        except RuntimeError:
            result = {"decision": "blocked", "price": price, "cash_snapshot": cash_balance, "reason": "Host refused the simulated order"}
    else:
        result = {"decision": "hold", "price": price, "cash_snapshot": cash_balance, "reason": "insufficient cash"}
else:
    result = {"decision": "hold", "price": price, "cash_snapshot": cash_balance, "reason": "price above limit"}