finclient 0.12.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.
- finclient/__init__.py +47 -0
- finclient/_encode.py +72 -0
- finclient/_errors.py +125 -0
- finclient/_generated/__init__.py +1 -0
- finclient/_generated/copy_types.py +1983 -0
- finclient/_generated/graph_ops.py +2393 -0
- finclient/_generated/graph_types.py +881 -0
- finclient/_generated/news_ops.py +816 -0
- finclient/_generated/news_types.py +323 -0
- finclient/_generated/social_ops.py +1239 -0
- finclient/_generated/social_types.py +416 -0
- finclient/_paging.py +104 -0
- finclient/_runtime.py +8 -0
- finclient/_service.py +269 -0
- finclient/_transport.py +135 -0
- finclient/_version.py +3 -0
- finclient/client.py +112 -0
- finclient/copy/__init__.py +39 -0
- finclient/copy/_common.py +87 -0
- finclient/copy/accounts.py +254 -0
- finclient/copy/changes.py +63 -0
- finclient/copy/fx.py +235 -0
- finclient/copy/orders.py +55 -0
- finclient/copy/sse.py +48 -0
- finclient/copy/webhooks.py +70 -0
- finclient/py.typed +0 -0
- finclient-0.12.0.dist-info/METADATA +206 -0
- finclient-0.12.0.dist-info/RECORD +30 -0
- finclient-0.12.0.dist-info/WHEEL +4 -0
- finclient-0.12.0.dist-info/licenses/LICENSE +21 -0
finclient/__init__.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"""FinClient: one client for the FinCopy, FinGraph, FinNews and FinSocial APIs."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
from ._errors import (
|
|
5
|
+
ApiConnectionError,
|
|
6
|
+
ApiResponseError,
|
|
7
|
+
AuthenticationError,
|
|
8
|
+
FinApiError,
|
|
9
|
+
InsufficientCreditsError,
|
|
10
|
+
MissingApiKeyError,
|
|
11
|
+
NotFoundError,
|
|
12
|
+
PermissionDeniedError,
|
|
13
|
+
RateLimitError,
|
|
14
|
+
ServerError,
|
|
15
|
+
)
|
|
16
|
+
from ._paging import Page, PageInfo
|
|
17
|
+
from ._transport import HttpRequest, HttpResponse, StreamResponse, Transport, TransportError, UrllibTransport
|
|
18
|
+
from ._version import __version__
|
|
19
|
+
from .client import FinClient, ServiceOptions
|
|
20
|
+
from .copy import FinWebhook, StreamEvent, verify_signature
|
|
21
|
+
|
|
22
|
+
__all__ = [
|
|
23
|
+
"ApiConnectionError",
|
|
24
|
+
"ApiResponseError",
|
|
25
|
+
"AuthenticationError",
|
|
26
|
+
"FinApiError",
|
|
27
|
+
"FinClient",
|
|
28
|
+
"FinWebhook",
|
|
29
|
+
"HttpRequest",
|
|
30
|
+
"HttpResponse",
|
|
31
|
+
"InsufficientCreditsError",
|
|
32
|
+
"MissingApiKeyError",
|
|
33
|
+
"NotFoundError",
|
|
34
|
+
"Page",
|
|
35
|
+
"PageInfo",
|
|
36
|
+
"PermissionDeniedError",
|
|
37
|
+
"RateLimitError",
|
|
38
|
+
"ServerError",
|
|
39
|
+
"ServiceOptions",
|
|
40
|
+
"StreamEvent",
|
|
41
|
+
"StreamResponse",
|
|
42
|
+
"Transport",
|
|
43
|
+
"TransportError",
|
|
44
|
+
"UrllibTransport",
|
|
45
|
+
"__version__",
|
|
46
|
+
"verify_signature",
|
|
47
|
+
]
|
finclient/_encode.py
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"""Encoding of paths, query strings and request bodies."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import json
|
|
5
|
+
import re
|
|
6
|
+
from datetime import date, datetime
|
|
7
|
+
from typing import Any, Iterable, List, Mapping, Optional, Sequence, Tuple, Union
|
|
8
|
+
from urllib.parse import quote
|
|
9
|
+
|
|
10
|
+
__all__ = ["drop_none", "encode_query", "seg", "snake"]
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def snake(name: str) -> str:
|
|
14
|
+
"""``pageNo`` -> ``page_no``, ``MaxPerKey`` -> ``max_per_key``."""
|
|
15
|
+
text = re.sub(r"([A-Z]+)([A-Z][a-z])", r"\1_\2", name)
|
|
16
|
+
text = re.sub(r"([a-z0-9])([A-Z])", r"\1_\2", text)
|
|
17
|
+
return text.lower()
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def seg(value: Any) -> str:
|
|
21
|
+
"""One URL path segment, percent-encoded."""
|
|
22
|
+
text = str(value)
|
|
23
|
+
if not text.strip():
|
|
24
|
+
raise ValueError("A path parameter must not be empty.")
|
|
25
|
+
return quote(text, safe="")
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _scalar(value: Any) -> Any:
|
|
29
|
+
if isinstance(value, (datetime, date)):
|
|
30
|
+
return value.isoformat()
|
|
31
|
+
return value
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def drop_none(value: Any) -> Any:
|
|
35
|
+
"""The value with every ``None`` removed, nested ones too, as FinCopy reads a missing field and a null one alike."""
|
|
36
|
+
if isinstance(value, Mapping):
|
|
37
|
+
return {key: drop_none(item) for key, item in value.items() if item is not None}
|
|
38
|
+
if isinstance(value, (list, tuple)):
|
|
39
|
+
return [drop_none(item) for item in value]
|
|
40
|
+
return _scalar(value)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _query_value(value: Any) -> str:
|
|
44
|
+
if isinstance(value, bool):
|
|
45
|
+
return "true" if value else "false"
|
|
46
|
+
return str(_scalar(value))
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def encode_query(
|
|
50
|
+
query: Optional[Iterable[Tuple[str, Any]]] = None,
|
|
51
|
+
extra: Optional[Iterable[Tuple[str, Any]]] = None,
|
|
52
|
+
) -> str:
|
|
53
|
+
"""The query string (without ``?``); values that are None are left out and a list repeats its name."""
|
|
54
|
+
pairs: List[Tuple[str, str]] = []
|
|
55
|
+
for name, value in list(query or []) + list(extra or []):
|
|
56
|
+
if value is None:
|
|
57
|
+
continue
|
|
58
|
+
if isinstance(value, (list, tuple)):
|
|
59
|
+
pairs.extend((name, _query_value(item)) for item in value if item is not None)
|
|
60
|
+
else:
|
|
61
|
+
pairs.append((name, _query_value(value)))
|
|
62
|
+
return "&".join(f"{quote(name, safe='')}={quote(value, safe='')}" for name, value in pairs)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _json_default(value: Any) -> Any:
|
|
66
|
+
if isinstance(value, (datetime, date)):
|
|
67
|
+
return value.isoformat()
|
|
68
|
+
raise TypeError(f"{type(value).__name__} is not JSON serializable.")
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def encode_body(body: Union[Mapping[str, Any], Sequence[Any]]) -> bytes:
|
|
72
|
+
return json.dumps(drop_none(body), separators=(",", ":"), default=_json_default).encode("utf-8")
|
finclient/_errors.py
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"""The exceptions FinClient raises. Every one derives from :class:`FinApiError`."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
from typing import Any, Optional, Sequence, Union
|
|
5
|
+
|
|
6
|
+
__all__ = [
|
|
7
|
+
"FinApiError",
|
|
8
|
+
"ApiConnectionError",
|
|
9
|
+
"ApiResponseError",
|
|
10
|
+
"AuthenticationError",
|
|
11
|
+
"InsufficientCreditsError",
|
|
12
|
+
"MissingApiKeyError",
|
|
13
|
+
"NotFoundError",
|
|
14
|
+
"PermissionDeniedError",
|
|
15
|
+
"RateLimitError",
|
|
16
|
+
"ServerError",
|
|
17
|
+
"error_for_status",
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class FinApiError(Exception):
|
|
22
|
+
"""An unsuccessful API call.
|
|
23
|
+
|
|
24
|
+
Attributes:
|
|
25
|
+
status_code: The HTTP status, or 0 when no response arrived (timeout, network failure or a missing key).
|
|
26
|
+
code: The API's own error code (``invalid_api_key``, ``insufficient_credits``, ``package_not_allowed`` ...)
|
|
27
|
+
or, for FinCopy, its numeric response code. ``None`` when the body gave none.
|
|
28
|
+
message: A human-readable explanation.
|
|
29
|
+
errors: Further messages the API listed.
|
|
30
|
+
error_code: A short reason set by the SDK: ``timeout``, ``network``, ``rate_limited``, ``invalid_response``,
|
|
31
|
+
``empty_response`` or ``missing_api_key``; ``None`` for errors the API itself reported.
|
|
32
|
+
retry_after: Seconds the API asked the caller to wait (``Retry-After``), when it said.
|
|
33
|
+
lane: On limit refusals, the setting that governs the limit that was hit.
|
|
34
|
+
limit: On limit refusals, the value that was hit.
|
|
35
|
+
catag: On per-category limits, the category tag.
|
|
36
|
+
tier: On per-category limits, the caller's package tier.
|
|
37
|
+
"""
|
|
38
|
+
|
|
39
|
+
def __init__(
|
|
40
|
+
self,
|
|
41
|
+
message: str,
|
|
42
|
+
*,
|
|
43
|
+
status_code: int = 0,
|
|
44
|
+
code: Union[str, int, None] = None,
|
|
45
|
+
errors: Sequence[str] = (),
|
|
46
|
+
error_code: Optional[str] = None,
|
|
47
|
+
retry_after: Optional[float] = None,
|
|
48
|
+
lane: Optional[str] = None,
|
|
49
|
+
limit: Any = None,
|
|
50
|
+
catag: Optional[str] = None,
|
|
51
|
+
tier: Optional[str] = None,
|
|
52
|
+
) -> None:
|
|
53
|
+
super().__init__(message or "The request failed.")
|
|
54
|
+
self.message = message or "The request failed."
|
|
55
|
+
self.status_code = status_code
|
|
56
|
+
self.code = code
|
|
57
|
+
self.errors = tuple(errors)
|
|
58
|
+
self.error_code = error_code
|
|
59
|
+
self.retry_after = retry_after
|
|
60
|
+
self.lane = lane
|
|
61
|
+
self.limit = limit
|
|
62
|
+
self.catag = catag
|
|
63
|
+
self.tier = tier
|
|
64
|
+
|
|
65
|
+
def __repr__(self) -> str:
|
|
66
|
+
return f"{type(self).__name__}(status_code={self.status_code!r}, code={self.code!r}, message={self.message!r})"
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
class ApiConnectionError(FinApiError):
|
|
70
|
+
"""No answer arrived: the request timed out or the network failed. ``error_code`` is ``timeout`` or ``network``."""
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
class ApiResponseError(FinApiError):
|
|
74
|
+
"""The API answered, but not with a usable body (``invalid_response`` or ``empty_response``)."""
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
class AuthenticationError(FinApiError):
|
|
78
|
+
"""HTTP 401: the key is missing, unknown or disabled."""
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
class MissingApiKeyError(AuthenticationError):
|
|
82
|
+
"""A part of the client was used without an API key. Raised before any request is sent."""
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
class InsufficientCreditsError(FinApiError):
|
|
86
|
+
"""HTTP 402: not enough credits, or a credit budget or call limit was reached."""
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
class PermissionDeniedError(FinApiError):
|
|
90
|
+
"""HTTP 403: the key's package may not call this operation, or the operation is in preview."""
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
class NotFoundError(FinApiError):
|
|
94
|
+
"""HTTP 404."""
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
class RateLimitError(FinApiError):
|
|
98
|
+
"""HTTP 429: a rate or call limit was reached. ``retry_after`` says how long to wait, when the API said."""
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
class ServerError(FinApiError):
|
|
102
|
+
"""HTTP 5xx."""
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def error_for_status(status: int, message: str, **details: Any) -> FinApiError:
|
|
106
|
+
"""The exception class that matches an HTTP status."""
|
|
107
|
+
if status == 401:
|
|
108
|
+
cls: type = AuthenticationError
|
|
109
|
+
elif status == 402:
|
|
110
|
+
cls = InsufficientCreditsError
|
|
111
|
+
elif status == 403:
|
|
112
|
+
cls = PermissionDeniedError
|
|
113
|
+
elif status == 404:
|
|
114
|
+
cls = NotFoundError
|
|
115
|
+
elif status == 429:
|
|
116
|
+
cls = RateLimitError
|
|
117
|
+
details.setdefault("error_code", "rate_limited")
|
|
118
|
+
elif status >= 500:
|
|
119
|
+
cls = ServerError
|
|
120
|
+
else:
|
|
121
|
+
cls = FinApiError
|
|
122
|
+
error: FinApiError = cls(message, status_code=status, **details)
|
|
123
|
+
return error
|
|
124
|
+
|
|
125
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Types and operations generated from the OpenAPI snapshots in spec/. Do not edit by hand."""
|