from puga import market, fio def _book(monkeypatch): monkeypatch.setattr(fio, "order_book", lambda m, c, r=False: { "SellingOrders": [{"ItemCount": 10, "ItemCost": 110}, {"ItemCount": 5, "ItemCost": 100}], "BuyingOrders": [{"ItemCount": 4, "ItemCost": 90}, {"ItemCount": 10, "ItemCost": 80}], }) def test_buy_walks_asks_ascending(monkeypatch): _book(monkeypatch) r = market.walk("X", "AI1", 10, "buy") assert r["total"] == 5 * 100 + 5 * 110 and r["worst"] == 110 and not r["short"] def test_sell_walks_bids_descending_and_reports_shortfall(monkeypatch): _book(monkeypatch) r = market.walk("X", "AI1", 20, "sell") assert r["filled"] == 14 and r["short"] and r["worst"] == 80 assert r["total"] == 4 * 90 + 10 * 80