Skip to content

Commit 4afd282

Browse files
author
Caleb Quilley
committed
Fix tests
1 parent f7963ad commit 4afd282

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

cogs/commands/market.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,7 @@ def match(self):
7575

7676
earliest_trade = min(bid, ask, key=lambda x: x.order_time)
7777

78-
bid.price = earliest_trade.price
79-
ask.price = earliest_trade.price
80-
81-
bought = Order(earliest_trade.price, 'bid', bid.price, qty, bid.order_time)
78+
bought = Order(earliest_trade.price, 'bid', bid.user_id, qty, bid.order_time)
8279
sold = Order(earliest_trade.price, 'ask', ask.user_id, qty, ask.order_time)
8380

8481
self.trade_history[bid.user_id].append(bought)
@@ -164,7 +161,7 @@ def __str__(self):
164161
bid_vol = bid_counts.get(price, [" " * 15] * 2)
165162
ask_vol = ask_counts.get(price, [" " * 10] * 2)
166163
formatted_price = f"{price:.2f}"
167-
order_book_lines.append(f"{str(bid_vol[0])} | {str(bid_vol[1]):<15} | {str(formatted_price):<10} | {str(ask_vol[1]):<15} | {str(ask_vol)[0]}")
164+
order_book_lines.append(f"{str(bid_vol[0]):<15} | {str(bid_vol[1]):<15} | {str(formatted_price):<10} | {str(ask_vol[1]):<15} | {str(ask_vol)[0]}")
168165

169166
order_book_lines.append("```")
170167

tests/test_market.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@ def test_can_place_orders():
1010
assert len(m.bids) == 1
1111

1212
assert str(m) == """Market is: OPEN
13+
1314
📊 **TEST Order Book** 📊
14-
Bid Orders | Bid Volume | Price | Ask Volume | Ask Orders
15-
| | 102 | 7 | 2
16-
1 | 3 | 101 | |
17-
"""
15+
16+
Bid Orders | Bid Volume | Price | Ask Volume | Ask Orders
17+
| | 102.00 | 5 | 2
18+
1 | 3 | 101.00 | |
19+
20+
Last Trade: None"""
1821

1922
def test_single_match():
2023
m = Market("test")
@@ -46,6 +49,7 @@ def test_multi_match():
4649
assert m.asks[0].user_id == 3
4750
assert len(m.trade_history[1]) == 1
4851
assert len(m.trade_history[2]) == 1
52+
assert 3 not in m.trade_history
4953
assert len(m.trade_history[4]) == 2
5054

5155
def test_turning():
@@ -63,11 +67,10 @@ def test_multi_level_clear():
6367
assert m.ask(101, 1, 1, 2) is None
6468
assert m.ask(102, 1, 1, 3) is None
6569
assert m.ask(103, 1, 100, 4) is None
66-
assert m.bid(103, 2, 10, 4) == """<@2> bought 1 from <@1> at 100
70+
assert m.bid(103, 2, 10, 5) == """<@2> bought 1 from <@1> at 100
6771
<@2> bought 1 from <@1> at 101
6872
<@2> bought 1 from <@1> at 102
69-
<@2> bought 7 from <@1> at 103
70-
"""
73+
<@2> bought 7 from <@1> at 103"""
7174
assert len(m.bids) == 0
7275
assert len(m.asks) == 1
7376
assert m.asks[0].qty == 93

0 commit comments

Comments
 (0)