|
55 | 55 | ) |
56 | 56 | from app.services.quick_trade.symbols import is_supported_crypto_exchange, symbols_match as quick_trade_symbols_match |
57 | 57 | from app.services.quick_trade.history import parse_quick_trade_metadata, history_order_status |
| 58 | +from app.services.quick_trade.trade_history import resolve_trade_history |
58 | 59 | from app.services.quick_trade.fee_reconciliation import fee_update_from_fill, reconcile_quick_trade_fees |
59 | 60 | from app.services.quick_trade.order_reconciliation import reconcile_quick_trade_orders |
60 | 61 | from app.services.quick_trade.account_warmup import configure_quick_trade_derivatives, warm_quick_trade_account |
@@ -1876,43 +1877,8 @@ def get_history(): |
1876 | 1877 | "created_at": to_utc_iso(r.get("created_at")) or str(r.get("created_at") or ""), |
1877 | 1878 | }) |
1878 | 1879 |
|
1879 | | - exchange_history = {"supported": False, "trades": []} |
1880 | | - if credential_id > 0 and symbol and market_type in ("spot", "swap"): |
1881 | | - try: |
1882 | | - from app.services.quick_trade.trade_history import exchange_trade_history |
1883 | | - |
1884 | | - config = build_exchange_config(credential_id, user_id, {"market_type": market_type}) |
1885 | | - client = create_exchange_client(config, market_type=market_type) |
1886 | | - exchange_history = exchange_trade_history( |
1887 | | - client, |
1888 | | - symbol, |
1889 | | - market_type=market_type, |
1890 | | - limit=limit, |
1891 | | - offset=offset, |
1892 | | - ) |
1893 | | - except Exception as exc: |
1894 | | - logger.info("Native exchange trade history unavailable: %s", exc) |
1895 | | - |
1896 | | - if exchange_history.get("supported"): |
1897 | | - active_statuses = { |
1898 | | - "new", "open", "pending", "submitted", "partially_filled", |
1899 | | - "partially-filled", "accepted", "cancel_pending", |
1900 | | - } |
1901 | | - pending_orders = [ |
1902 | | - trade for trade in trades |
1903 | | - if str(trade.get("status") or "").strip().lower() in active_statuses |
1904 | | - ] |
1905 | | - trades = pending_orders + list(exchange_history.get("trades") or []) |
1906 | | - trades.sort(key=lambda trade: str(trade.get("created_at") or ""), reverse=True) |
1907 | | - |
1908 | | - return jsonify({ |
1909 | | - "code": 1, |
1910 | | - "msg": "success", |
1911 | | - "data": { |
1912 | | - "trades": trades, |
1913 | | - "source": "exchange" if exchange_history.get("supported") else "local_fallback", |
1914 | | - }, |
1915 | | - }) |
| 1880 | + data = resolve_trade_history(trades, user_id, credential_id, symbol, market_type, limit, offset) |
| 1881 | + return jsonify({"code": 1, "msg": "success", "data": data}) |
1916 | 1882 | except Exception as e: |
1917 | 1883 | logger.error(f"get_history failed: {e}") |
1918 | 1884 | return jsonify({"code": 0, "msg": str(e)}), 500 |
|
0 commit comments