|
@@ -11,7 +11,7 @@ from uuid import uuid4
|
|
|
from fastapi import HTTPException
|
|
from fastapi import HTTPException
|
|
|
|
|
|
|
|
from .bitstamp import BitstampClient, BitstampError
|
|
from .bitstamp import BitstampClient, BitstampError
|
|
|
-from .services_bitstamp import get_bitstamp_client, clear_bitstamp_trading_client
|
|
|
|
|
|
|
+from .services_bitstamp import get_bitstamp_client, clear_bitstamp_trading_client, invalidate_account_cache
|
|
|
from .bitstamp_metadata import load_market_by_symbol
|
|
from .bitstamp_metadata import load_market_by_symbol
|
|
|
from .storage import get_connection
|
|
from .storage import get_connection
|
|
|
|
|
|
|
@@ -174,6 +174,8 @@ def place_order(*, account_id: str, market: str, side: str, order_type: str, amo
|
|
|
)
|
|
)
|
|
|
conn.commit()
|
|
conn.commit()
|
|
|
|
|
|
|
|
|
|
+ invalidate_account_cache(account_id)
|
|
|
|
|
+
|
|
|
return {"ok": True, "bitstamp_order_id": bitstamp_order_id, "record_id": record_id, "status": str(result.get("status", "open")), "raw": result}
|
|
return {"ok": True, "bitstamp_order_id": bitstamp_order_id, "record_id": record_id, "status": str(result.get("status", "open")), "raw": result}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -218,6 +220,7 @@ def get_open_orders(*, account_id: str, client_id: str | None = None) -> dict:
|
|
|
status = _normalize_status(result.get("status", "unknown"))
|
|
status = _normalize_status(result.get("status", "unknown"))
|
|
|
if status not in OPEN_ORDER_STATUSES:
|
|
if status not in OPEN_ORDER_STATUSES:
|
|
|
_set_local_order_status(bitstamp_order_id=str(bitstamp_order_id), status=status)
|
|
_set_local_order_status(bitstamp_order_id=str(bitstamp_order_id), status=status)
|
|
|
|
|
+ invalidate_account_cache(account_id)
|
|
|
continue
|
|
continue
|
|
|
order["status"] = status
|
|
order["status"] = status
|
|
|
order["raw_json"] = json.dumps(result)
|
|
order["raw_json"] = json.dumps(result)
|
|
@@ -226,6 +229,7 @@ def get_open_orders(*, account_id: str, client_id: str | None = None) -> dict:
|
|
|
msg = str(exc)
|
|
msg = str(exc)
|
|
|
if "not found" in msg.lower():
|
|
if "not found" in msg.lower():
|
|
|
_set_local_order_status(bitstamp_order_id=str(bitstamp_order_id), status="missing")
|
|
_set_local_order_status(bitstamp_order_id=str(bitstamp_order_id), status="missing")
|
|
|
|
|
+ invalidate_account_cache(account_id)
|
|
|
continue
|
|
continue
|
|
|
# Best effort: keep the local record when the exchange cannot be queried.
|
|
# Best effort: keep the local record when the exchange cannot be queried.
|
|
|
orders.append(order)
|
|
orders.append(order)
|
|
@@ -258,6 +262,7 @@ def cancel_all_orders(*, account_id: str, client_id: str | None = None) -> dict:
|
|
|
break
|
|
break
|
|
|
if "not found" in detail.lower():
|
|
if "not found" in detail.lower():
|
|
|
_set_local_order_status(bitstamp_order_id=bitstamp_order_id, status="missing")
|
|
_set_local_order_status(bitstamp_order_id=bitstamp_order_id, status="missing")
|
|
|
|
|
+ invalidate_account_cache(account_id)
|
|
|
results.append({"ok": False, "order_id": bitstamp_order_id, "error": detail, "status": "missing"})
|
|
results.append({"ok": False, "order_id": bitstamp_order_id, "error": detail, "status": "missing"})
|
|
|
continue
|
|
continue
|
|
|
raise
|
|
raise
|
|
@@ -284,6 +289,8 @@ def query_order(*, account_id: str, order_id, client_order_id: str | None = None
|
|
|
)
|
|
)
|
|
|
conn.commit()
|
|
conn.commit()
|
|
|
|
|
|
|
|
|
|
+ invalidate_account_cache(account_id)
|
|
|
|
|
+
|
|
|
return {"ok": True, "order_id": order_id, "raw": result}
|
|
return {"ok": True, "order_id": order_id, "raw": result}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -309,4 +316,6 @@ def cancel_order(*, account_id: str, order_id) -> dict:
|
|
|
)
|
|
)
|
|
|
conn.commit()
|
|
conn.commit()
|
|
|
|
|
|
|
|
|
|
+ invalidate_account_cache(account_id)
|
|
|
|
|
+
|
|
|
return {"ok": bool(result), "order_id": order_id, "raw": result}
|
|
return {"ok": bool(result), "order_id": order_id, "raw": result}
|