btgsolutions-dataservices-python-client 2.16.0__tar.gz → 2.17.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.
- {btgsolutions_dataservices_python_client-2.16.0/btgsolutions_dataservices_python_client.egg-info → btgsolutions-dataservices-python-client-2.17.0}/PKG-INFO +14 -16
- {btgsolutions_dataservices_python_client-2.16.0 → btgsolutions-dataservices-python-client-2.17.0}/README.md +8 -1
- {btgsolutions_dataservices_python_client-2.16.0 → btgsolutions-dataservices-python-client-2.17.0}/btgsolutions_dataservices/rest/__init__.py +2 -1
- btgsolutions-dataservices-python-client-2.17.0/btgsolutions_dataservices/rest/ticker_last_event_polling.py +148 -0
- {btgsolutions_dataservices_python_client-2.16.0 → btgsolutions-dataservices-python-client-2.17.0/btgsolutions_dataservices_python_client.egg-info}/PKG-INFO +14 -16
- {btgsolutions_dataservices_python_client-2.16.0 → btgsolutions-dataservices-python-client-2.17.0}/btgsolutions_dataservices_python_client.egg-info/SOURCES.txt +1 -0
- {btgsolutions_dataservices_python_client-2.16.0 → btgsolutions-dataservices-python-client-2.17.0}/setup.py +1 -1
- {btgsolutions_dataservices_python_client-2.16.0 → btgsolutions-dataservices-python-client-2.17.0}/LICENSE +0 -0
- {btgsolutions_dataservices_python_client-2.16.0 → btgsolutions-dataservices-python-client-2.17.0}/MANIFEST.in +0 -0
- {btgsolutions_dataservices_python_client-2.16.0 → btgsolutions-dataservices-python-client-2.17.0}/btgsolutions_dataservices/__init__.py +0 -0
- {btgsolutions_dataservices_python_client-2.16.0 → btgsolutions-dataservices-python-client-2.17.0}/btgsolutions_dataservices/config.py +0 -0
- {btgsolutions_dataservices_python_client-2.16.0 → btgsolutions-dataservices-python-client-2.17.0}/btgsolutions_dataservices/exceptions.py +0 -0
- {btgsolutions_dataservices_python_client-2.16.0 → btgsolutions-dataservices-python-client-2.17.0}/btgsolutions_dataservices/rest/authenticator.py +0 -0
- {btgsolutions_dataservices_python_client-2.16.0 → btgsolutions-dataservices-python-client-2.17.0}/btgsolutions_dataservices/rest/bulk_data.py +0 -0
- {btgsolutions_dataservices_python_client-2.16.0 → btgsolutions-dataservices-python-client-2.17.0}/btgsolutions_dataservices/rest/company_data.py +0 -0
- {btgsolutions_dataservices_python_client-2.16.0 → btgsolutions-dataservices-python-client-2.17.0}/btgsolutions_dataservices/rest/corporate_events.py +0 -0
- {btgsolutions_dataservices_python_client-2.16.0 → btgsolutions-dataservices-python-client-2.17.0}/btgsolutions_dataservices/rest/hfn.py +0 -0
- {btgsolutions_dataservices_python_client-2.16.0 → btgsolutions-dataservices-python-client-2.17.0}/btgsolutions_dataservices/rest/historical_candles.py +0 -0
- {btgsolutions_dataservices_python_client-2.16.0 → btgsolutions-dataservices-python-client-2.17.0}/btgsolutions_dataservices/rest/intraday_candles.py +0 -0
- {btgsolutions_dataservices_python_client-2.16.0 → btgsolutions-dataservices-python-client-2.17.0}/btgsolutions_dataservices/rest/intraday_tick_data.py +0 -0
- {btgsolutions_dataservices_python_client-2.16.0 → btgsolutions-dataservices-python-client-2.17.0}/btgsolutions_dataservices/rest/public_sources.py +0 -0
- {btgsolutions_dataservices_python_client-2.16.0 → btgsolutions-dataservices-python-client-2.17.0}/btgsolutions_dataservices/rest/quotes.py +0 -0
- {btgsolutions_dataservices_python_client-2.16.0 → btgsolutions-dataservices-python-client-2.17.0}/btgsolutions_dataservices/rest/reference_data.py +0 -0
- {btgsolutions_dataservices_python_client-2.16.0 → btgsolutions-dataservices-python-client-2.17.0}/btgsolutions_dataservices/rest/stock_loan.py +0 -0
- {btgsolutions_dataservices_python_client-2.16.0 → btgsolutions-dataservices-python-client-2.17.0}/btgsolutions_dataservices/rest/ticker_last_event.py +0 -0
- {btgsolutions_dataservices_python_client-2.16.0 → btgsolutions-dataservices-python-client-2.17.0}/btgsolutions_dataservices/websocket/__init__.py +0 -0
- {btgsolutions_dataservices_python_client-2.16.0 → btgsolutions-dataservices-python-client-2.17.0}/btgsolutions_dataservices/websocket/hfn_websocket_client.py +0 -0
- {btgsolutions_dataservices_python_client-2.16.0 → btgsolutions-dataservices-python-client-2.17.0}/btgsolutions_dataservices/websocket/market_data_feed.py +0 -0
- {btgsolutions_dataservices_python_client-2.16.0 → btgsolutions-dataservices-python-client-2.17.0}/btgsolutions_dataservices/websocket/market_data_websocket_client.py +0 -0
- {btgsolutions_dataservices_python_client-2.16.0 → btgsolutions-dataservices-python-client-2.17.0}/btgsolutions_dataservices/websocket/websocket_default_functions.py +0 -0
- {btgsolutions_dataservices_python_client-2.16.0 → btgsolutions-dataservices-python-client-2.17.0}/btgsolutions_dataservices_python_client.egg-info/dependency_links.txt +0 -0
- {btgsolutions_dataservices_python_client-2.16.0 → btgsolutions-dataservices-python-client-2.17.0}/btgsolutions_dataservices_python_client.egg-info/requires.txt +3 -3
- {btgsolutions_dataservices_python_client-2.16.0 → btgsolutions-dataservices-python-client-2.17.0}/btgsolutions_dataservices_python_client.egg-info/top_level.txt +0 -0
- {btgsolutions_dataservices_python_client-2.16.0 → btgsolutions-dataservices-python-client-2.17.0}/pyproject.toml +0 -0
- {btgsolutions_dataservices_python_client-2.16.0 → btgsolutions-dataservices-python-client-2.17.0}/requirements.txt +0 -0
- {btgsolutions_dataservices_python_client-2.16.0 → btgsolutions-dataservices-python-client-2.17.0}/setup.cfg +0 -0
|
@@ -1,25 +1,14 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
2
|
Name: btgsolutions-dataservices-python-client
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.17.0
|
|
4
4
|
Summary: Python package containing several classes and data for extracting and manipulating market and trading data.
|
|
5
5
|
Home-page: https://github.com/BTG-Pactual-Solutions/btgsolutions-dataservices-python-client
|
|
6
6
|
Author: BTG Solutions Data Services powered by BTG Pactual Solutions
|
|
7
|
+
License: UNKNOWN
|
|
8
|
+
Platform: UNKNOWN
|
|
7
9
|
Requires-Python: >=3.9,<3.14
|
|
8
10
|
Description-Content-Type: text/markdown
|
|
9
11
|
License-File: LICENSE
|
|
10
|
-
Requires-Dist: pandas>=2.2.2
|
|
11
|
-
Requires-Dist: websocket-client>=1.8.0
|
|
12
|
-
Requires-Dist: PyJWT>=2.8.0
|
|
13
|
-
Requires-Dist: requests>=2.32.3
|
|
14
|
-
Requires-Dist: pyarrow>=17.0.0
|
|
15
|
-
Dynamic: author
|
|
16
|
-
Dynamic: description
|
|
17
|
-
Dynamic: description-content-type
|
|
18
|
-
Dynamic: home-page
|
|
19
|
-
Dynamic: license-file
|
|
20
|
-
Dynamic: requires-dist
|
|
21
|
-
Dynamic: requires-python
|
|
22
|
-
Dynamic: summary
|
|
23
12
|
|
|
24
13
|
# BTG Solutions - Data Services
|
|
25
14
|
|
|
@@ -244,7 +233,6 @@ import btgsolutions_dataservices as btg
|
|
|
244
233
|
last_event = btg.TickerLastEvent(api_key='YOUR_API_KEY')
|
|
245
234
|
last_event.get_tobs(data_type='stocks')
|
|
246
235
|
```
|
|
247
|
-
|
|
248
236
|
#### Ticker Last Trading Status
|
|
249
237
|
|
|
250
238
|
```python
|
|
@@ -252,6 +240,14 @@ import btgsolutions_dataservices as btg
|
|
|
252
240
|
last_event = btg.TickerLastEvent(api_key='YOUR_API_KEY')
|
|
253
241
|
last_event.get_status(tickers=['PETR4','VALE3'])
|
|
254
242
|
```
|
|
243
|
+
#### Ticker Last Top of Book Polling
|
|
244
|
+
|
|
245
|
+
```python
|
|
246
|
+
import btgsolutions_dataservices as btg
|
|
247
|
+
last_event = btg.TickerLastEventPolling(api_key='YOUR_API_KEY', data_type='top-of-books', data_subtype='stocks')
|
|
248
|
+
last_event.get()
|
|
249
|
+
```
|
|
250
|
+
|
|
255
251
|
|
|
256
252
|
### Historical Data
|
|
257
253
|
|
|
@@ -469,3 +465,5 @@ import btgsolutions_dataservices as btg
|
|
|
469
465
|
ref = btg.ReferenceData(api_key='YOUR_API_KEY')
|
|
470
466
|
ref.ticker_reference(tickers=['VALE3','PETR4'])
|
|
471
467
|
```
|
|
468
|
+
|
|
469
|
+
|
|
@@ -221,7 +221,6 @@ import btgsolutions_dataservices as btg
|
|
|
221
221
|
last_event = btg.TickerLastEvent(api_key='YOUR_API_KEY')
|
|
222
222
|
last_event.get_tobs(data_type='stocks')
|
|
223
223
|
```
|
|
224
|
-
|
|
225
224
|
#### Ticker Last Trading Status
|
|
226
225
|
|
|
227
226
|
```python
|
|
@@ -229,6 +228,14 @@ import btgsolutions_dataservices as btg
|
|
|
229
228
|
last_event = btg.TickerLastEvent(api_key='YOUR_API_KEY')
|
|
230
229
|
last_event.get_status(tickers=['PETR4','VALE3'])
|
|
231
230
|
```
|
|
231
|
+
#### Ticker Last Top of Book Polling
|
|
232
|
+
|
|
233
|
+
```python
|
|
234
|
+
import btgsolutions_dataservices as btg
|
|
235
|
+
last_event = btg.TickerLastEventPolling(api_key='YOUR_API_KEY', data_type='top-of-books', data_subtype='stocks')
|
|
236
|
+
last_event.get()
|
|
237
|
+
```
|
|
238
|
+
|
|
232
239
|
|
|
233
240
|
### Historical Data
|
|
234
241
|
|
|
@@ -10,4 +10,5 @@ from .corporate_events import CorporateEvents
|
|
|
10
10
|
from .company_data import CompanyData
|
|
11
11
|
from .public_sources import PublicSources
|
|
12
12
|
from .reference_data import ReferenceData
|
|
13
|
-
from .stock_loan import StockLoan
|
|
13
|
+
from .stock_loan import StockLoan
|
|
14
|
+
from .ticker_last_event_polling import TickerLastEventPolling
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import time
|
|
2
|
+
from typing import Optional, List
|
|
3
|
+
from ..exceptions import BadResponse
|
|
4
|
+
import requests
|
|
5
|
+
from ..config import url_api_v1
|
|
6
|
+
from .authenticator import Authenticator
|
|
7
|
+
import pandas as pd
|
|
8
|
+
import json
|
|
9
|
+
from datetime import datetime, timezone
|
|
10
|
+
import threading
|
|
11
|
+
|
|
12
|
+
class TickerLastEventPolling:
|
|
13
|
+
"""
|
|
14
|
+
This class continuously polls and caches the latest ticker market data in the background for quick and up-to-date access.
|
|
15
|
+
|
|
16
|
+
* Main use case:
|
|
17
|
+
|
|
18
|
+
>>> from btgsolutions_dataservices import TickerLastEventPolling
|
|
19
|
+
>>> last_event = TickerLastEventPolling(
|
|
20
|
+
>>> api_key='YOUR_API_KEY',
|
|
21
|
+
>>> data_type='top-of-books',
|
|
22
|
+
>>> data_subtype='stocks',
|
|
23
|
+
>>> )
|
|
24
|
+
|
|
25
|
+
>>> last_event.get(
|
|
26
|
+
>>> raw_data=False
|
|
27
|
+
>>> )
|
|
28
|
+
|
|
29
|
+
Parameters
|
|
30
|
+
----------------
|
|
31
|
+
api_key: str
|
|
32
|
+
User identification key.
|
|
33
|
+
Field is required.
|
|
34
|
+
data_type: str
|
|
35
|
+
Market Data type.
|
|
36
|
+
Options: 'top-of-books'
|
|
37
|
+
Field is required.
|
|
38
|
+
data_subtype: str
|
|
39
|
+
Market Data subtype.
|
|
40
|
+
Options: 'stocks', 'options', 'derivatives'.
|
|
41
|
+
Field is required.
|
|
42
|
+
"""
|
|
43
|
+
def __init__(
|
|
44
|
+
self,
|
|
45
|
+
api_key:Optional[str],
|
|
46
|
+
data_type: str,
|
|
47
|
+
data_subtype: str,
|
|
48
|
+
interval_seconds: float = 1.0
|
|
49
|
+
):
|
|
50
|
+
self.api_key = api_key
|
|
51
|
+
self.authenticator = Authenticator(self.api_key)
|
|
52
|
+
self.interval_seconds = interval_seconds
|
|
53
|
+
self.data_type = data_type
|
|
54
|
+
|
|
55
|
+
self._last_request_datetime = None
|
|
56
|
+
self._cache = {}
|
|
57
|
+
|
|
58
|
+
self._available_data_types = {
|
|
59
|
+
"top-of-books": ['stocks', 'derivatives', 'options']
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
self._available_url = {
|
|
63
|
+
"top-of-books": {
|
|
64
|
+
"data": f"{url_api_v1}/marketdata/last-event/books/top/{data_subtype}/batch",
|
|
65
|
+
"available": f"{url_api_v1}/marketdata/last-event/books/{data_subtype}/availables"
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if data_type not in self._available_data_types:
|
|
70
|
+
raise Exception(f"Must provide a valid data_type. Valid data types are: {self._available_data_types}")
|
|
71
|
+
|
|
72
|
+
if data_subtype not in self._available_data_types[data_type]:
|
|
73
|
+
raise Exception(f"Must provide a valid data_subtype. Valid data subtypes are: {self._available_data_types[data_type]}")
|
|
74
|
+
|
|
75
|
+
self.url = self._available_url[self.data_type]["data"]
|
|
76
|
+
|
|
77
|
+
self._update_data()
|
|
78
|
+
|
|
79
|
+
threading.Thread(target=self._polling_loop, daemon=True).start()
|
|
80
|
+
|
|
81
|
+
def _polling_loop(self):
|
|
82
|
+
|
|
83
|
+
while True:
|
|
84
|
+
try:
|
|
85
|
+
self._update_data()
|
|
86
|
+
except Exception as e:
|
|
87
|
+
print("error on updating data:", e)
|
|
88
|
+
continue
|
|
89
|
+
|
|
90
|
+
time.sleep(self.interval_seconds)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def _update_data(self):
|
|
94
|
+
url = self.url + (f"?dt={self._last_request_datetime.strftime('%Y-%m-%dT%H:%M:%S.000Z')}" if self._last_request_datetime else "")
|
|
95
|
+
|
|
96
|
+
request_datetime = datetime.now(timezone.utc)
|
|
97
|
+
|
|
98
|
+
response = requests.request("GET", url, headers={"authorization": f"Bearer {self.authenticator.token}"})
|
|
99
|
+
|
|
100
|
+
if response.status_code != 200:
|
|
101
|
+
return
|
|
102
|
+
|
|
103
|
+
self._last_request_datetime = request_datetime
|
|
104
|
+
|
|
105
|
+
new_data = { tob["sb"]: tob for tob in response.json() if tob.get("sb")}
|
|
106
|
+
|
|
107
|
+
self._cache.update(new_data)
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def get(self, force_update: bool=False, raw_data:bool=False):
|
|
111
|
+
|
|
112
|
+
"""
|
|
113
|
+
This method provides the last events for all tickers of the given data type and data subtype.
|
|
114
|
+
|
|
115
|
+
Parameters
|
|
116
|
+
----------------
|
|
117
|
+
force_update: bool
|
|
118
|
+
If true, forces an update before returning the data. If false, returns the data.
|
|
119
|
+
Field is not required. Default: False.
|
|
120
|
+
raw_data: bool
|
|
121
|
+
If false, returns data in a dataframe. If true, returns raw data.
|
|
122
|
+
Field is not required. Default: False.
|
|
123
|
+
"""
|
|
124
|
+
if force_update:
|
|
125
|
+
self._update_data()
|
|
126
|
+
|
|
127
|
+
if raw_data:
|
|
128
|
+
return list(self._cache.values())
|
|
129
|
+
else:
|
|
130
|
+
return pd.DataFrame(self._cache.values())
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def get_available_tickers(self):
|
|
135
|
+
|
|
136
|
+
"""
|
|
137
|
+
This method provides all the available tickers for the specific data type and data subtype.
|
|
138
|
+
|
|
139
|
+
"""
|
|
140
|
+
|
|
141
|
+
url = self._available_url[self.data_type]["available"]
|
|
142
|
+
|
|
143
|
+
response = requests.request("GET", url, headers={"authorization": f"Bearer {self.authenticator.token}"})
|
|
144
|
+
if response.status_code == 200:
|
|
145
|
+
return response.json()
|
|
146
|
+
else:
|
|
147
|
+
response = json.loads(response.text)
|
|
148
|
+
raise BadResponse(f'Error: {response.get("error", "")}')
|
|
@@ -1,25 +1,14 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
2
|
Name: btgsolutions-dataservices-python-client
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.17.0
|
|
4
4
|
Summary: Python package containing several classes and data for extracting and manipulating market and trading data.
|
|
5
5
|
Home-page: https://github.com/BTG-Pactual-Solutions/btgsolutions-dataservices-python-client
|
|
6
6
|
Author: BTG Solutions Data Services powered by BTG Pactual Solutions
|
|
7
|
+
License: UNKNOWN
|
|
8
|
+
Platform: UNKNOWN
|
|
7
9
|
Requires-Python: >=3.9,<3.14
|
|
8
10
|
Description-Content-Type: text/markdown
|
|
9
11
|
License-File: LICENSE
|
|
10
|
-
Requires-Dist: pandas>=2.2.2
|
|
11
|
-
Requires-Dist: websocket-client>=1.8.0
|
|
12
|
-
Requires-Dist: PyJWT>=2.8.0
|
|
13
|
-
Requires-Dist: requests>=2.32.3
|
|
14
|
-
Requires-Dist: pyarrow>=17.0.0
|
|
15
|
-
Dynamic: author
|
|
16
|
-
Dynamic: description
|
|
17
|
-
Dynamic: description-content-type
|
|
18
|
-
Dynamic: home-page
|
|
19
|
-
Dynamic: license-file
|
|
20
|
-
Dynamic: requires-dist
|
|
21
|
-
Dynamic: requires-python
|
|
22
|
-
Dynamic: summary
|
|
23
12
|
|
|
24
13
|
# BTG Solutions - Data Services
|
|
25
14
|
|
|
@@ -244,7 +233,6 @@ import btgsolutions_dataservices as btg
|
|
|
244
233
|
last_event = btg.TickerLastEvent(api_key='YOUR_API_KEY')
|
|
245
234
|
last_event.get_tobs(data_type='stocks')
|
|
246
235
|
```
|
|
247
|
-
|
|
248
236
|
#### Ticker Last Trading Status
|
|
249
237
|
|
|
250
238
|
```python
|
|
@@ -252,6 +240,14 @@ import btgsolutions_dataservices as btg
|
|
|
252
240
|
last_event = btg.TickerLastEvent(api_key='YOUR_API_KEY')
|
|
253
241
|
last_event.get_status(tickers=['PETR4','VALE3'])
|
|
254
242
|
```
|
|
243
|
+
#### Ticker Last Top of Book Polling
|
|
244
|
+
|
|
245
|
+
```python
|
|
246
|
+
import btgsolutions_dataservices as btg
|
|
247
|
+
last_event = btg.TickerLastEventPolling(api_key='YOUR_API_KEY', data_type='top-of-books', data_subtype='stocks')
|
|
248
|
+
last_event.get()
|
|
249
|
+
```
|
|
250
|
+
|
|
255
251
|
|
|
256
252
|
### Historical Data
|
|
257
253
|
|
|
@@ -469,3 +465,5 @@ import btgsolutions_dataservices as btg
|
|
|
469
465
|
ref = btg.ReferenceData(api_key='YOUR_API_KEY')
|
|
470
466
|
ref.ticker_reference(tickers=['VALE3','PETR4'])
|
|
471
467
|
```
|
|
468
|
+
|
|
469
|
+
|
|
@@ -21,6 +21,7 @@ btgsolutions_dataservices/rest/quotes.py
|
|
|
21
21
|
btgsolutions_dataservices/rest/reference_data.py
|
|
22
22
|
btgsolutions_dataservices/rest/stock_loan.py
|
|
23
23
|
btgsolutions_dataservices/rest/ticker_last_event.py
|
|
24
|
+
btgsolutions_dataservices/rest/ticker_last_event_polling.py
|
|
24
25
|
btgsolutions_dataservices/websocket/__init__.py
|
|
25
26
|
btgsolutions_dataservices/websocket/hfn_websocket_client.py
|
|
26
27
|
btgsolutions_dataservices/websocket/market_data_feed.py
|
|
@@ -22,7 +22,7 @@ description = "Python package containing several classes and data for extracting
|
|
|
22
22
|
|
|
23
23
|
setup(
|
|
24
24
|
name='btgsolutions-dataservices-python-client',
|
|
25
|
-
version='2.
|
|
25
|
+
version='2.17.0',
|
|
26
26
|
description=description,
|
|
27
27
|
long_description=long_description,
|
|
28
28
|
long_description_content_type='text/markdown',
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|