btgsolutions-dataservices-python-client 3.2.1__tar.gz → 3.2.3__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-3.2.1/btgsolutions_dataservices_python_client.egg-info → btgsolutions_dataservices_python_client-3.2.3}/PKG-INFO +2 -2
- {btgsolutions_dataservices_python_client-3.2.1 → btgsolutions_dataservices_python_client-3.2.3}/README.md +1 -1
- {btgsolutions_dataservices_python_client-3.2.1 → btgsolutions_dataservices_python_client-3.2.3}/btgsolutions_dataservices/__init__.py +2 -0
- {btgsolutions_dataservices_python_client-3.2.1 → btgsolutions_dataservices_python_client-3.2.3}/btgsolutions_dataservices/rest/authenticator.py +13 -5
- {btgsolutions_dataservices_python_client-3.2.1 → btgsolutions_dataservices_python_client-3.2.3}/btgsolutions_dataservices/rest/intraday_candles.py +8 -3
- {btgsolutions_dataservices_python_client-3.2.1 → btgsolutions_dataservices_python_client-3.2.3}/btgsolutions_dataservices/rest/ticker_last_event_polling.py +16 -7
- {btgsolutions_dataservices_python_client-3.2.1 → btgsolutions_dataservices_python_client-3.2.3/btgsolutions_dataservices_python_client.egg-info}/PKG-INFO +2 -2
- {btgsolutions_dataservices_python_client-3.2.1 → btgsolutions_dataservices_python_client-3.2.3}/setup.py +3 -1
- {btgsolutions_dataservices_python_client-3.2.1 → btgsolutions_dataservices_python_client-3.2.3}/LICENSE +0 -0
- {btgsolutions_dataservices_python_client-3.2.1 → btgsolutions_dataservices_python_client-3.2.3}/MANIFEST.in +0 -0
- {btgsolutions_dataservices_python_client-3.2.1 → btgsolutions_dataservices_python_client-3.2.3}/btgsolutions_dataservices/config.py +0 -0
- {btgsolutions_dataservices_python_client-3.2.1 → btgsolutions_dataservices_python_client-3.2.3}/btgsolutions_dataservices/exceptions.py +0 -0
- {btgsolutions_dataservices_python_client-3.2.1 → btgsolutions_dataservices_python_client-3.2.3}/btgsolutions_dataservices/rest/__init__.py +0 -0
- {btgsolutions_dataservices_python_client-3.2.1 → btgsolutions_dataservices_python_client-3.2.3}/btgsolutions_dataservices/rest/bulk_data.py +0 -0
- {btgsolutions_dataservices_python_client-3.2.1 → btgsolutions_dataservices_python_client-3.2.3}/btgsolutions_dataservices/rest/company_data.py +0 -0
- {btgsolutions_dataservices_python_client-3.2.1 → btgsolutions_dataservices_python_client-3.2.3}/btgsolutions_dataservices/rest/corporate_events.py +0 -0
- {btgsolutions_dataservices_python_client-3.2.1 → btgsolutions_dataservices_python_client-3.2.3}/btgsolutions_dataservices/rest/hfn.py +0 -0
- {btgsolutions_dataservices_python_client-3.2.1 → btgsolutions_dataservices_python_client-3.2.3}/btgsolutions_dataservices/rest/historical_candles.py +0 -0
- {btgsolutions_dataservices_python_client-3.2.1 → btgsolutions_dataservices_python_client-3.2.3}/btgsolutions_dataservices/rest/intraday_tick_data.py +0 -0
- {btgsolutions_dataservices_python_client-3.2.1 → btgsolutions_dataservices_python_client-3.2.3}/btgsolutions_dataservices/rest/public_sources.py +0 -0
- {btgsolutions_dataservices_python_client-3.2.1 → btgsolutions_dataservices_python_client-3.2.3}/btgsolutions_dataservices/rest/quotes.py +0 -0
- {btgsolutions_dataservices_python_client-3.2.1 → btgsolutions_dataservices_python_client-3.2.3}/btgsolutions_dataservices/rest/reference_data.py +0 -0
- {btgsolutions_dataservices_python_client-3.2.1 → btgsolutions_dataservices_python_client-3.2.3}/btgsolutions_dataservices/rest/stock_loan.py +0 -0
- {btgsolutions_dataservices_python_client-3.2.1 → btgsolutions_dataservices_python_client-3.2.3}/btgsolutions_dataservices/rest/ticker_last_event.py +0 -0
- {btgsolutions_dataservices_python_client-3.2.1 → btgsolutions_dataservices_python_client-3.2.3}/btgsolutions_dataservices/websocket/__init__.py +0 -0
- {btgsolutions_dataservices_python_client-3.2.1 → btgsolutions_dataservices_python_client-3.2.3}/btgsolutions_dataservices/websocket/hfn_websocket_client.py +0 -0
- {btgsolutions_dataservices_python_client-3.2.1 → btgsolutions_dataservices_python_client-3.2.3}/btgsolutions_dataservices/websocket/market_data_feed.py +0 -0
- {btgsolutions_dataservices_python_client-3.2.1 → btgsolutions_dataservices_python_client-3.2.3}/btgsolutions_dataservices/websocket/market_data_websocket_client.py +0 -0
- {btgsolutions_dataservices_python_client-3.2.1 → btgsolutions_dataservices_python_client-3.2.3}/btgsolutions_dataservices/websocket/websocket_default_functions.py +0 -0
- {btgsolutions_dataservices_python_client-3.2.1 → btgsolutions_dataservices_python_client-3.2.3}/btgsolutions_dataservices_python_client.egg-info/SOURCES.txt +0 -0
- {btgsolutions_dataservices_python_client-3.2.1 → btgsolutions_dataservices_python_client-3.2.3}/btgsolutions_dataservices_python_client.egg-info/dependency_links.txt +0 -0
- {btgsolutions_dataservices_python_client-3.2.1 → btgsolutions_dataservices_python_client-3.2.3}/btgsolutions_dataservices_python_client.egg-info/requires.txt +0 -0
- {btgsolutions_dataservices_python_client-3.2.1 → btgsolutions_dataservices_python_client-3.2.3}/btgsolutions_dataservices_python_client.egg-info/top_level.txt +0 -0
- {btgsolutions_dataservices_python_client-3.2.1 → btgsolutions_dataservices_python_client-3.2.3}/pyproject.toml +0 -0
- {btgsolutions_dataservices_python_client-3.2.1 → btgsolutions_dataservices_python_client-3.2.3}/requirements.txt +0 -0
- {btgsolutions_dataservices_python_client-3.2.1 → btgsolutions_dataservices_python_client-3.2.3}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: btgsolutions_dataservices_python_client
|
|
3
|
-
Version: 3.2.
|
|
3
|
+
Version: 3.2.3
|
|
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
|
|
@@ -184,7 +184,7 @@ ws.run(on_message=lambda message: print(message))
|
|
|
184
184
|
```python
|
|
185
185
|
import btgsolutions_dataservices as btg
|
|
186
186
|
int_candles = btg.IntradayCandles(api_key='YOUR_API_KEY')
|
|
187
|
-
int_candles.get_intraday_candles(market_type='stocks', tickers=['PETR4', 'VALE3'], candle_period='1m', delay='delayed', mode='relative', timezone='UTC', raw_data=True)
|
|
187
|
+
int_candles.get_intraday_candles(market_type='stocks', tickers=['PETR4', 'VALE3'], candle_period='1m', delay='delayed', mode='relative', timezone='UTC', market_status='regular', raw_data=True)
|
|
188
188
|
```
|
|
189
189
|
|
|
190
190
|
#### Intraday Tick Data
|
|
@@ -161,7 +161,7 @@ ws.run(on_message=lambda message: print(message))
|
|
|
161
161
|
```python
|
|
162
162
|
import btgsolutions_dataservices as btg
|
|
163
163
|
int_candles = btg.IntradayCandles(api_key='YOUR_API_KEY')
|
|
164
|
-
int_candles.get_intraday_candles(market_type='stocks', tickers=['PETR4', 'VALE3'], candle_period='1m', delay='delayed', mode='relative', timezone='UTC', raw_data=True)
|
|
164
|
+
int_candles.get_intraday_candles(market_type='stocks', tickers=['PETR4', 'VALE3'], candle_period='1m', delay='delayed', mode='relative', timezone='UTC', market_status='regular', raw_data=True)
|
|
165
165
|
```
|
|
166
166
|
|
|
167
167
|
#### Intraday Tick Data
|
|
@@ -1,14 +1,19 @@
|
|
|
1
|
+
import uuid
|
|
1
2
|
import requests
|
|
2
3
|
import json
|
|
3
4
|
import jwt
|
|
4
5
|
import time
|
|
5
6
|
from ..config import url_apis
|
|
6
7
|
from ..exceptions import BadResponse
|
|
8
|
+
from .. import __version__
|
|
7
9
|
|
|
8
10
|
class Authenticator:
|
|
9
11
|
def __init__(self, api_key) -> None:
|
|
10
12
|
self.api_key = api_key
|
|
13
|
+
|
|
14
|
+
self._id = uuid.uuid4().hex[:8]
|
|
11
15
|
self._token = self.get_new_token()
|
|
16
|
+
self._expiration = self._get_expiration()
|
|
12
17
|
|
|
13
18
|
def get_new_token(self):
|
|
14
19
|
url = f"{url_apis}/authenticate"
|
|
@@ -17,7 +22,7 @@ class Authenticator:
|
|
|
17
22
|
}
|
|
18
23
|
payload = json.dumps({
|
|
19
24
|
"api_key": self.api_key,
|
|
20
|
-
"client_id": f"btgsolutions-client-python"
|
|
25
|
+
"client_id": f"btgsolutions-client-python/{__version__}/{self._id}"
|
|
21
26
|
})
|
|
22
27
|
response = requests.request("POST", url, data=payload, headers=headersList)
|
|
23
28
|
if response.status_code == 200:
|
|
@@ -30,13 +35,16 @@ class Authenticator:
|
|
|
30
35
|
|
|
31
36
|
return token
|
|
32
37
|
|
|
33
|
-
|
|
34
|
-
def token(self):
|
|
38
|
+
def _get_expiration(self):
|
|
35
39
|
token_decoded = jwt.decode(self._token, options={"verify_signature": False})
|
|
36
40
|
exp = token_decoded.get("exp")
|
|
37
|
-
|
|
38
|
-
|
|
41
|
+
return exp
|
|
42
|
+
|
|
43
|
+
@property
|
|
44
|
+
def token(self):
|
|
45
|
+
if int(time.time()) - 5 >= self._expiration: ## Subtracting 5 seconds to avoid edge cases of token expiration during request processing.
|
|
39
46
|
self._token = self.get_new_token()
|
|
47
|
+
self._expiration = self._get_expiration()
|
|
40
48
|
|
|
41
49
|
return self._token
|
|
42
50
|
|
|
@@ -60,6 +60,7 @@ class IntradayCandles:
|
|
|
60
60
|
mode:str='absolute',
|
|
61
61
|
raw_data:bool=False,
|
|
62
62
|
cross_filter:str='',
|
|
63
|
+
market_status:str='',
|
|
63
64
|
):
|
|
64
65
|
"""
|
|
65
66
|
This method provides realtime intraday candles for a given ticker.
|
|
@@ -95,9 +96,13 @@ class IntradayCandles:
|
|
|
95
96
|
Example: 'absolute', 'relative' or 'spark'.
|
|
96
97
|
Default: absolute.
|
|
97
98
|
cross_filter: str
|
|
98
|
-
Filter trades by cross status.
|
|
99
|
+
Filter trades by cross status.
|
|
99
100
|
Options: 'all', 'only_cross' or 'without_cross'.
|
|
100
101
|
Default: 'all'.
|
|
102
|
+
market_status: str
|
|
103
|
+
Filter trades by market status. Not available for 'Indices'.
|
|
104
|
+
Options: 'all' or 'regular'.
|
|
105
|
+
Default: 'all'.
|
|
101
106
|
raw_data: bool
|
|
102
107
|
If false, returns data in a dict of dataframes. If true, returns raw data.
|
|
103
108
|
Default: False.
|
|
@@ -107,8 +112,6 @@ class IntradayCandles:
|
|
|
107
112
|
|
|
108
113
|
if delay not in ['delayed', 'realtime']: raise DelayError(f"Must provide a valid 'delay' parameter. Input: '{delay}'. Accepted values: 'delayed' or 'realtime'.")
|
|
109
114
|
|
|
110
|
-
if cross_filter and market_type != 'derivatives': raise DelayError(f"The 'cross_filter' flag is only valid for market_type 'derivatives'.")
|
|
111
|
-
|
|
112
115
|
tickers = ','.join(tickers) if type(tickers) is list else tickers
|
|
113
116
|
|
|
114
117
|
url = f"{base_url}/api/v1/marketdata/br/b3/{delay}/intraday-candles/{market_type}?tickers={tickers}&candle_period={candle_period}&mode={mode}&timezone={timezone}"
|
|
@@ -119,6 +122,8 @@ class IntradayCandles:
|
|
|
119
122
|
|
|
120
123
|
if cross_filter: url += f'&cross_filter={cross_filter}'
|
|
121
124
|
|
|
125
|
+
if market_status: url += f'&market_status={market_status}'
|
|
126
|
+
|
|
122
127
|
response = requests.request("GET", url, headers=self.headers)
|
|
123
128
|
if response.status_code == 200:
|
|
124
129
|
response_data = json.loads(response.text)
|
|
@@ -53,6 +53,7 @@ class TickerLastEventPolling:
|
|
|
53
53
|
|
|
54
54
|
self._last_request_datetime = None
|
|
55
55
|
self._cache = {}
|
|
56
|
+
self._lock = threading.Lock()
|
|
56
57
|
|
|
57
58
|
self._available_data_types = {
|
|
58
59
|
"top-of-books": ['stocks', 'derivatives', 'options'],
|
|
@@ -106,21 +107,26 @@ class TickerLastEventPolling:
|
|
|
106
107
|
|
|
107
108
|
|
|
108
109
|
def _update_data(self):
|
|
109
|
-
|
|
110
|
+
|
|
111
|
+
with self._lock:
|
|
112
|
+
last_dt = self._last_request_datetime
|
|
113
|
+
|
|
114
|
+
url = self.url + (f"?dt={(last_dt - timedelta(seconds=60)).strftime('%Y-%m-%dT%H:%M:%S.000Z')}" if last_dt else "")
|
|
110
115
|
|
|
111
116
|
request_datetime = datetime.now(timezone.utc)
|
|
112
117
|
|
|
118
|
+
self.authenticator.token # force token refresh if needed
|
|
119
|
+
|
|
113
120
|
response = requests.request("GET", url, headers={"authorization": f"Bearer {self.authenticator.token}"})
|
|
114
121
|
|
|
115
122
|
if response.status_code != 200:
|
|
116
123
|
return
|
|
117
124
|
|
|
118
|
-
|
|
119
|
-
self._last_request_datetime = request_datetime
|
|
120
|
-
|
|
121
125
|
new_data = { tob["sb"]: tob for tob in response.json() if tob.get("sb")}
|
|
122
126
|
|
|
123
|
-
self.
|
|
127
|
+
with self._lock:
|
|
128
|
+
self._last_request_datetime = request_datetime
|
|
129
|
+
self._cache.update(new_data)
|
|
124
130
|
|
|
125
131
|
|
|
126
132
|
def get(self, force_update: bool=False, raw_data:bool=False):
|
|
@@ -139,11 +145,14 @@ class TickerLastEventPolling:
|
|
|
139
145
|
"""
|
|
140
146
|
if force_update:
|
|
141
147
|
self._update_data()
|
|
148
|
+
|
|
149
|
+
with self._lock:
|
|
150
|
+
data = list(self._cache.values())
|
|
142
151
|
|
|
143
152
|
if raw_data:
|
|
144
|
-
return
|
|
153
|
+
return data
|
|
145
154
|
else:
|
|
146
|
-
return pd.DataFrame(
|
|
155
|
+
return pd.DataFrame(data)
|
|
147
156
|
|
|
148
157
|
|
|
149
158
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: btgsolutions_dataservices_python_client
|
|
3
|
-
Version: 3.2.
|
|
3
|
+
Version: 3.2.3
|
|
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
|
|
@@ -184,7 +184,7 @@ ws.run(on_message=lambda message: print(message))
|
|
|
184
184
|
```python
|
|
185
185
|
import btgsolutions_dataservices as btg
|
|
186
186
|
int_candles = btg.IntradayCandles(api_key='YOUR_API_KEY')
|
|
187
|
-
int_candles.get_intraday_candles(market_type='stocks', tickers=['PETR4', 'VALE3'], candle_period='1m', delay='delayed', mode='relative', timezone='UTC', raw_data=True)
|
|
187
|
+
int_candles.get_intraday_candles(market_type='stocks', tickers=['PETR4', 'VALE3'], candle_period='1m', delay='delayed', mode='relative', timezone='UTC', market_status='regular', raw_data=True)
|
|
188
188
|
```
|
|
189
189
|
|
|
190
190
|
#### Intraday Tick Data
|
|
@@ -2,6 +2,8 @@ from setuptools import setup, find_packages
|
|
|
2
2
|
import os
|
|
3
3
|
from pathlib import Path
|
|
4
4
|
|
|
5
|
+
from btgsolutions_dataservices import __version__
|
|
6
|
+
|
|
5
7
|
this_directory = Path(__file__).parent
|
|
6
8
|
long_description = (this_directory / "README.md").read_text()
|
|
7
9
|
|
|
@@ -22,7 +24,7 @@ description = "Python package containing several classes and data for extracting
|
|
|
22
24
|
|
|
23
25
|
setup(
|
|
24
26
|
name='btgsolutions_dataservices_python_client',
|
|
25
|
-
version=
|
|
27
|
+
version=__version__,
|
|
26
28
|
description=description,
|
|
27
29
|
long_description=long_description,
|
|
28
30
|
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
|