Allow store the status of an order
This commit is contained in:
parent
0921b7205e
commit
a33a60b879
@ -22,9 +22,10 @@ def apply_database_schema(connection):
|
|||||||
type varchar,
|
type varchar,
|
||||||
instrument char(12),
|
instrument char(12),
|
||||||
limit_price varchar,
|
limit_price varchar,
|
||||||
quantity varchar,
|
quantity int,
|
||||||
created_at timestamp
|
created_at timestamp,
|
||||||
);
|
status varchar DEFAULT('pending')
|
||||||
|
)
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -62,3 +63,12 @@ def insert_order(connection, order: Order):
|
|||||||
order.created_at = returned_row[1]
|
order.created_at = returned_row[1]
|
||||||
|
|
||||||
return order
|
return order
|
||||||
|
|
||||||
|
|
||||||
|
def mark_order_as(connection, order_id, status):
|
||||||
|
connection.execute(
|
||||||
|
"""
|
||||||
|
UPDATE orders set status = :status where id = :order_id
|
||||||
|
""",
|
||||||
|
{"status": status, "order_id": order_id},
|
||||||
|
)
|
||||||
|
@ -26,5 +26,27 @@ def test_store_order(db_connection):
|
|||||||
assert record[2] == order.type_.value
|
assert record[2] == order.type_.value
|
||||||
assert record[3] == order.instrument
|
assert record[3] == order.instrument
|
||||||
assert record[4] == str(order.limit_price)
|
assert record[4] == str(order.limit_price)
|
||||||
assert record[5] == str(order.quantity)
|
assert record[5] == order.quantity
|
||||||
assert record[6] == order.created_at
|
assert record[6] == order.created_at
|
||||||
|
assert record[7] == "pending"
|
||||||
|
|
||||||
|
|
||||||
|
def test_mark_order_as(db_connection):
|
||||||
|
order = Order(
|
||||||
|
id="",
|
||||||
|
created_at=datetime.now(),
|
||||||
|
side=OrderSide.BUY,
|
||||||
|
type=OrderType.LIMIT,
|
||||||
|
instrument="123456789123",
|
||||||
|
limit_price=123.00,
|
||||||
|
quantity=1,
|
||||||
|
)
|
||||||
|
database.insert_order(db_connection, order)
|
||||||
|
|
||||||
|
database.mark_order_as(db_connection, order.id_, "failed")
|
||||||
|
|
||||||
|
record = db_connection.execute(
|
||||||
|
"SELECT status FROM orders where id = :id", {"id": order.id_}
|
||||||
|
).fetchone()
|
||||||
|
|
||||||
|
assert record[0] == "failed"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user