btgsolutions-dataservices-python-client 3.2.6__tar.gz → 3.2.8__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.6 → btgsolutions_dataservices_python_client-3.2.8}/PKG-INFO +43 -4
- {btgsolutions_dataservices_python_client-3.2.6 → btgsolutions_dataservices_python_client-3.2.8}/README.md +36 -2
- {btgsolutions_dataservices_python_client-3.2.6 → btgsolutions_dataservices_python_client-3.2.8}/btgsolutions_dataservices/__init__.py +1 -1
- {btgsolutions_dataservices_python_client-3.2.6 → btgsolutions_dataservices_python_client-3.2.8}/btgsolutions_dataservices/rest/__init__.py +1 -0
- btgsolutions_dataservices_python_client-3.2.8/btgsolutions_dataservices/rest/broker_reference.py +63 -0
- {btgsolutions_dataservices_python_client-3.2.6 → btgsolutions_dataservices_python_client-3.2.8}/btgsolutions_dataservices/rest/historical_candles.py +14 -4
- btgsolutions_dataservices_python_client-3.2.8/btgsolutions_dataservices/rest/historical_candles_crypto.py +177 -0
- {btgsolutions_dataservices_python_client-3.2.6 → btgsolutions_dataservices_python_client-3.2.8}/btgsolutions_dataservices_python_client.egg-info/PKG-INFO +44 -5
- {btgsolutions_dataservices_python_client-3.2.6 → btgsolutions_dataservices_python_client-3.2.8}/btgsolutions_dataservices_python_client.egg-info/SOURCES.txt +2 -0
- {btgsolutions_dataservices_python_client-3.2.6 → btgsolutions_dataservices_python_client-3.2.8}/btgsolutions_dataservices_python_client.egg-info/requires.txt +1 -1
- {btgsolutions_dataservices_python_client-3.2.6 → btgsolutions_dataservices_python_client-3.2.8}/requirements.txt +1 -1
- {btgsolutions_dataservices_python_client-3.2.6 → btgsolutions_dataservices_python_client-3.2.8}/setup.py +1 -1
- {btgsolutions_dataservices_python_client-3.2.6 → btgsolutions_dataservices_python_client-3.2.8}/LICENSE +0 -0
- {btgsolutions_dataservices_python_client-3.2.6 → btgsolutions_dataservices_python_client-3.2.8}/MANIFEST.in +0 -0
- {btgsolutions_dataservices_python_client-3.2.6 → btgsolutions_dataservices_python_client-3.2.8}/btgsolutions_dataservices/config.py +0 -0
- {btgsolutions_dataservices_python_client-3.2.6 → btgsolutions_dataservices_python_client-3.2.8}/btgsolutions_dataservices/exceptions.py +0 -0
- {btgsolutions_dataservices_python_client-3.2.6 → btgsolutions_dataservices_python_client-3.2.8}/btgsolutions_dataservices/rest/authenticator.py +0 -0
- {btgsolutions_dataservices_python_client-3.2.6 → btgsolutions_dataservices_python_client-3.2.8}/btgsolutions_dataservices/rest/bulk_data.py +0 -0
- {btgsolutions_dataservices_python_client-3.2.6 → btgsolutions_dataservices_python_client-3.2.8}/btgsolutions_dataservices/rest/company_data.py +0 -0
- {btgsolutions_dataservices_python_client-3.2.6 → btgsolutions_dataservices_python_client-3.2.8}/btgsolutions_dataservices/rest/corporate_events.py +0 -0
- {btgsolutions_dataservices_python_client-3.2.6 → btgsolutions_dataservices_python_client-3.2.8}/btgsolutions_dataservices/rest/hfn.py +0 -0
- {btgsolutions_dataservices_python_client-3.2.6 → btgsolutions_dataservices_python_client-3.2.8}/btgsolutions_dataservices/rest/intraday_candles.py +0 -0
- {btgsolutions_dataservices_python_client-3.2.6 → btgsolutions_dataservices_python_client-3.2.8}/btgsolutions_dataservices/rest/intraday_tick_data.py +0 -0
- {btgsolutions_dataservices_python_client-3.2.6 → btgsolutions_dataservices_python_client-3.2.8}/btgsolutions_dataservices/rest/public_sources.py +0 -0
- {btgsolutions_dataservices_python_client-3.2.6 → btgsolutions_dataservices_python_client-3.2.8}/btgsolutions_dataservices/rest/quotes.py +0 -0
- {btgsolutions_dataservices_python_client-3.2.6 → btgsolutions_dataservices_python_client-3.2.8}/btgsolutions_dataservices/rest/reference_data.py +0 -0
- {btgsolutions_dataservices_python_client-3.2.6 → btgsolutions_dataservices_python_client-3.2.8}/btgsolutions_dataservices/rest/stock_loan.py +0 -0
- {btgsolutions_dataservices_python_client-3.2.6 → btgsolutions_dataservices_python_client-3.2.8}/btgsolutions_dataservices/rest/ticker_last_event.py +0 -0
- {btgsolutions_dataservices_python_client-3.2.6 → btgsolutions_dataservices_python_client-3.2.8}/btgsolutions_dataservices/rest/ticker_last_event_polling.py +0 -0
- {btgsolutions_dataservices_python_client-3.2.6 → btgsolutions_dataservices_python_client-3.2.8}/btgsolutions_dataservices/websocket/__init__.py +0 -0
- {btgsolutions_dataservices_python_client-3.2.6 → btgsolutions_dataservices_python_client-3.2.8}/btgsolutions_dataservices/websocket/hfn_websocket_client.py +0 -0
- {btgsolutions_dataservices_python_client-3.2.6 → btgsolutions_dataservices_python_client-3.2.8}/btgsolutions_dataservices/websocket/market_data_feed.py +0 -0
- {btgsolutions_dataservices_python_client-3.2.6 → btgsolutions_dataservices_python_client-3.2.8}/btgsolutions_dataservices/websocket/market_data_websocket_client.py +0 -0
- {btgsolutions_dataservices_python_client-3.2.6 → btgsolutions_dataservices_python_client-3.2.8}/btgsolutions_dataservices/websocket/websocket_default_functions.py +0 -0
- {btgsolutions_dataservices_python_client-3.2.6 → btgsolutions_dataservices_python_client-3.2.8}/btgsolutions_dataservices_python_client.egg-info/dependency_links.txt +0 -0
- {btgsolutions_dataservices_python_client-3.2.6 → btgsolutions_dataservices_python_client-3.2.8}/btgsolutions_dataservices_python_client.egg-info/top_level.txt +0 -0
- {btgsolutions_dataservices_python_client-3.2.6 → btgsolutions_dataservices_python_client-3.2.8}/pyproject.toml +0 -0
- {btgsolutions_dataservices_python_client-3.2.6 → btgsolutions_dataservices_python_client-3.2.8}/setup.cfg +0 -0
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: btgsolutions_dataservices_python_client
|
|
3
|
-
Version: 3.2.
|
|
3
|
+
Version: 3.2.8
|
|
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
|
-
Requires-Python: >=3.9,<3.
|
|
7
|
+
Requires-Python: >=3.9,<3.15
|
|
8
8
|
Description-Content-Type: text/markdown
|
|
9
9
|
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
|
|
10
15
|
|
|
11
16
|
# BTG Solutions - Data Services
|
|
12
17
|
|
|
@@ -232,7 +237,7 @@ last_event.get()
|
|
|
232
237
|
```python
|
|
233
238
|
import btgsolutions_dataservices as btg
|
|
234
239
|
hist_candles = btg.HistoricalCandles(api_key='YOUR_API_KEY')
|
|
235
|
-
hist_candles.get_interday_history_candles(ticker='PETR4', market_type='stocks', corporate_events_adj=True, start_date='2023-10-01', end_date='2023-10-13', rmv_after_market=True, timezone='UTC', raw_data=False)
|
|
240
|
+
hist_candles.get_interday_history_candles(ticker='PETR4', market_type='stocks', corporate_events_adj=True, start_date='2023-10-01', end_date='2023-10-13', rmv_after_market=True, timezone='UTC', raw_data=False, round=False)
|
|
236
241
|
```
|
|
237
242
|
|
|
238
243
|
##### Intraday
|
|
@@ -240,7 +245,7 @@ hist_candles.get_interday_history_candles(ticker='PETR4', market_type='stocks',
|
|
|
240
245
|
```python
|
|
241
246
|
import btgsolutions_dataservices as btg
|
|
242
247
|
hist_candles = btg.HistoricalCandles(api_key='YOUR_API_KEY')
|
|
243
|
-
hist_candles.get_intraday_history_candles(ticker='PETR4', market_type='stocks', corporate_events_adj=True, date='2023-10-06', candle='1m', rmv_after_market=True, timezone='UTC', raw_data=False)
|
|
248
|
+
hist_candles.get_intraday_history_candles(ticker='PETR4', market_type='stocks', corporate_events_adj=True, date='2023-10-06', candle='1m', rmv_after_market=True, timezone='UTC', raw_data=False, round=True)
|
|
244
249
|
```
|
|
245
250
|
|
|
246
251
|
##### Available Tickers
|
|
@@ -259,6 +264,32 @@ hist_candles = btg.HistoricalCandles(api_key='YOUR_API_KEY')
|
|
|
259
264
|
hist_candles.get_intraday_history_candles(ticker='PETR4', market_type='stocks', corporate_events_adj=True, date='2023-10-06', candle='1m', rmv_after_market=True, timezone='UTC', raw_data=False).plot(x='candle_time', y='close_price', kind='scatter')
|
|
260
265
|
```
|
|
261
266
|
|
|
267
|
+
#### Historical Candles Crypto
|
|
268
|
+
|
|
269
|
+
##### Interday
|
|
270
|
+
|
|
271
|
+
```python
|
|
272
|
+
import btgsolutions_dataservices as btg
|
|
273
|
+
hist_candles_crypto = btg.HistoricalCandlesCrypto(api_key='YOUR_API_KEY')
|
|
274
|
+
hist_candles_crypto.get_interday_history_candles(ticker='BTC', currency='BRL', exchange='consolidated', start_date='2025-06-01', end_date='2025-07-01', timezone='UTC', raw_data=False)
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
##### Intraday
|
|
278
|
+
|
|
279
|
+
```python
|
|
280
|
+
import btgsolutions_dataservices as btg
|
|
281
|
+
hist_candles_crypto = btg.HistoricalCandlesCrypto(api_key='YOUR_API_KEY')
|
|
282
|
+
hist_candles_crypto.get_intraday_history_candles(ticker='BTC', currency='BRL', exchange='consolidated', date='2025-06-01', candle='1h', timezone='America/Sao_Paulo', raw_data=False)
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
##### Available Tickers
|
|
286
|
+
|
|
287
|
+
```python
|
|
288
|
+
import btgsolutions_dataservices as btg
|
|
289
|
+
hist_candles_crypto = btg.HistoricalCandlesCrypto(api_key='YOUR_API_KEY')
|
|
290
|
+
hist_candles_crypto.get_available_tickers(exchange='coinbase', date='2023-01-13')
|
|
291
|
+
```
|
|
292
|
+
|
|
262
293
|
#### Historical Tick Data (Bulk Data)
|
|
263
294
|
|
|
264
295
|
##### Available Tickers
|
|
@@ -432,6 +463,14 @@ corporate_events.get(start_date='2024-05-01', end_date='2024-05-31')
|
|
|
432
463
|
# corporate_events.get(start_date='2024-05-01', end_date='2024-05-31', tickers=['VALE3'])
|
|
433
464
|
```
|
|
434
465
|
|
|
466
|
+
#### Broker Reference
|
|
467
|
+
|
|
468
|
+
```python
|
|
469
|
+
import btgsolutions_dataservices as btg
|
|
470
|
+
broker_reference = btg.BrokerReference(api_key='YOUR_API_KEY')
|
|
471
|
+
broker_reference.get()
|
|
472
|
+
```
|
|
473
|
+
|
|
435
474
|
#### Ticker Reference Data
|
|
436
475
|
|
|
437
476
|
```python
|
|
@@ -222,7 +222,7 @@ last_event.get()
|
|
|
222
222
|
```python
|
|
223
223
|
import btgsolutions_dataservices as btg
|
|
224
224
|
hist_candles = btg.HistoricalCandles(api_key='YOUR_API_KEY')
|
|
225
|
-
hist_candles.get_interday_history_candles(ticker='PETR4', market_type='stocks', corporate_events_adj=True, start_date='2023-10-01', end_date='2023-10-13', rmv_after_market=True, timezone='UTC', raw_data=False)
|
|
225
|
+
hist_candles.get_interday_history_candles(ticker='PETR4', market_type='stocks', corporate_events_adj=True, start_date='2023-10-01', end_date='2023-10-13', rmv_after_market=True, timezone='UTC', raw_data=False, round=False)
|
|
226
226
|
```
|
|
227
227
|
|
|
228
228
|
##### Intraday
|
|
@@ -230,7 +230,7 @@ hist_candles.get_interday_history_candles(ticker='PETR4', market_type='stocks',
|
|
|
230
230
|
```python
|
|
231
231
|
import btgsolutions_dataservices as btg
|
|
232
232
|
hist_candles = btg.HistoricalCandles(api_key='YOUR_API_KEY')
|
|
233
|
-
hist_candles.get_intraday_history_candles(ticker='PETR4', market_type='stocks', corporate_events_adj=True, date='2023-10-06', candle='1m', rmv_after_market=True, timezone='UTC', raw_data=False)
|
|
233
|
+
hist_candles.get_intraday_history_candles(ticker='PETR4', market_type='stocks', corporate_events_adj=True, date='2023-10-06', candle='1m', rmv_after_market=True, timezone='UTC', raw_data=False, round=True)
|
|
234
234
|
```
|
|
235
235
|
|
|
236
236
|
##### Available Tickers
|
|
@@ -249,6 +249,32 @@ hist_candles = btg.HistoricalCandles(api_key='YOUR_API_KEY')
|
|
|
249
249
|
hist_candles.get_intraday_history_candles(ticker='PETR4', market_type='stocks', corporate_events_adj=True, date='2023-10-06', candle='1m', rmv_after_market=True, timezone='UTC', raw_data=False).plot(x='candle_time', y='close_price', kind='scatter')
|
|
250
250
|
```
|
|
251
251
|
|
|
252
|
+
#### Historical Candles Crypto
|
|
253
|
+
|
|
254
|
+
##### Interday
|
|
255
|
+
|
|
256
|
+
```python
|
|
257
|
+
import btgsolutions_dataservices as btg
|
|
258
|
+
hist_candles_crypto = btg.HistoricalCandlesCrypto(api_key='YOUR_API_KEY')
|
|
259
|
+
hist_candles_crypto.get_interday_history_candles(ticker='BTC', currency='BRL', exchange='consolidated', start_date='2025-06-01', end_date='2025-07-01', timezone='UTC', raw_data=False)
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
##### Intraday
|
|
263
|
+
|
|
264
|
+
```python
|
|
265
|
+
import btgsolutions_dataservices as btg
|
|
266
|
+
hist_candles_crypto = btg.HistoricalCandlesCrypto(api_key='YOUR_API_KEY')
|
|
267
|
+
hist_candles_crypto.get_intraday_history_candles(ticker='BTC', currency='BRL', exchange='consolidated', date='2025-06-01', candle='1h', timezone='America/Sao_Paulo', raw_data=False)
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
##### Available Tickers
|
|
271
|
+
|
|
272
|
+
```python
|
|
273
|
+
import btgsolutions_dataservices as btg
|
|
274
|
+
hist_candles_crypto = btg.HistoricalCandlesCrypto(api_key='YOUR_API_KEY')
|
|
275
|
+
hist_candles_crypto.get_available_tickers(exchange='coinbase', date='2023-01-13')
|
|
276
|
+
```
|
|
277
|
+
|
|
252
278
|
#### Historical Tick Data (Bulk Data)
|
|
253
279
|
|
|
254
280
|
##### Available Tickers
|
|
@@ -422,6 +448,14 @@ corporate_events.get(start_date='2024-05-01', end_date='2024-05-31')
|
|
|
422
448
|
# corporate_events.get(start_date='2024-05-01', end_date='2024-05-31', tickers=['VALE3'])
|
|
423
449
|
```
|
|
424
450
|
|
|
451
|
+
#### Broker Reference
|
|
452
|
+
|
|
453
|
+
```python
|
|
454
|
+
import btgsolutions_dataservices as btg
|
|
455
|
+
broker_reference = btg.BrokerReference(api_key='YOUR_API_KEY')
|
|
456
|
+
broker_reference.get()
|
|
457
|
+
```
|
|
458
|
+
|
|
425
459
|
#### Ticker Reference Data
|
|
426
460
|
|
|
427
461
|
```python
|
btgsolutions_dataservices_python_client-3.2.8/btgsolutions_dataservices/rest/broker_reference.py
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
from ..exceptions import BadResponse
|
|
3
|
+
import requests
|
|
4
|
+
from ..config import url_api_v1
|
|
5
|
+
from .authenticator import Authenticator
|
|
6
|
+
import pandas as pd
|
|
7
|
+
import json
|
|
8
|
+
|
|
9
|
+
class BrokerReference:
|
|
10
|
+
"""
|
|
11
|
+
This class provides broker reference information.
|
|
12
|
+
|
|
13
|
+
* Main use case:
|
|
14
|
+
|
|
15
|
+
>>> from btgsolutions_dataservices import BrokerReference
|
|
16
|
+
>>> broker_reference = BrokerReference(
|
|
17
|
+
>>> api_key='YOUR_API_KEY',
|
|
18
|
+
>>> )
|
|
19
|
+
>>> broker_reference.get()
|
|
20
|
+
|
|
21
|
+
Parameters
|
|
22
|
+
----------------
|
|
23
|
+
api_key: str
|
|
24
|
+
User identification key.
|
|
25
|
+
Field is required.
|
|
26
|
+
"""
|
|
27
|
+
def __init__(
|
|
28
|
+
self,
|
|
29
|
+
api_key:Optional[str]
|
|
30
|
+
):
|
|
31
|
+
self.api_key = api_key
|
|
32
|
+
self.token = Authenticator(self.api_key).token
|
|
33
|
+
self.headers = {"authorization": f"authorization {self.token}"}
|
|
34
|
+
|
|
35
|
+
def get(self, raw_data:bool=False):
|
|
36
|
+
|
|
37
|
+
"""
|
|
38
|
+
Returns the full broker reference dataset from the API.
|
|
39
|
+
|
|
40
|
+
Parameters
|
|
41
|
+
----------------
|
|
42
|
+
raw_data: bool
|
|
43
|
+
If False, returns the response as a pandas DataFrame.
|
|
44
|
+
If True, returns the raw JSON payload.
|
|
45
|
+
Field is not required. Default: False.
|
|
46
|
+
|
|
47
|
+
Returns
|
|
48
|
+
----------------
|
|
49
|
+
pandas.DataFrame | dict | list
|
|
50
|
+
Broker reference data returned by the API.
|
|
51
|
+
"""
|
|
52
|
+
|
|
53
|
+
url = f"{url_api_v1}/marketdata/broker/info/all-brokers"
|
|
54
|
+
|
|
55
|
+
response = requests.request("GET", url, headers=self.headers)
|
|
56
|
+
if response.status_code == 200:
|
|
57
|
+
if raw_data:
|
|
58
|
+
return response.json()
|
|
59
|
+
else:
|
|
60
|
+
return pd.DataFrame(response.json())
|
|
61
|
+
else:
|
|
62
|
+
response = json.loads(response.text)
|
|
63
|
+
raise BadResponse(f'Error: {response.get("error", "")}')
|
|
@@ -24,6 +24,7 @@ class HistoricalCandles:
|
|
|
24
24
|
>>> end_date = '2023-10-20',
|
|
25
25
|
>>> rmv_after_market = True,
|
|
26
26
|
>>> timezone = 'UTC',
|
|
27
|
+
>>> round = True,
|
|
27
28
|
>>> raw_data = False
|
|
28
29
|
>>> )
|
|
29
30
|
|
|
@@ -37,6 +38,7 @@ class HistoricalCandles:
|
|
|
37
38
|
>>> rmv_after_market = True,
|
|
38
39
|
>>> timezone = 'UTC',
|
|
39
40
|
>>> candle='1m',
|
|
41
|
+
>>> round = True,
|
|
40
42
|
>>> raw_data = False
|
|
41
43
|
>>> )
|
|
42
44
|
|
|
@@ -63,7 +65,8 @@ class HistoricalCandles:
|
|
|
63
65
|
corporate_events_adj:bool,
|
|
64
66
|
rmv_after_market:bool,
|
|
65
67
|
timezone:str,
|
|
66
|
-
raw_data:bool=False
|
|
68
|
+
raw_data:bool=False,
|
|
69
|
+
round:bool=True
|
|
67
70
|
):
|
|
68
71
|
"""
|
|
69
72
|
This method provides historical candles for a given ticket in determined period.
|
|
@@ -93,12 +96,15 @@ class HistoricalCandles:
|
|
|
93
96
|
raw_data: bool
|
|
94
97
|
If false, returns data in a dataframe. If true, returns raw data.
|
|
95
98
|
Field is not required. Default: False.
|
|
99
|
+
round: bool
|
|
100
|
+
Apply rounding to prices.
|
|
101
|
+
Field is not required. Default: True.
|
|
96
102
|
"""
|
|
97
103
|
|
|
98
104
|
if market_type not in ['stocks', 'derivatives']:
|
|
99
105
|
raise MarketTypeError(f'Allowed values: "stocks" or "derivatives". Input value: "{market_type}".')
|
|
100
106
|
|
|
101
|
-
url = f"{url_apis_v3}/marketdata/history/candles/intraday/{market_type}?ticker={ticker}&corporate_events_adj={corporate_events_adj}&rmv_after_market={rmv_after_market}&timezone={timezone}&date={date}&candle={candle}"
|
|
107
|
+
url = f"{url_apis_v3}/marketdata/history/candles/intraday/{market_type}?ticker={ticker}&corporate_events_adj={corporate_events_adj}&rmv_after_market={rmv_after_market}&timezone={timezone}&date={date}&candle={candle}&round={round}"
|
|
102
108
|
response = requests.request("GET", url, headers=self.headers)
|
|
103
109
|
if response.status_code == 200:
|
|
104
110
|
response_data = json.loads(response.text)
|
|
@@ -116,7 +122,8 @@ class HistoricalCandles:
|
|
|
116
122
|
corporate_events_adj:bool,
|
|
117
123
|
rmv_after_market:bool,
|
|
118
124
|
timezone:str,
|
|
119
|
-
raw_data:bool=False
|
|
125
|
+
raw_data:bool=False,
|
|
126
|
+
round:bool=True
|
|
120
127
|
):
|
|
121
128
|
"""
|
|
122
129
|
This method provides historical candles for a given ticket in determined period.
|
|
@@ -146,12 +153,15 @@ class HistoricalCandles:
|
|
|
146
153
|
raw_data: bool
|
|
147
154
|
If false, returns data in a dataframe. If true, returns raw data.
|
|
148
155
|
Field is not required. Default: False.
|
|
156
|
+
round: bool
|
|
157
|
+
Apply rounding to prices.
|
|
158
|
+
Field is not required. Default: True.
|
|
149
159
|
"""
|
|
150
160
|
|
|
151
161
|
if market_type not in ['stocks', 'derivatives']:
|
|
152
162
|
raise MarketTypeError(f'Allowed values: "stocks" or "derivatives". Input value: "{market_type}".')
|
|
153
163
|
|
|
154
|
-
url = f"{url_apis_v3}/marketdata/history/candles/interday/{market_type}?ticker={ticker}&corporate_events_adj={corporate_events_adj}&rmv_after_market={rmv_after_market}&timezone={timezone}&start_date={start_date}&end_date={end_date}"
|
|
164
|
+
url = f"{url_apis_v3}/marketdata/history/candles/interday/{market_type}?ticker={ticker}&corporate_events_adj={corporate_events_adj}&rmv_after_market={rmv_after_market}&timezone={timezone}&start_date={start_date}&end_date={end_date}&round={round}"
|
|
155
165
|
response = requests.request("GET", url, headers=self.headers)
|
|
156
166
|
if response.status_code == 200:
|
|
157
167
|
response_data = json.loads(response.text)
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
from ..exceptions import BadResponse, MarketTypeError
|
|
3
|
+
import requests
|
|
4
|
+
from ..config import url_apis_v3
|
|
5
|
+
from .authenticator import Authenticator
|
|
6
|
+
import json
|
|
7
|
+
import pandas as pd
|
|
8
|
+
|
|
9
|
+
class HistoricalCandlesCrypto:
|
|
10
|
+
"""
|
|
11
|
+
This class provides historical candles for cryptocurrencies.
|
|
12
|
+
|
|
13
|
+
Available tickers: ETH, SOL, BTC
|
|
14
|
+
Available exchanges: coinbase, mercado_bitcoin, consolidated
|
|
15
|
+
Available currencies: BRL, USD
|
|
16
|
+
Available candles: '1s', '30s', '1m', '5m', '15m', '30m', '1h'
|
|
17
|
+
|
|
18
|
+
* Main use case - Interday:
|
|
19
|
+
|
|
20
|
+
>>> from btgsolutions_dataservices import HistoricalCandlesCrypto
|
|
21
|
+
>>> hist_candles = HistoricalCandlesCrypto(
|
|
22
|
+
>>> api_key='YOUR_API_KEY',
|
|
23
|
+
>>> )
|
|
24
|
+
>>> hist_candles.get_interday_history_candles(
|
|
25
|
+
>>> ticker = 'BTC',
|
|
26
|
+
>>> currency = 'BRL',
|
|
27
|
+
>>> exchange = 'consolidated',
|
|
28
|
+
>>> start_date = '2025-06-01',
|
|
29
|
+
>>> end_date = '2025-07-01',
|
|
30
|
+
>>> timezone = 'UTC',
|
|
31
|
+
>>> raw_data = False
|
|
32
|
+
>>> )
|
|
33
|
+
|
|
34
|
+
* Main use case - Intraday:
|
|
35
|
+
|
|
36
|
+
>>> hist_candles.get_intraday_history_candles(
|
|
37
|
+
>>> ticker = 'BTC',
|
|
38
|
+
>>> currency = 'BRL',
|
|
39
|
+
>>> exchange = 'consolidated',
|
|
40
|
+
>>> date = '2025-06-01',
|
|
41
|
+
>>> timezone = 'America/Sao_Paulo',
|
|
42
|
+
>>> candle='1h',
|
|
43
|
+
>>> raw_data = False
|
|
44
|
+
>>> )
|
|
45
|
+
|
|
46
|
+
Parameters
|
|
47
|
+
----------------
|
|
48
|
+
api_key: str
|
|
49
|
+
User identification key.
|
|
50
|
+
Field is required.
|
|
51
|
+
"""
|
|
52
|
+
def __init__(
|
|
53
|
+
self,
|
|
54
|
+
api_key:Optional[str]
|
|
55
|
+
):
|
|
56
|
+
self.api_key = api_key
|
|
57
|
+
self.token = Authenticator(self.api_key).token
|
|
58
|
+
self.headers = {"authorization": f"authorization {self.token}"}
|
|
59
|
+
|
|
60
|
+
def get_intraday_history_candles(
|
|
61
|
+
self,
|
|
62
|
+
ticker:str,
|
|
63
|
+
currency:str,
|
|
64
|
+
exchange:str,
|
|
65
|
+
date:str,
|
|
66
|
+
candle:str,
|
|
67
|
+
timezone:str,
|
|
68
|
+
raw_data:bool=False
|
|
69
|
+
):
|
|
70
|
+
"""
|
|
71
|
+
This method provides historical intraday candles for cryptocurrencies.
|
|
72
|
+
|
|
73
|
+
Parameters
|
|
74
|
+
----------------
|
|
75
|
+
ticker: str
|
|
76
|
+
Cryptocurrency ticker.
|
|
77
|
+
Field is required. Allowed values: 'BTC', 'ETH', 'SOL'.
|
|
78
|
+
currency: str
|
|
79
|
+
Currency for the prices.
|
|
80
|
+
Field is required. Allowed values: 'BRL' or 'USD'.
|
|
81
|
+
exchange: str
|
|
82
|
+
Exchange name.
|
|
83
|
+
Field is required. Allowed values: 'coinbase', 'mercado_bitcoin', 'consolidated'.
|
|
84
|
+
date: string<date>
|
|
85
|
+
Date of requested data. Format: "YYYY-MM-DD".
|
|
86
|
+
Field is required. Example: '2025-06-01'.
|
|
87
|
+
candle: str
|
|
88
|
+
Candle period.
|
|
89
|
+
Field is required. Allowed values: '1s', '30s', '1m', '5m', '15m', '30m', '1h'.
|
|
90
|
+
timezone: str
|
|
91
|
+
Timezone of the datetime.
|
|
92
|
+
Field is required. Allowed values: 'America/Sao_Paulo' or 'UTC'.
|
|
93
|
+
raw_data: bool
|
|
94
|
+
If false, returns data in a dataframe. If true, returns raw data.
|
|
95
|
+
Field is not required. Default: False.
|
|
96
|
+
"""
|
|
97
|
+
|
|
98
|
+
url = f"{url_apis_v3}/marketdata/history/candles/intraday/crypto?ticker={ticker}¤cy={currency}&exchange={exchange}&date={date}&candle={candle}&timezone={timezone}"
|
|
99
|
+
response = requests.request("GET", url, headers=self.headers)
|
|
100
|
+
if response.status_code == 200:
|
|
101
|
+
response_data = json.loads(response.text)
|
|
102
|
+
return response_data if raw_data else pd.DataFrame(response_data)
|
|
103
|
+
|
|
104
|
+
response = json.loads(response.text)
|
|
105
|
+
raise BadResponse(f'Error: {response.get("ApiClientError", "")}.\n{response.get("SuggestedAction", "")}')
|
|
106
|
+
|
|
107
|
+
def get_interday_history_candles(
|
|
108
|
+
self,
|
|
109
|
+
ticker:str,
|
|
110
|
+
currency:str,
|
|
111
|
+
exchange:str,
|
|
112
|
+
start_date:str,
|
|
113
|
+
end_date:str,
|
|
114
|
+
timezone:str,
|
|
115
|
+
raw_data:bool=False
|
|
116
|
+
):
|
|
117
|
+
"""
|
|
118
|
+
This method provides historical daily candles for cryptocurrencies.
|
|
119
|
+
|
|
120
|
+
Parameters
|
|
121
|
+
----------------
|
|
122
|
+
ticker: str
|
|
123
|
+
Cryptocurrency ticker.
|
|
124
|
+
Field is required. Allowed values: 'BTC', 'ETH', 'SOL'.
|
|
125
|
+
currency: str
|
|
126
|
+
Currency for the prices.
|
|
127
|
+
Field is required. Allowed values: 'BRL' or 'USD'.
|
|
128
|
+
exchange: str
|
|
129
|
+
Exchange name.
|
|
130
|
+
Field is required. Allowed values: 'coinbase', 'mercado_bitcoin', 'consolidated'.
|
|
131
|
+
start_date: string<date>
|
|
132
|
+
Start date of analysis. Format: "YYYY-MM-DD".
|
|
133
|
+
Field is required. Example: '2025-06-01'.
|
|
134
|
+
end_date: string<date>
|
|
135
|
+
End date of analysis. Format: "YYYY-MM-DD".
|
|
136
|
+
Field is required. Example: '2025-07-01'.
|
|
137
|
+
timezone: str
|
|
138
|
+
Timezone of the datetime.
|
|
139
|
+
Field is required. Allowed values: 'America/Sao_Paulo' or 'UTC'.
|
|
140
|
+
raw_data: bool
|
|
141
|
+
If false, returns data in a dataframe. If true, returns raw data.
|
|
142
|
+
Field is not required. Default: False.
|
|
143
|
+
"""
|
|
144
|
+
|
|
145
|
+
url = f"{url_apis_v3}/marketdata/history/candles/interday/crypto?ticker={ticker}¤cy={currency}&exchange={exchange}&start_date={start_date}&end_date={end_date}&timezone={timezone}"
|
|
146
|
+
response = requests.request("GET", url, headers=self.headers)
|
|
147
|
+
if response.status_code == 200:
|
|
148
|
+
response_data = json.loads(response.text)
|
|
149
|
+
return response_data if raw_data else pd.DataFrame(response_data)
|
|
150
|
+
|
|
151
|
+
response = json.loads(response.text)
|
|
152
|
+
raise BadResponse(f'Error: {response.get("ApiClientError", "")}.\n{response.get("SuggestedAction", "")}')
|
|
153
|
+
|
|
154
|
+
def get_available_tickers(
|
|
155
|
+
self,
|
|
156
|
+
exchange:str,
|
|
157
|
+
date:str,
|
|
158
|
+
):
|
|
159
|
+
"""
|
|
160
|
+
This method provides all cryptocurrency tickers available for query.
|
|
161
|
+
|
|
162
|
+
Parameters
|
|
163
|
+
----------------
|
|
164
|
+
exchange: str
|
|
165
|
+
Exchange name.
|
|
166
|
+
Field is required. Allowed values: 'coinbase', 'mercado_bitcoin', 'consolidated'.
|
|
167
|
+
date: string<date>
|
|
168
|
+
Date of requested data. Format: "YYYY-MM-DD".
|
|
169
|
+
Field is required. Example: '2023-01-13'.
|
|
170
|
+
"""
|
|
171
|
+
|
|
172
|
+
url = f"{url_apis_v3}/marketdata/history/candles/available-tickers/crypto?date={date}&exchange={exchange}"
|
|
173
|
+
|
|
174
|
+
response = requests.request("GET", url, headers=self.headers)
|
|
175
|
+
if response.status_code == 200: return response.json()
|
|
176
|
+
response = response.json()
|
|
177
|
+
raise BadResponse(f'Error: {response.get("ApiClientError", "") or response.get("ApiServerMessage", "")}.\n{response.get("SuggestedAction", "")}')
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
|
-
Name:
|
|
3
|
-
Version: 3.2.
|
|
2
|
+
Name: btgsolutions_dataservices_python_client
|
|
3
|
+
Version: 3.2.8
|
|
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
|
-
Requires-Python: >=3.9,<3.
|
|
7
|
+
Requires-Python: >=3.9,<3.15
|
|
8
8
|
Description-Content-Type: text/markdown
|
|
9
9
|
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
|
|
10
15
|
|
|
11
16
|
# BTG Solutions - Data Services
|
|
12
17
|
|
|
@@ -232,7 +237,7 @@ last_event.get()
|
|
|
232
237
|
```python
|
|
233
238
|
import btgsolutions_dataservices as btg
|
|
234
239
|
hist_candles = btg.HistoricalCandles(api_key='YOUR_API_KEY')
|
|
235
|
-
hist_candles.get_interday_history_candles(ticker='PETR4', market_type='stocks', corporate_events_adj=True, start_date='2023-10-01', end_date='2023-10-13', rmv_after_market=True, timezone='UTC', raw_data=False)
|
|
240
|
+
hist_candles.get_interday_history_candles(ticker='PETR4', market_type='stocks', corporate_events_adj=True, start_date='2023-10-01', end_date='2023-10-13', rmv_after_market=True, timezone='UTC', raw_data=False, round=False)
|
|
236
241
|
```
|
|
237
242
|
|
|
238
243
|
##### Intraday
|
|
@@ -240,7 +245,7 @@ hist_candles.get_interday_history_candles(ticker='PETR4', market_type='stocks',
|
|
|
240
245
|
```python
|
|
241
246
|
import btgsolutions_dataservices as btg
|
|
242
247
|
hist_candles = btg.HistoricalCandles(api_key='YOUR_API_KEY')
|
|
243
|
-
hist_candles.get_intraday_history_candles(ticker='PETR4', market_type='stocks', corporate_events_adj=True, date='2023-10-06', candle='1m', rmv_after_market=True, timezone='UTC', raw_data=False)
|
|
248
|
+
hist_candles.get_intraday_history_candles(ticker='PETR4', market_type='stocks', corporate_events_adj=True, date='2023-10-06', candle='1m', rmv_after_market=True, timezone='UTC', raw_data=False, round=True)
|
|
244
249
|
```
|
|
245
250
|
|
|
246
251
|
##### Available Tickers
|
|
@@ -259,6 +264,32 @@ hist_candles = btg.HistoricalCandles(api_key='YOUR_API_KEY')
|
|
|
259
264
|
hist_candles.get_intraday_history_candles(ticker='PETR4', market_type='stocks', corporate_events_adj=True, date='2023-10-06', candle='1m', rmv_after_market=True, timezone='UTC', raw_data=False).plot(x='candle_time', y='close_price', kind='scatter')
|
|
260
265
|
```
|
|
261
266
|
|
|
267
|
+
#### Historical Candles Crypto
|
|
268
|
+
|
|
269
|
+
##### Interday
|
|
270
|
+
|
|
271
|
+
```python
|
|
272
|
+
import btgsolutions_dataservices as btg
|
|
273
|
+
hist_candles_crypto = btg.HistoricalCandlesCrypto(api_key='YOUR_API_KEY')
|
|
274
|
+
hist_candles_crypto.get_interday_history_candles(ticker='BTC', currency='BRL', exchange='consolidated', start_date='2025-06-01', end_date='2025-07-01', timezone='UTC', raw_data=False)
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
##### Intraday
|
|
278
|
+
|
|
279
|
+
```python
|
|
280
|
+
import btgsolutions_dataservices as btg
|
|
281
|
+
hist_candles_crypto = btg.HistoricalCandlesCrypto(api_key='YOUR_API_KEY')
|
|
282
|
+
hist_candles_crypto.get_intraday_history_candles(ticker='BTC', currency='BRL', exchange='consolidated', date='2025-06-01', candle='1h', timezone='America/Sao_Paulo', raw_data=False)
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
##### Available Tickers
|
|
286
|
+
|
|
287
|
+
```python
|
|
288
|
+
import btgsolutions_dataservices as btg
|
|
289
|
+
hist_candles_crypto = btg.HistoricalCandlesCrypto(api_key='YOUR_API_KEY')
|
|
290
|
+
hist_candles_crypto.get_available_tickers(exchange='coinbase', date='2023-01-13')
|
|
291
|
+
```
|
|
292
|
+
|
|
262
293
|
#### Historical Tick Data (Bulk Data)
|
|
263
294
|
|
|
264
295
|
##### Available Tickers
|
|
@@ -432,6 +463,14 @@ corporate_events.get(start_date='2024-05-01', end_date='2024-05-31')
|
|
|
432
463
|
# corporate_events.get(start_date='2024-05-01', end_date='2024-05-31', tickers=['VALE3'])
|
|
433
464
|
```
|
|
434
465
|
|
|
466
|
+
#### Broker Reference
|
|
467
|
+
|
|
468
|
+
```python
|
|
469
|
+
import btgsolutions_dataservices as btg
|
|
470
|
+
broker_reference = btg.BrokerReference(api_key='YOUR_API_KEY')
|
|
471
|
+
broker_reference.get()
|
|
472
|
+
```
|
|
473
|
+
|
|
435
474
|
#### Ticker Reference Data
|
|
436
475
|
|
|
437
476
|
```python
|
|
@@ -9,11 +9,13 @@ btgsolutions_dataservices/config.py
|
|
|
9
9
|
btgsolutions_dataservices/exceptions.py
|
|
10
10
|
btgsolutions_dataservices/rest/__init__.py
|
|
11
11
|
btgsolutions_dataservices/rest/authenticator.py
|
|
12
|
+
btgsolutions_dataservices/rest/broker_reference.py
|
|
12
13
|
btgsolutions_dataservices/rest/bulk_data.py
|
|
13
14
|
btgsolutions_dataservices/rest/company_data.py
|
|
14
15
|
btgsolutions_dataservices/rest/corporate_events.py
|
|
15
16
|
btgsolutions_dataservices/rest/hfn.py
|
|
16
17
|
btgsolutions_dataservices/rest/historical_candles.py
|
|
18
|
+
btgsolutions_dataservices/rest/historical_candles_crypto.py
|
|
17
19
|
btgsolutions_dataservices/rest/intraday_candles.py
|
|
18
20
|
btgsolutions_dataservices/rest/intraday_tick_data.py
|
|
19
21
|
btgsolutions_dataservices/rest/public_sources.py
|
|
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
|