orionapi 2.20.0__tar.gz → 2.22.0__tar.gz
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
__version__ = "2.
|
|
1
|
+
__version__ = "2.22.0"
|
|
2
2
|
|
|
3
3
|
import logging
|
|
4
4
|
import re
|
|
@@ -187,17 +187,20 @@ class BaseAPI:
|
|
|
187
187
|
|
|
188
188
|
base_url = None
|
|
189
189
|
|
|
190
|
-
def __init__(self, rate_limit=10, verify_ssl=True, ca_bundle=None):
|
|
190
|
+
def __init__(self, rate_limit=10, verify_ssl=True, ca_bundle=None, timeout=30):
|
|
191
191
|
"""Initialize base API with rate limiting and SSL configuration.
|
|
192
192
|
|
|
193
193
|
Args:
|
|
194
194
|
rate_limit: Maximum API calls per second (default 10, set to 0 to disable)
|
|
195
195
|
verify_ssl: Verify SSL certificates (default True)
|
|
196
196
|
ca_bundle: Path to custom CA bundle file (optional)
|
|
197
|
+
timeout: Default per-request timeout in seconds (default 30). Used by
|
|
198
|
+
:meth:`api_request` when a call doesn't pass its own ``timeout``.
|
|
197
199
|
"""
|
|
198
200
|
self._rate_limiter = RateLimiter(calls_per_second=rate_limit)
|
|
199
201
|
self.verify_ssl = verify_ssl
|
|
200
202
|
self.ca_bundle = ca_bundle
|
|
203
|
+
self.timeout = timeout
|
|
201
204
|
# RLock so subclasses can hold the lock across an internal call
|
|
202
205
|
# path that re-enters auth-header construction.
|
|
203
206
|
self._token_lock = threading.RLock()
|
|
@@ -249,7 +252,7 @@ class BaseAPI:
|
|
|
249
252
|
|
|
250
253
|
return data
|
|
251
254
|
|
|
252
|
-
def api_request(self, url, req_func=None, timeout=
|
|
255
|
+
def api_request(self, url, req_func=None, timeout=None, **kwargs):
|
|
253
256
|
"""Make an authenticated API request with error handling.
|
|
254
257
|
|
|
255
258
|
Args:
|
|
@@ -258,7 +261,9 @@ class BaseAPI:
|
|
|
258
261
|
Defaults to ``requests.get``. Resolved at call time (not bound as a
|
|
259
262
|
default argument) so that patching ``requests.get`` in tests takes
|
|
260
263
|
effect for GET methods.
|
|
261
|
-
timeout:
|
|
264
|
+
timeout: Per-call request timeout in seconds. When None (default), falls
|
|
265
|
+
back to the client's ``self.timeout`` (set in the constructor,
|
|
266
|
+
default 30).
|
|
262
267
|
**kwargs: Additional arguments passed to the request
|
|
263
268
|
|
|
264
269
|
Returns:
|
|
@@ -271,6 +276,8 @@ class BaseAPI:
|
|
|
271
276
|
"""
|
|
272
277
|
if req_func is None:
|
|
273
278
|
req_func = requests.get
|
|
279
|
+
if timeout is None:
|
|
280
|
+
timeout = self.timeout
|
|
274
281
|
|
|
275
282
|
# Apply rate limiting
|
|
276
283
|
self._rate_limiter.wait()
|
|
@@ -338,8 +345,12 @@ class OrionAPI(BaseAPI):
|
|
|
338
345
|
'user@example.com'
|
|
339
346
|
"""
|
|
340
347
|
|
|
341
|
-
def __init__(
|
|
342
|
-
|
|
348
|
+
def __init__(
|
|
349
|
+
self, usr=None, pwd=None, rate_limit=10, verify_ssl=True, ca_bundle=None, timeout=30
|
|
350
|
+
):
|
|
351
|
+
super().__init__(
|
|
352
|
+
rate_limit=rate_limit, verify_ssl=verify_ssl, ca_bundle=ca_bundle, timeout=timeout
|
|
353
|
+
)
|
|
343
354
|
self.token = None
|
|
344
355
|
self.base_url = "https://api.orionadvisor.com/api/v1/"
|
|
345
356
|
self._custom_field_cache = {}
|
|
@@ -2124,8 +2135,11 @@ class EclipseBase(BaseAPI):
|
|
|
2124
2135
|
rate_limit=10,
|
|
2125
2136
|
verify_ssl=True,
|
|
2126
2137
|
ca_bundle=None,
|
|
2138
|
+
timeout=30,
|
|
2127
2139
|
):
|
|
2128
|
-
super().__init__(
|
|
2140
|
+
super().__init__(
|
|
2141
|
+
rate_limit=rate_limit, verify_ssl=verify_ssl, ca_bundle=ca_bundle, timeout=timeout
|
|
2142
|
+
)
|
|
2129
2143
|
self.eclipse_token = None
|
|
2130
2144
|
self.base_url = "https://api.orioneclipse.com/v1"
|
|
2131
2145
|
# The v2 surface lives at the host root (/api/v2/...), NOT under /v1.
|
|
@@ -4245,6 +4259,24 @@ class EclipseV1(EclipseBase):
|
|
|
4245
4259
|
res = self.api_request(f"{self.base_url}/tradeorder/instances/{instance_id}/tradeLogs")
|
|
4246
4260
|
return res.json()
|
|
4247
4261
|
|
|
4262
|
+
def get_instance_trades(self, instance_id, status=None):
|
|
4263
|
+
"""Get the trades belonging to a trade instance.
|
|
4264
|
+
|
|
4265
|
+
Args:
|
|
4266
|
+
instance_id: Trade instance ID
|
|
4267
|
+
status: Optional status filter, "open" or "closed" (maps to ``status``)
|
|
4268
|
+
|
|
4269
|
+
Returns:
|
|
4270
|
+
list: Trade dicts for the instance
|
|
4271
|
+
"""
|
|
4272
|
+
params = {}
|
|
4273
|
+
if status is not None:
|
|
4274
|
+
params["status"] = status
|
|
4275
|
+
res = self.api_request(
|
|
4276
|
+
f"{self.base_url}/tradeorder/instances/{instance_id}/trades", params=params
|
|
4277
|
+
)
|
|
4278
|
+
return res.json()
|
|
4279
|
+
|
|
4248
4280
|
def get_trade_log_detail(self, log_id):
|
|
4249
4281
|
"""Get detailed HTML trade log showing trading engine decision-making.
|
|
4250
4282
|
|
|
@@ -10817,6 +10849,7 @@ class Eclipse(EclipseBase):
|
|
|
10817
10849
|
rate_limit=10,
|
|
10818
10850
|
verify_ssl=True,
|
|
10819
10851
|
ca_bundle=None,
|
|
10852
|
+
timeout=30,
|
|
10820
10853
|
):
|
|
10821
10854
|
super().__init__(
|
|
10822
10855
|
usr=usr,
|
|
@@ -10826,6 +10859,7 @@ class Eclipse(EclipseBase):
|
|
|
10826
10859
|
rate_limit=rate_limit,
|
|
10827
10860
|
verify_ssl=verify_ssl,
|
|
10828
10861
|
ca_bundle=ca_bundle,
|
|
10862
|
+
timeout=timeout,
|
|
10829
10863
|
)
|
|
10830
10864
|
# Share the single authenticated token with both sub-clients (no re-login).
|
|
10831
10865
|
sub_kwargs = {
|
|
@@ -10833,6 +10867,7 @@ class Eclipse(EclipseBase):
|
|
|
10833
10867
|
"rate_limit": rate_limit,
|
|
10834
10868
|
"verify_ssl": verify_ssl,
|
|
10835
10869
|
"ca_bundle": ca_bundle,
|
|
10870
|
+
"timeout": timeout,
|
|
10836
10871
|
}
|
|
10837
10872
|
self.v1 = EclipseV1(**sub_kwargs)
|
|
10838
10873
|
self.v2 = EclipseV2(**sub_kwargs)
|
|
File without changes
|