|
| 1 | +"""``client.arbitrage`` — exchange + market arbitrage operations. |
| 2 | +
|
| 3 | +Two distinct flavours: |
| 4 | + • ``exchange_*`` — cross-exchange arbitrage. |
| 5 | + • ``market_*`` — intra-exchange market arbitrage. |
| 6 | +Plus a shared backlog API. |
| 7 | +""" |
| 8 | + |
| 9 | +from __future__ import annotations |
| 10 | + |
| 11 | +from collections.abc import Sequence |
| 12 | +from typing import TYPE_CHECKING, Any |
| 13 | + |
| 14 | +if TYPE_CHECKING: |
| 15 | + from .._client import CryptohopperClient |
| 16 | + |
| 17 | +BacklogId = int | str |
| 18 | + |
| 19 | + |
| 20 | +class Arbitrage: |
| 21 | + def __init__(self, client: CryptohopperClient) -> None: |
| 22 | + self._client = client |
| 23 | + |
| 24 | + # ─── Cross-exchange arbitrage ───────────────────────────────────────── |
| 25 | + |
| 26 | + def exchange_start(self, data: dict[str, Any]) -> dict[str, Any]: |
| 27 | + """Start a cross-exchange arbitrage run. Requires ``trade``.""" |
| 28 | + return self._client._request("POST", "/arbitrage/exchange", json=data) |
| 29 | + |
| 30 | + def exchange_cancel(self, data: dict[str, Any] | None = None) -> dict[str, Any]: |
| 31 | + """Cancel a cross-exchange arbitrage run. Requires ``trade``.""" |
| 32 | + return self._client._request("POST", "/arbitrage/cancel", json=data or {}) |
| 33 | + |
| 34 | + def exchange_results(self, **params: Any) -> Sequence[dict[str, Any]]: |
| 35 | + """Fetch results of exchange-arbitrage runs. Requires ``read``.""" |
| 36 | + return self._client._request( |
| 37 | + "GET", "/arbitrage/results", params=params or None |
| 38 | + ) |
| 39 | + |
| 40 | + def exchange_history(self, **params: Any) -> Sequence[dict[str, Any]]: |
| 41 | + """Historical exchange-arbitrage runs. Requires ``read``.""" |
| 42 | + return self._client._request( |
| 43 | + "GET", "/arbitrage/history", params=params or None |
| 44 | + ) |
| 45 | + |
| 46 | + def exchange_total(self) -> dict[str, Any]: |
| 47 | + """Running totals across exchange-arbitrage runs. Requires ``read``.""" |
| 48 | + return self._client._request("GET", "/arbitrage/total") |
| 49 | + |
| 50 | + def exchange_reset_total(self) -> dict[str, Any]: |
| 51 | + """Reset the running totals. Requires ``manage``.""" |
| 52 | + return self._client._request("POST", "/arbitrage/resettotal", json={}) |
| 53 | + |
| 54 | + # ─── Intra-exchange market arbitrage ────────────────────────────────── |
| 55 | + |
| 56 | + def market_start(self, data: dict[str, Any]) -> dict[str, Any]: |
| 57 | + """Start an intra-exchange arbitrage run. Requires ``trade``.""" |
| 58 | + return self._client._request("POST", "/arbitrage/market", json=data) |
| 59 | + |
| 60 | + def market_cancel(self, data: dict[str, Any] | None = None) -> dict[str, Any]: |
| 61 | + """Cancel a market-arbitrage run. Requires ``trade``.""" |
| 62 | + return self._client._request("POST", "/arbitrage/market-cancel", json=data or {}) |
| 63 | + |
| 64 | + def market_result(self, **params: Any) -> dict[str, Any]: |
| 65 | + """Result of a specific market-arbitrage run. Requires ``read``.""" |
| 66 | + return self._client._request( |
| 67 | + "GET", "/arbitrage/market-result", params=params or None |
| 68 | + ) |
| 69 | + |
| 70 | + def market_history(self, **params: Any) -> Sequence[dict[str, Any]]: |
| 71 | + """Historical market-arb runs. Requires ``read``.""" |
| 72 | + return self._client._request( |
| 73 | + "GET", "/arbitrage/market-history", params=params or None |
| 74 | + ) |
| 75 | + |
| 76 | + # ─── Backlog (shared) ──────────────────────────────────────────────── |
| 77 | + |
| 78 | + def backlogs(self, **params: Any) -> Sequence[dict[str, Any]]: |
| 79 | + """List queued/pending backlog items. Requires ``read``.""" |
| 80 | + return self._client._request( |
| 81 | + "GET", "/arbitrage/get-backlogs", params=params or None |
| 82 | + ) |
| 83 | + |
| 84 | + def backlog(self, backlog_id: BacklogId) -> dict[str, Any]: |
| 85 | + """Fetch a single backlog item. Requires ``read``.""" |
| 86 | + return self._client._request( |
| 87 | + "GET", "/arbitrage/get-backlog", params={"backlog_id": backlog_id} |
| 88 | + ) |
| 89 | + |
| 90 | + def delete_backlog(self, backlog_id: BacklogId) -> dict[str, Any]: |
| 91 | + """Delete a backlog item. Requires ``manage``.""" |
| 92 | + return self._client._request( |
| 93 | + "POST", "/arbitrage/delete-backlog", json={"backlog_id": backlog_id} |
| 94 | + ) |
0 commit comments