btgsolutions-dataservices-python-client 3.2.8__tar.gz → 3.2.10__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.8/btgsolutions_dataservices_python_client.egg-info → btgsolutions_dataservices_python_client-3.2.10}/PKG-INFO +34 -2
- {btgsolutions_dataservices_python_client-3.2.8 → btgsolutions_dataservices_python_client-3.2.10}/README.md +24 -0
- {btgsolutions_dataservices_python_client-3.2.8 → btgsolutions_dataservices_python_client-3.2.10}/btgsolutions_dataservices/__init__.py +1 -1
- {btgsolutions_dataservices_python_client-3.2.8 → btgsolutions_dataservices_python_client-3.2.10}/btgsolutions_dataservices/config.py +6 -0
- {btgsolutions_dataservices_python_client-3.2.8 → btgsolutions_dataservices_python_client-3.2.10}/btgsolutions_dataservices/rest/__init__.py +1 -0
- {btgsolutions_dataservices_python_client-3.2.8 → btgsolutions_dataservices_python_client-3.2.10}/btgsolutions_dataservices/rest/historical_candles.py +4 -0
- {btgsolutions_dataservices_python_client-3.2.8 → btgsolutions_dataservices_python_client-3.2.10}/btgsolutions_dataservices/rest/quotes.py +4 -4
- {btgsolutions_dataservices_python_client-3.2.8 → btgsolutions_dataservices_python_client-3.2.10}/btgsolutions_dataservices/websocket/__init__.py +2 -1
- btgsolutions_dataservices_python_client-3.2.10/btgsolutions_dataservices/websocket/broker_analytics.py +300 -0
- {btgsolutions_dataservices_python_client-3.2.8 → btgsolutions_dataservices_python_client-3.2.10/btgsolutions_dataservices_python_client.egg-info}/PKG-INFO +34 -2
- {btgsolutions_dataservices_python_client-3.2.8 → btgsolutions_dataservices_python_client-3.2.10}/btgsolutions_dataservices_python_client.egg-info/SOURCES.txt +1 -0
- {btgsolutions_dataservices_python_client-3.2.8 → btgsolutions_dataservices_python_client-3.2.10}/LICENSE +0 -0
- {btgsolutions_dataservices_python_client-3.2.8 → btgsolutions_dataservices_python_client-3.2.10}/MANIFEST.in +0 -0
- {btgsolutions_dataservices_python_client-3.2.8 → btgsolutions_dataservices_python_client-3.2.10}/btgsolutions_dataservices/exceptions.py +0 -0
- {btgsolutions_dataservices_python_client-3.2.8 → btgsolutions_dataservices_python_client-3.2.10}/btgsolutions_dataservices/rest/authenticator.py +0 -0
- {btgsolutions_dataservices_python_client-3.2.8 → btgsolutions_dataservices_python_client-3.2.10}/btgsolutions_dataservices/rest/broker_reference.py +0 -0
- {btgsolutions_dataservices_python_client-3.2.8 → btgsolutions_dataservices_python_client-3.2.10}/btgsolutions_dataservices/rest/bulk_data.py +0 -0
- {btgsolutions_dataservices_python_client-3.2.8 → btgsolutions_dataservices_python_client-3.2.10}/btgsolutions_dataservices/rest/company_data.py +0 -0
- {btgsolutions_dataservices_python_client-3.2.8 → btgsolutions_dataservices_python_client-3.2.10}/btgsolutions_dataservices/rest/corporate_events.py +0 -0
- {btgsolutions_dataservices_python_client-3.2.8 → btgsolutions_dataservices_python_client-3.2.10}/btgsolutions_dataservices/rest/hfn.py +0 -0
- {btgsolutions_dataservices_python_client-3.2.8 → btgsolutions_dataservices_python_client-3.2.10}/btgsolutions_dataservices/rest/historical_candles_crypto.py +0 -0
- {btgsolutions_dataservices_python_client-3.2.8 → btgsolutions_dataservices_python_client-3.2.10}/btgsolutions_dataservices/rest/intraday_candles.py +0 -0
- {btgsolutions_dataservices_python_client-3.2.8 → btgsolutions_dataservices_python_client-3.2.10}/btgsolutions_dataservices/rest/intraday_tick_data.py +0 -0
- {btgsolutions_dataservices_python_client-3.2.8 → btgsolutions_dataservices_python_client-3.2.10}/btgsolutions_dataservices/rest/public_sources.py +0 -0
- {btgsolutions_dataservices_python_client-3.2.8 → btgsolutions_dataservices_python_client-3.2.10}/btgsolutions_dataservices/rest/reference_data.py +0 -0
- {btgsolutions_dataservices_python_client-3.2.8 → btgsolutions_dataservices_python_client-3.2.10}/btgsolutions_dataservices/rest/stock_loan.py +0 -0
- {btgsolutions_dataservices_python_client-3.2.8 → btgsolutions_dataservices_python_client-3.2.10}/btgsolutions_dataservices/rest/ticker_last_event.py +0 -0
- {btgsolutions_dataservices_python_client-3.2.8 → btgsolutions_dataservices_python_client-3.2.10}/btgsolutions_dataservices/rest/ticker_last_event_polling.py +0 -0
- {btgsolutions_dataservices_python_client-3.2.8 → btgsolutions_dataservices_python_client-3.2.10}/btgsolutions_dataservices/websocket/hfn_websocket_client.py +0 -0
- {btgsolutions_dataservices_python_client-3.2.8 → btgsolutions_dataservices_python_client-3.2.10}/btgsolutions_dataservices/websocket/market_data_feed.py +0 -0
- {btgsolutions_dataservices_python_client-3.2.8 → btgsolutions_dataservices_python_client-3.2.10}/btgsolutions_dataservices/websocket/market_data_websocket_client.py +0 -0
- {btgsolutions_dataservices_python_client-3.2.8 → btgsolutions_dataservices_python_client-3.2.10}/btgsolutions_dataservices/websocket/websocket_default_functions.py +0 -0
- {btgsolutions_dataservices_python_client-3.2.8 → btgsolutions_dataservices_python_client-3.2.10}/btgsolutions_dataservices_python_client.egg-info/dependency_links.txt +0 -0
- {btgsolutions_dataservices_python_client-3.2.8 → btgsolutions_dataservices_python_client-3.2.10}/btgsolutions_dataservices_python_client.egg-info/requires.txt +0 -0
- {btgsolutions_dataservices_python_client-3.2.8 → btgsolutions_dataservices_python_client-3.2.10}/btgsolutions_dataservices_python_client.egg-info/top_level.txt +0 -0
- {btgsolutions_dataservices_python_client-3.2.8 → btgsolutions_dataservices_python_client-3.2.10}/pyproject.toml +0 -0
- {btgsolutions_dataservices_python_client-3.2.8 → btgsolutions_dataservices_python_client-3.2.10}/requirements.txt +0 -0
- {btgsolutions_dataservices_python_client-3.2.8 → btgsolutions_dataservices_python_client-3.2.10}/setup.cfg +0 -0
- {btgsolutions_dataservices_python_client-3.2.8 → btgsolutions_dataservices_python_client-3.2.10}/setup.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: btgsolutions_dataservices_python_client
|
|
3
|
-
Version: 3.2.
|
|
3
|
+
Version: 3.2.10
|
|
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
|
|
@@ -12,6 +12,14 @@ Requires-Dist: websocket-client>=1.8.0
|
|
|
12
12
|
Requires-Dist: PyJWT>=2.8.0
|
|
13
13
|
Requires-Dist: requests>=2.32.3
|
|
14
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
|
|
15
23
|
|
|
16
24
|
# BTG Solutions - Data Services
|
|
17
25
|
|
|
@@ -171,6 +179,30 @@ ws.run(on_message=lambda message: print(message))
|
|
|
171
179
|
# sleep(1)
|
|
172
180
|
```
|
|
173
181
|
|
|
182
|
+
##### Broker Analytics
|
|
183
|
+
|
|
184
|
+
```python
|
|
185
|
+
import btgsolutions_dataservices as btg
|
|
186
|
+
|
|
187
|
+
ws = btg.BrokerAnalyticsWebSocketClient(api_key='YOUR_API_KEY')
|
|
188
|
+
ws.run(on_message=lambda message: print(message))
|
|
189
|
+
|
|
190
|
+
ws.available_tickers()
|
|
191
|
+
ws.available_brokers()
|
|
192
|
+
ws.subscribe_top_tickers(n=10, brokers=['85'])
|
|
193
|
+
ws.subscribe_top_brokers(n=5, tickers=['SNFF11'])
|
|
194
|
+
ws.subscribed_to()
|
|
195
|
+
ws.get_last_event(analytics_type='top_tickers', n=3, brokers=['85', '3'])
|
|
196
|
+
ws.get_last_event(analytics_type='top_brokers', n=100, tickers=['SNFF11'])
|
|
197
|
+
ws.unsubscribe_top_tickers(brokers=['85'])
|
|
198
|
+
ws.unsubscribe_top_brokers(tickers=['SNFF11'])
|
|
199
|
+
|
|
200
|
+
## The following is optional to keep the program running in a .py file:
|
|
201
|
+
# from time import sleep
|
|
202
|
+
# while True:
|
|
203
|
+
# sleep(1)
|
|
204
|
+
```
|
|
205
|
+
|
|
174
206
|
#### Intraday Candles
|
|
175
207
|
|
|
176
208
|
```python
|
|
@@ -156,6 +156,30 @@ ws.run(on_message=lambda message: print(message))
|
|
|
156
156
|
# sleep(1)
|
|
157
157
|
```
|
|
158
158
|
|
|
159
|
+
##### Broker Analytics
|
|
160
|
+
|
|
161
|
+
```python
|
|
162
|
+
import btgsolutions_dataservices as btg
|
|
163
|
+
|
|
164
|
+
ws = btg.BrokerAnalyticsWebSocketClient(api_key='YOUR_API_KEY')
|
|
165
|
+
ws.run(on_message=lambda message: print(message))
|
|
166
|
+
|
|
167
|
+
ws.available_tickers()
|
|
168
|
+
ws.available_brokers()
|
|
169
|
+
ws.subscribe_top_tickers(n=10, brokers=['85'])
|
|
170
|
+
ws.subscribe_top_brokers(n=5, tickers=['SNFF11'])
|
|
171
|
+
ws.subscribed_to()
|
|
172
|
+
ws.get_last_event(analytics_type='top_tickers', n=3, brokers=['85', '3'])
|
|
173
|
+
ws.get_last_event(analytics_type='top_brokers', n=100, tickers=['SNFF11'])
|
|
174
|
+
ws.unsubscribe_top_tickers(brokers=['85'])
|
|
175
|
+
ws.unsubscribe_top_brokers(tickers=['SNFF11'])
|
|
176
|
+
|
|
177
|
+
## The following is optional to keep the program running in a .py file:
|
|
178
|
+
# from time import sleep
|
|
179
|
+
# while True:
|
|
180
|
+
# sleep(1)
|
|
181
|
+
```
|
|
182
|
+
|
|
159
183
|
#### Intraday Candles
|
|
160
184
|
|
|
161
185
|
```python
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from .intraday_candles import IntradayCandles
|
|
2
2
|
from .historical_candles import HistoricalCandles
|
|
3
|
+
from .historical_candles_crypto import HistoricalCandlesCrypto
|
|
3
4
|
from .authenticator import Authenticator
|
|
4
5
|
from .bulk_data import BulkData
|
|
5
6
|
from .hfn import HighFrequencyNews
|
|
@@ -98,6 +98,8 @@ class HistoricalCandles:
|
|
|
98
98
|
Field is not required. Default: False.
|
|
99
99
|
round: bool
|
|
100
100
|
Apply rounding to prices.
|
|
101
|
+
Useful when corporate_events_adj=True, since price adjustment factors
|
|
102
|
+
may generate values with many decimal places.
|
|
101
103
|
Field is not required. Default: True.
|
|
102
104
|
"""
|
|
103
105
|
|
|
@@ -155,6 +157,8 @@ class HistoricalCandles:
|
|
|
155
157
|
Field is not required. Default: False.
|
|
156
158
|
round: bool
|
|
157
159
|
Apply rounding to prices.
|
|
160
|
+
Useful when corporate_events_adj=True, since price adjustment factors
|
|
161
|
+
may generate values with many decimal places.
|
|
158
162
|
Field is not required. Default: True.
|
|
159
163
|
"""
|
|
160
164
|
|
|
@@ -43,7 +43,7 @@ class Quotes:
|
|
|
43
43
|
self.token = Authenticator(self.api_key).token
|
|
44
44
|
self.headers = {"authorization": f"authorization {self.token}"}
|
|
45
45
|
|
|
46
|
-
self.available_market_types = ['stocks', 'options', 'derivatives']
|
|
46
|
+
self.available_market_types = ['stocks', 'options', 'derivatives', 'indices']
|
|
47
47
|
self.available_modes = ['realtime', 'delayed']
|
|
48
48
|
self.available_variations = ['intraday', 'interday']
|
|
49
49
|
|
|
@@ -64,7 +64,7 @@ class Quotes:
|
|
|
64
64
|
Field is required. Example: ['VALE3'], ['PETR4', 'PRIO3'].
|
|
65
65
|
market_type: str
|
|
66
66
|
Market type.
|
|
67
|
-
Field is required. Example: 'stocks', 'options', 'derivatives'.
|
|
67
|
+
Field is required. Example: 'stocks', 'options', 'derivatives', 'indices'.
|
|
68
68
|
mode: str
|
|
69
69
|
Realtime or 15-minutes delayed.
|
|
70
70
|
Field is required. Example: 'realtime' or 'delayed'.
|
|
@@ -111,7 +111,7 @@ class Quotes:
|
|
|
111
111
|
----------------
|
|
112
112
|
market_type: str
|
|
113
113
|
Market type.
|
|
114
|
-
Field is required. Example: 'stocks', 'options', 'derivatives'.
|
|
114
|
+
Field is required. Example: 'stocks', 'options', 'derivatives', 'indices'.
|
|
115
115
|
mode: str
|
|
116
116
|
Realtime or 15-minutes delayed.
|
|
117
117
|
Field is not required. Example: 'realtime' or 'delayed'.
|
|
@@ -172,7 +172,7 @@ class Quotes:
|
|
|
172
172
|
----------------
|
|
173
173
|
market_type: str
|
|
174
174
|
Market type.
|
|
175
|
-
Field is required. Example: 'stocks', 'options', 'derivatives'.
|
|
175
|
+
Field is required. Example: 'stocks', 'options', 'derivatives', 'indices'.
|
|
176
176
|
mode: str
|
|
177
177
|
Realtime or 15-minutes delayed.
|
|
178
178
|
Field is not required. Example: 'realtime' or 'delayed'.
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
from .market_data_websocket_client import MarketDataWebSocketClient
|
|
2
2
|
from .hfn_websocket_client import HFNWebSocketClient
|
|
3
|
-
from .market_data_feed import MarketDataFeed
|
|
3
|
+
from .market_data_feed import MarketDataFeed
|
|
4
|
+
from .broker_analytics import BrokerAnalyticsWebSocketClient
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
from typing import Optional, List
|
|
2
|
+
from ..exceptions import WSTypeError
|
|
3
|
+
from ..rest import Authenticator
|
|
4
|
+
from ..config import broker_analytics_socket_urls, MAX_WS_RECONNECT_RETRIES, REALTIME, BR
|
|
5
|
+
from .websocket_default_functions import _on_open, _on_message, _on_error, _on_close
|
|
6
|
+
import websocket
|
|
7
|
+
import json
|
|
8
|
+
import ssl
|
|
9
|
+
import threading
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class BrokerAnalyticsWebSocketClient:
|
|
13
|
+
"""
|
|
14
|
+
This class connects with BTG Solutions Data Services Broker Analytics WebSocket,
|
|
15
|
+
receiving broker analytics events (top tickers by broker and top brokers by ticker).
|
|
16
|
+
|
|
17
|
+
* Main use case:
|
|
18
|
+
|
|
19
|
+
>>> from btgsolutions_dataservices import BrokerAnalyticsWebSocketClient
|
|
20
|
+
>>> ws = BrokerAnalyticsWebSocketClient(
|
|
21
|
+
>>> api_key='YOUR_API_KEY',
|
|
22
|
+
>>> ssl=True
|
|
23
|
+
>>> )
|
|
24
|
+
>>> ws.run()
|
|
25
|
+
>>> ws.available_tickers()
|
|
26
|
+
>>> ws.available_brokers()
|
|
27
|
+
>>> ws.subscribe_top_tickers(n=10, brokers=['85'])
|
|
28
|
+
>>> ws.subscribe_top_brokers(n=5)
|
|
29
|
+
>>> ws.subscribed_to()
|
|
30
|
+
>>> ws.get_last_event(analytics_type='top_tickers', n=3, brokers=['85', '3'])
|
|
31
|
+
>>> ws.get_last_event(analytics_type='top_brokers', n=5)
|
|
32
|
+
>>> ws.unsubscribe_top_tickers(brokers=['85'])
|
|
33
|
+
>>> ws.unsubscribe_top_brokers()
|
|
34
|
+
>>> ws.close()
|
|
35
|
+
|
|
36
|
+
Parameters
|
|
37
|
+
----------------
|
|
38
|
+
api_key: str
|
|
39
|
+
User identification key.
|
|
40
|
+
Field is required.
|
|
41
|
+
|
|
42
|
+
ssl: bool
|
|
43
|
+
Enable or disable ssl configuration.
|
|
44
|
+
Field is not required. Default: True (enable).
|
|
45
|
+
"""
|
|
46
|
+
|
|
47
|
+
def __init__(
|
|
48
|
+
self,
|
|
49
|
+
api_key: str,
|
|
50
|
+
ssl: Optional[bool] = True,
|
|
51
|
+
**kwargs,
|
|
52
|
+
):
|
|
53
|
+
self.api_key = api_key
|
|
54
|
+
self.ssl = ssl
|
|
55
|
+
|
|
56
|
+
self.__authenticator = Authenticator(self.api_key)
|
|
57
|
+
self.__nro_reconnect_retries = 0
|
|
58
|
+
|
|
59
|
+
try:
|
|
60
|
+
self.url = broker_analytics_socket_urls[BR][REALTIME]
|
|
61
|
+
except Exception:
|
|
62
|
+
raise WSTypeError(
|
|
63
|
+
"There is no WebSocket type for Broker Analytics (brazil/realtime).\nPlease check your request parameters and try again"
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
self.websocket_cfg = kwargs
|
|
67
|
+
|
|
68
|
+
def run(
|
|
69
|
+
self,
|
|
70
|
+
on_open=None,
|
|
71
|
+
on_message=None,
|
|
72
|
+
on_error=None,
|
|
73
|
+
on_close=None,
|
|
74
|
+
reconnect=True
|
|
75
|
+
):
|
|
76
|
+
"""
|
|
77
|
+
Initializes a connection to websocket and starts to receive Broker Analytics events.
|
|
78
|
+
|
|
79
|
+
Parameters
|
|
80
|
+
----------
|
|
81
|
+
on_open: function
|
|
82
|
+
- Called at opening connection to websocket.
|
|
83
|
+
- Field is not required.
|
|
84
|
+
- Default: prints that the connection was opened in case of success.
|
|
85
|
+
|
|
86
|
+
on_message: function
|
|
87
|
+
- Called every time it receives a message.
|
|
88
|
+
- Arguments:
|
|
89
|
+
1. Data received from the server.
|
|
90
|
+
- Field is not required.
|
|
91
|
+
- Default: prints the data.
|
|
92
|
+
|
|
93
|
+
on_error: function
|
|
94
|
+
- Called when a error occurs.
|
|
95
|
+
- Arguments:
|
|
96
|
+
1. Exception object.
|
|
97
|
+
- Field is not required.
|
|
98
|
+
- Default: prints the error.
|
|
99
|
+
|
|
100
|
+
on_close: function
|
|
101
|
+
- Called when connection is closed.
|
|
102
|
+
- Arguments:
|
|
103
|
+
1. close_status_code.
|
|
104
|
+
2. close_msg.
|
|
105
|
+
- Field is not required.
|
|
106
|
+
- Default: prints a message that the connection was closed.
|
|
107
|
+
|
|
108
|
+
reconnect: bool
|
|
109
|
+
Try reconnect if connection is closed.
|
|
110
|
+
Field is not required.
|
|
111
|
+
Default: True.
|
|
112
|
+
"""
|
|
113
|
+
if on_open is None:
|
|
114
|
+
on_open = _on_open
|
|
115
|
+
if on_message is None:
|
|
116
|
+
on_message = _on_message
|
|
117
|
+
if on_error is None:
|
|
118
|
+
on_error = _on_error
|
|
119
|
+
if on_close is None:
|
|
120
|
+
on_close = _on_close
|
|
121
|
+
|
|
122
|
+
def intermediary_on_open(ws):
|
|
123
|
+
on_open()
|
|
124
|
+
self.__nro_reconnect_retries = 0
|
|
125
|
+
|
|
126
|
+
def intermediary_on_message(ws, data):
|
|
127
|
+
on_message(data)
|
|
128
|
+
|
|
129
|
+
def intermediary_on_error(ws, error):
|
|
130
|
+
on_error(error)
|
|
131
|
+
|
|
132
|
+
def intermediary_on_close(ws, close_status_code, close_msg):
|
|
133
|
+
on_close(close_status_code, close_msg)
|
|
134
|
+
|
|
135
|
+
if reconnect:
|
|
136
|
+
if self.__nro_reconnect_retries == MAX_WS_RECONNECT_RETRIES:
|
|
137
|
+
print("### Fail retriyng reconnect")
|
|
138
|
+
return
|
|
139
|
+
self.__nro_reconnect_retries += 1
|
|
140
|
+
print(f"### Reconnecting.... Attempts: {self.__nro_reconnect_retries}/{MAX_WS_RECONNECT_RETRIES}")
|
|
141
|
+
self.run(on_open, on_message, on_error, on_close, reconnect)
|
|
142
|
+
|
|
143
|
+
self.ws = websocket.WebSocketApp(
|
|
144
|
+
url=self.url,
|
|
145
|
+
on_open=intermediary_on_open,
|
|
146
|
+
on_message=intermediary_on_message,
|
|
147
|
+
on_error=intermediary_on_error,
|
|
148
|
+
on_close=intermediary_on_close,
|
|
149
|
+
header={
|
|
150
|
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.54 Safari/537.36",
|
|
151
|
+
"Sec-WebSocket-Protocol": self.__authenticator.token,
|
|
152
|
+
}
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
ssl_conf = {} if self.ssl else {"sslopt": {"cert_reqs": ssl.CERT_NONE}}
|
|
156
|
+
wst = threading.Thread(target=self.ws.run_forever, kwargs=ssl_conf)
|
|
157
|
+
wst.daemon = True
|
|
158
|
+
wst.start()
|
|
159
|
+
|
|
160
|
+
while True:
|
|
161
|
+
if self.ws.sock is not None and self.ws.sock.connected:
|
|
162
|
+
break
|
|
163
|
+
pass
|
|
164
|
+
|
|
165
|
+
def __send(self, data):
|
|
166
|
+
if not isinstance(data, str):
|
|
167
|
+
data = json.dumps(data)
|
|
168
|
+
print(f"Sending data: {data}")
|
|
169
|
+
return self.ws.send(data)
|
|
170
|
+
|
|
171
|
+
def close(self):
|
|
172
|
+
"""
|
|
173
|
+
Closes connection with websocket.
|
|
174
|
+
"""
|
|
175
|
+
self.ws.close()
|
|
176
|
+
|
|
177
|
+
def subscribe_top_tickers(self, n: int = 10, brokers: Optional[List[str]] = None):
|
|
178
|
+
"""
|
|
179
|
+
Subscribes to top tickers by broker.
|
|
180
|
+
|
|
181
|
+
Parameters
|
|
182
|
+
----------
|
|
183
|
+
n: int
|
|
184
|
+
Number of results.
|
|
185
|
+
Field is not required. Default: 10.
|
|
186
|
+
|
|
187
|
+
brokers: list
|
|
188
|
+
Broker ids filter.
|
|
189
|
+
Field is not required.
|
|
190
|
+
"""
|
|
191
|
+
params = {'type': 'top_tickers', 'n': n}
|
|
192
|
+
if brokers is not None:
|
|
193
|
+
params['brokers'] = brokers
|
|
194
|
+
self.__send({'action': 'subscribe', 'params': params})
|
|
195
|
+
|
|
196
|
+
def subscribe_top_brokers(self, n: int = 5, tickers: Optional[List[str]] = None):
|
|
197
|
+
"""
|
|
198
|
+
Subscribes to top brokers by ticker.
|
|
199
|
+
|
|
200
|
+
Parameters
|
|
201
|
+
----------
|
|
202
|
+
n: int
|
|
203
|
+
Number of results.
|
|
204
|
+
Field is not required. Default: 5.
|
|
205
|
+
tickers: list
|
|
206
|
+
Ticker symbols filter.
|
|
207
|
+
Field is not required.
|
|
208
|
+
"""
|
|
209
|
+
params = {'type': 'top_brokers', 'n': n}
|
|
210
|
+
if tickers is not None:
|
|
211
|
+
params['tickers'] = tickers
|
|
212
|
+
self.__send({'action': 'subscribe', 'params': params})
|
|
213
|
+
|
|
214
|
+
def unsubscribe_top_tickers(self, brokers: Optional[List[str]] = None):
|
|
215
|
+
"""
|
|
216
|
+
Unsubscribes from top tickers by broker.
|
|
217
|
+
|
|
218
|
+
Parameters
|
|
219
|
+
----------
|
|
220
|
+
brokers: list
|
|
221
|
+
Broker ids filter.
|
|
222
|
+
Field is not required.
|
|
223
|
+
"""
|
|
224
|
+
params = {'type': 'top_tickers'}
|
|
225
|
+
if brokers is not None:
|
|
226
|
+
params['brokers'] = brokers
|
|
227
|
+
self.__send({'action': 'unsubscribe', 'params': params})
|
|
228
|
+
|
|
229
|
+
def unsubscribe_top_brokers(self, tickers: Optional[List[str]] = None):
|
|
230
|
+
"""
|
|
231
|
+
Unsubscribes from top brokers by ticker.
|
|
232
|
+
|
|
233
|
+
Parameters
|
|
234
|
+
----------
|
|
235
|
+
tickers: list
|
|
236
|
+
Ticker symbols filter.
|
|
237
|
+
Field is not required.
|
|
238
|
+
"""
|
|
239
|
+
params = {'type': 'top_brokers'}
|
|
240
|
+
if tickers is not None:
|
|
241
|
+
params['tickers'] = tickers
|
|
242
|
+
self.__send({'action': 'unsubscribe', 'params': params})
|
|
243
|
+
|
|
244
|
+
def get_last_event(
|
|
245
|
+
self,
|
|
246
|
+
analytics_type: Optional[str] = None,
|
|
247
|
+
n: Optional[int] = None,
|
|
248
|
+
brokers: Optional[List[str]] = None,
|
|
249
|
+
tickers: Optional[List[str]] = None,
|
|
250
|
+
):
|
|
251
|
+
"""
|
|
252
|
+
Returns latest broker analytics event.
|
|
253
|
+
|
|
254
|
+
Parameters
|
|
255
|
+
----------
|
|
256
|
+
analytics_type: str
|
|
257
|
+
Analytics type.
|
|
258
|
+
Options: 'top_tickers' or 'top_brokers'.
|
|
259
|
+
Field is not required.
|
|
260
|
+
|
|
261
|
+
n: int
|
|
262
|
+
Number of results.
|
|
263
|
+
Field is not required.
|
|
264
|
+
|
|
265
|
+
brokers: list
|
|
266
|
+
Broker ids filter.
|
|
267
|
+
Field is not required.
|
|
268
|
+
tickers: list
|
|
269
|
+
Ticker symbols filter.
|
|
270
|
+
Field is not required.
|
|
271
|
+
"""
|
|
272
|
+
payload = {'action': 'get_last_event'}
|
|
273
|
+
if analytics_type is not None:
|
|
274
|
+
params = {'type': analytics_type}
|
|
275
|
+
if n is not None:
|
|
276
|
+
params['n'] = n
|
|
277
|
+
if brokers is not None:
|
|
278
|
+
params['brokers'] = brokers
|
|
279
|
+
if tickers is not None:
|
|
280
|
+
params['tickers'] = tickers
|
|
281
|
+
payload['params'] = params
|
|
282
|
+
self.__send(payload)
|
|
283
|
+
|
|
284
|
+
def subscribed_to(self):
|
|
285
|
+
"""
|
|
286
|
+
Returns current subscriptions.
|
|
287
|
+
"""
|
|
288
|
+
self.__send({'action': 'subscribed_to'})
|
|
289
|
+
|
|
290
|
+
def available_tickers(self):
|
|
291
|
+
"""
|
|
292
|
+
Returns available tickers.
|
|
293
|
+
"""
|
|
294
|
+
self.__send({'action': 'available_tickers'})
|
|
295
|
+
|
|
296
|
+
def available_brokers(self):
|
|
297
|
+
"""
|
|
298
|
+
Returns available brokers.
|
|
299
|
+
"""
|
|
300
|
+
self.__send({'action': 'available_brokers'})
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: btgsolutions_dataservices_python_client
|
|
3
|
-
Version: 3.2.
|
|
3
|
+
Version: 3.2.10
|
|
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
|
|
@@ -12,6 +12,14 @@ Requires-Dist: websocket-client>=1.8.0
|
|
|
12
12
|
Requires-Dist: PyJWT>=2.8.0
|
|
13
13
|
Requires-Dist: requests>=2.32.3
|
|
14
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
|
|
15
23
|
|
|
16
24
|
# BTG Solutions - Data Services
|
|
17
25
|
|
|
@@ -171,6 +179,30 @@ ws.run(on_message=lambda message: print(message))
|
|
|
171
179
|
# sleep(1)
|
|
172
180
|
```
|
|
173
181
|
|
|
182
|
+
##### Broker Analytics
|
|
183
|
+
|
|
184
|
+
```python
|
|
185
|
+
import btgsolutions_dataservices as btg
|
|
186
|
+
|
|
187
|
+
ws = btg.BrokerAnalyticsWebSocketClient(api_key='YOUR_API_KEY')
|
|
188
|
+
ws.run(on_message=lambda message: print(message))
|
|
189
|
+
|
|
190
|
+
ws.available_tickers()
|
|
191
|
+
ws.available_brokers()
|
|
192
|
+
ws.subscribe_top_tickers(n=10, brokers=['85'])
|
|
193
|
+
ws.subscribe_top_brokers(n=5, tickers=['SNFF11'])
|
|
194
|
+
ws.subscribed_to()
|
|
195
|
+
ws.get_last_event(analytics_type='top_tickers', n=3, brokers=['85', '3'])
|
|
196
|
+
ws.get_last_event(analytics_type='top_brokers', n=100, tickers=['SNFF11'])
|
|
197
|
+
ws.unsubscribe_top_tickers(brokers=['85'])
|
|
198
|
+
ws.unsubscribe_top_brokers(tickers=['SNFF11'])
|
|
199
|
+
|
|
200
|
+
## The following is optional to keep the program running in a .py file:
|
|
201
|
+
# from time import sleep
|
|
202
|
+
# while True:
|
|
203
|
+
# sleep(1)
|
|
204
|
+
```
|
|
205
|
+
|
|
174
206
|
#### Intraday Candles
|
|
175
207
|
|
|
176
208
|
```python
|
|
@@ -25,6 +25,7 @@ btgsolutions_dataservices/rest/stock_loan.py
|
|
|
25
25
|
btgsolutions_dataservices/rest/ticker_last_event.py
|
|
26
26
|
btgsolutions_dataservices/rest/ticker_last_event_polling.py
|
|
27
27
|
btgsolutions_dataservices/websocket/__init__.py
|
|
28
|
+
btgsolutions_dataservices/websocket/broker_analytics.py
|
|
28
29
|
btgsolutions_dataservices/websocket/hfn_websocket_client.py
|
|
29
30
|
btgsolutions_dataservices/websocket/market_data_feed.py
|
|
30
31
|
btgsolutions_dataservices/websocket/market_data_websocket_client.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
|
|
File without changes
|
|
File without changes
|