oxarchive 0.2.2__py3-none-any.whl → 0.3.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
oxarchive/resources/trades.py
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
+
import warnings
|
|
6
|
+
from dataclasses import dataclass
|
|
5
7
|
from datetime import datetime
|
|
6
8
|
from typing import Literal, Optional
|
|
7
9
|
|
|
@@ -9,6 +11,13 @@ from ..http import HttpClient
|
|
|
9
11
|
from ..types import Trade, Timestamp
|
|
10
12
|
|
|
11
13
|
|
|
14
|
+
@dataclass
|
|
15
|
+
class CursorResponse:
|
|
16
|
+
"""Response with cursor for pagination."""
|
|
17
|
+
data: list[Trade]
|
|
18
|
+
next_cursor: Optional[str] = None
|
|
19
|
+
|
|
20
|
+
|
|
12
21
|
class TradesResource:
|
|
13
22
|
"""
|
|
14
23
|
Trades API resource.
|
|
@@ -17,8 +26,14 @@ class TradesResource:
|
|
|
17
26
|
>>> # Get recent trades
|
|
18
27
|
>>> trades = client.trades.recent("BTC")
|
|
19
28
|
>>>
|
|
20
|
-
>>> # Get trade history with
|
|
21
|
-
>>>
|
|
29
|
+
>>> # Get trade history with cursor-based pagination (recommended)
|
|
30
|
+
>>> result = client.trades.list("BTC", start="2024-01-01", end="2024-01-02")
|
|
31
|
+
>>> trades = result.data
|
|
32
|
+
>>>
|
|
33
|
+
>>> # Get all pages
|
|
34
|
+
>>> while result.next_cursor:
|
|
35
|
+
... result = client.trades.list("BTC", start="2024-01-01", end="2024-01-02", cursor=result.next_cursor)
|
|
36
|
+
... trades.extend(result.data)
|
|
22
37
|
"""
|
|
23
38
|
|
|
24
39
|
def __init__(self, http: HttpClient):
|
|
@@ -41,6 +56,90 @@ class TradesResource:
|
|
|
41
56
|
return None
|
|
42
57
|
|
|
43
58
|
def list(
|
|
59
|
+
self,
|
|
60
|
+
coin: str,
|
|
61
|
+
*,
|
|
62
|
+
start: Timestamp,
|
|
63
|
+
end: Timestamp,
|
|
64
|
+
cursor: Optional[Timestamp] = None,
|
|
65
|
+
limit: Optional[int] = None,
|
|
66
|
+
side: Optional[Literal["buy", "sell"]] = None,
|
|
67
|
+
) -> CursorResponse:
|
|
68
|
+
"""
|
|
69
|
+
Get trade history for a coin using cursor-based pagination.
|
|
70
|
+
|
|
71
|
+
Uses cursor-based pagination by default, which is more efficient for large datasets.
|
|
72
|
+
Use the next_cursor from the response as the cursor parameter to get the next page.
|
|
73
|
+
|
|
74
|
+
Args:
|
|
75
|
+
coin: The coin symbol (e.g., 'BTC', 'ETH')
|
|
76
|
+
start: Start timestamp (required)
|
|
77
|
+
end: End timestamp (required)
|
|
78
|
+
cursor: Cursor from previous response's next_cursor (timestamp)
|
|
79
|
+
limit: Maximum number of results (default: 100, max: 1000)
|
|
80
|
+
side: Filter by trade side
|
|
81
|
+
|
|
82
|
+
Returns:
|
|
83
|
+
CursorResponse with trades and next_cursor for pagination
|
|
84
|
+
|
|
85
|
+
Example:
|
|
86
|
+
>>> # First page
|
|
87
|
+
>>> result = client.trades.list("BTC", start=start, end=end, limit=1000)
|
|
88
|
+
>>> trades = result.data
|
|
89
|
+
>>>
|
|
90
|
+
>>> # Subsequent pages
|
|
91
|
+
>>> while result.next_cursor:
|
|
92
|
+
... result = client.trades.list(
|
|
93
|
+
... "BTC", start=start, end=end, cursor=result.next_cursor, limit=1000
|
|
94
|
+
... )
|
|
95
|
+
... trades.extend(result.data)
|
|
96
|
+
"""
|
|
97
|
+
data = self._http.get(
|
|
98
|
+
f"/v1/trades/{coin.upper()}",
|
|
99
|
+
params={
|
|
100
|
+
"start": self._convert_timestamp(start),
|
|
101
|
+
"end": self._convert_timestamp(end),
|
|
102
|
+
"cursor": self._convert_timestamp(cursor),
|
|
103
|
+
"limit": limit,
|
|
104
|
+
"side": side,
|
|
105
|
+
},
|
|
106
|
+
)
|
|
107
|
+
return CursorResponse(
|
|
108
|
+
data=[Trade.model_validate(item) for item in data["data"]],
|
|
109
|
+
next_cursor=data.get("meta", {}).get("next_cursor"),
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
async def alist(
|
|
113
|
+
self,
|
|
114
|
+
coin: str,
|
|
115
|
+
*,
|
|
116
|
+
start: Timestamp,
|
|
117
|
+
end: Timestamp,
|
|
118
|
+
cursor: Optional[Timestamp] = None,
|
|
119
|
+
limit: Optional[int] = None,
|
|
120
|
+
side: Optional[Literal["buy", "sell"]] = None,
|
|
121
|
+
) -> CursorResponse:
|
|
122
|
+
"""
|
|
123
|
+
Async version of list().
|
|
124
|
+
|
|
125
|
+
Uses cursor-based pagination by default.
|
|
126
|
+
"""
|
|
127
|
+
data = await self._http.aget(
|
|
128
|
+
f"/v1/trades/{coin.upper()}",
|
|
129
|
+
params={
|
|
130
|
+
"start": self._convert_timestamp(start),
|
|
131
|
+
"end": self._convert_timestamp(end),
|
|
132
|
+
"cursor": self._convert_timestamp(cursor),
|
|
133
|
+
"limit": limit,
|
|
134
|
+
"side": side,
|
|
135
|
+
},
|
|
136
|
+
)
|
|
137
|
+
return CursorResponse(
|
|
138
|
+
data=[Trade.model_validate(item) for item in data["data"]],
|
|
139
|
+
next_cursor=data.get("meta", {}).get("next_cursor"),
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
def list_with_offset(
|
|
44
143
|
self,
|
|
45
144
|
coin: str,
|
|
46
145
|
*,
|
|
@@ -51,7 +150,10 @@ class TradesResource:
|
|
|
51
150
|
side: Optional[Literal["buy", "sell"]] = None,
|
|
52
151
|
) -> list[Trade]:
|
|
53
152
|
"""
|
|
54
|
-
Get trade history
|
|
153
|
+
Get trade history using offset-based pagination.
|
|
154
|
+
|
|
155
|
+
.. deprecated::
|
|
156
|
+
Use list() with cursor-based pagination instead for better performance.
|
|
55
157
|
|
|
56
158
|
Args:
|
|
57
159
|
coin: The coin symbol (e.g., 'BTC', 'ETH')
|
|
@@ -64,6 +166,11 @@ class TradesResource:
|
|
|
64
166
|
Returns:
|
|
65
167
|
List of trades
|
|
66
168
|
"""
|
|
169
|
+
warnings.warn(
|
|
170
|
+
"list_with_offset() is deprecated. Use list() with cursor-based pagination instead.",
|
|
171
|
+
DeprecationWarning,
|
|
172
|
+
stacklevel=2,
|
|
173
|
+
)
|
|
67
174
|
data = self._http.get(
|
|
68
175
|
f"/v1/trades/{coin.upper()}",
|
|
69
176
|
params={
|
|
@@ -76,7 +183,7 @@ class TradesResource:
|
|
|
76
183
|
)
|
|
77
184
|
return [Trade.model_validate(item) for item in data["data"]]
|
|
78
185
|
|
|
79
|
-
async def
|
|
186
|
+
async def alist_with_offset(
|
|
80
187
|
self,
|
|
81
188
|
coin: str,
|
|
82
189
|
*,
|
|
@@ -86,7 +193,17 @@ class TradesResource:
|
|
|
86
193
|
offset: Optional[int] = None,
|
|
87
194
|
side: Optional[Literal["buy", "sell"]] = None,
|
|
88
195
|
) -> list[Trade]:
|
|
89
|
-
"""
|
|
196
|
+
"""
|
|
197
|
+
Async version of list_with_offset().
|
|
198
|
+
|
|
199
|
+
.. deprecated::
|
|
200
|
+
Use alist() with cursor-based pagination instead.
|
|
201
|
+
"""
|
|
202
|
+
warnings.warn(
|
|
203
|
+
"alist_with_offset() is deprecated. Use alist() with cursor-based pagination instead.",
|
|
204
|
+
DeprecationWarning,
|
|
205
|
+
stacklevel=2,
|
|
206
|
+
)
|
|
90
207
|
data = await self._http.aget(
|
|
91
208
|
f"/v1/trades/{coin.upper()}",
|
|
92
209
|
params={
|
|
@@ -123,3 +240,60 @@ class TradesResource:
|
|
|
123
240
|
params={"limit": limit},
|
|
124
241
|
)
|
|
125
242
|
return [Trade.model_validate(item) for item in data["data"]]
|
|
243
|
+
|
|
244
|
+
def list_cursor(
|
|
245
|
+
self,
|
|
246
|
+
coin: str,
|
|
247
|
+
*,
|
|
248
|
+
start: Timestamp,
|
|
249
|
+
end: Timestamp,
|
|
250
|
+
cursor: Optional[Timestamp] = None,
|
|
251
|
+
limit: Optional[int] = None,
|
|
252
|
+
side: Optional[Literal["buy", "sell"]] = None,
|
|
253
|
+
) -> CursorResponse:
|
|
254
|
+
"""
|
|
255
|
+
Get trade history using cursor-based pagination.
|
|
256
|
+
|
|
257
|
+
.. deprecated::
|
|
258
|
+
Use list() instead - it now uses cursor-based pagination by default.
|
|
259
|
+
|
|
260
|
+
Args:
|
|
261
|
+
coin: The coin symbol (e.g., 'BTC', 'ETH')
|
|
262
|
+
start: Start timestamp (required)
|
|
263
|
+
end: End timestamp (required)
|
|
264
|
+
cursor: Cursor from previous response's next_cursor (timestamp)
|
|
265
|
+
limit: Maximum number of results
|
|
266
|
+
side: Filter by trade side
|
|
267
|
+
|
|
268
|
+
Returns:
|
|
269
|
+
CursorResponse with trades and next_cursor for pagination
|
|
270
|
+
"""
|
|
271
|
+
warnings.warn(
|
|
272
|
+
"list_cursor() is deprecated. Use list() instead - it now uses cursor-based pagination by default.",
|
|
273
|
+
DeprecationWarning,
|
|
274
|
+
stacklevel=2,
|
|
275
|
+
)
|
|
276
|
+
return self.list(coin, start=start, end=end, cursor=cursor, limit=limit, side=side)
|
|
277
|
+
|
|
278
|
+
async def alist_cursor(
|
|
279
|
+
self,
|
|
280
|
+
coin: str,
|
|
281
|
+
*,
|
|
282
|
+
start: Timestamp,
|
|
283
|
+
end: Timestamp,
|
|
284
|
+
cursor: Optional[Timestamp] = None,
|
|
285
|
+
limit: Optional[int] = None,
|
|
286
|
+
side: Optional[Literal["buy", "sell"]] = None,
|
|
287
|
+
) -> CursorResponse:
|
|
288
|
+
"""
|
|
289
|
+
Async version of list_cursor().
|
|
290
|
+
|
|
291
|
+
.. deprecated::
|
|
292
|
+
Use alist() instead - it now uses cursor-based pagination by default.
|
|
293
|
+
"""
|
|
294
|
+
warnings.warn(
|
|
295
|
+
"alist_cursor() is deprecated. Use alist() instead - it now uses cursor-based pagination by default.",
|
|
296
|
+
DeprecationWarning,
|
|
297
|
+
stacklevel=2,
|
|
298
|
+
)
|
|
299
|
+
return await self.alist(coin, start=start, end=end, cursor=cursor, limit=limit, side=side)
|
|
@@ -8,7 +8,7 @@ oxarchive/resources/funding.py,sha256=TXkZxodVQTVcVbzNG6SpMQAzf8AkLm2NYZJxnP4MNX
|
|
|
8
8
|
oxarchive/resources/instruments.py,sha256=flD1sH6x3P3CTqV1ZwkfwbranVacmhsHn5Dhr7lGQhM,1606
|
|
9
9
|
oxarchive/resources/openinterest.py,sha256=h13yLA72LpfryUf8IqF6W7uE4ObYY2Qbc-auv4LtPqc,3552
|
|
10
10
|
oxarchive/resources/orderbook.py,sha256=o_DTdpzKrZvHL9YXm8cGGUugPM8uUa6r9O_72r1ByV0,4557
|
|
11
|
-
oxarchive/resources/trades.py,sha256=
|
|
12
|
-
oxarchive-0.
|
|
13
|
-
oxarchive-0.
|
|
14
|
-
oxarchive-0.
|
|
11
|
+
oxarchive/resources/trades.py,sha256=XCi2rXA2hxaTt0KNlWw8f7W0hzAvNWyT7DaivMz_rHw,10012
|
|
12
|
+
oxarchive-0.3.0.dist-info/METADATA,sha256=yq_BurBDJwE1f1Nv6IANatT2KPE0uJ-7OUaY1N-omPk,8749
|
|
13
|
+
oxarchive-0.3.0.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
14
|
+
oxarchive-0.3.0.dist-info/RECORD,,
|
|
File without changes
|