btgsolutions-dataservices-python-client 2.14.1__tar.gz → 2.16.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.
Files changed (35) hide show
  1. {btgsolutions_dataservices_python_client-2.14.1/btgsolutions_dataservices_python_client.egg-info → btgsolutions_dataservices_python_client-2.16.0}/PKG-INFO +27 -2
  2. {btgsolutions_dataservices_python_client-2.14.1 → btgsolutions_dataservices_python_client-2.16.0}/README.md +25 -0
  3. {btgsolutions_dataservices_python_client-2.14.1 → btgsolutions_dataservices_python_client-2.16.0}/btgsolutions_dataservices/config.py +8 -1
  4. {btgsolutions_dataservices_python_client-2.14.1 → btgsolutions_dataservices_python_client-2.16.0}/btgsolutions_dataservices/rest/__init__.py +2 -1
  5. {btgsolutions_dataservices_python_client-2.14.1 → btgsolutions_dataservices_python_client-2.16.0}/btgsolutions_dataservices/rest/intraday_candles.py +10 -1
  6. btgsolutions_dataservices_python_client-2.16.0/btgsolutions_dataservices/rest/stock_loan.py +110 -0
  7. {btgsolutions_dataservices_python_client-2.14.1 → btgsolutions_dataservices_python_client-2.16.0}/btgsolutions_dataservices/websocket/market_data_feed.py +1 -1
  8. {btgsolutions_dataservices_python_client-2.14.1 → btgsolutions_dataservices_python_client-2.16.0}/btgsolutions_dataservices/websocket/market_data_websocket_client.py +3 -3
  9. {btgsolutions_dataservices_python_client-2.14.1 → btgsolutions_dataservices_python_client-2.16.0/btgsolutions_dataservices_python_client.egg-info}/PKG-INFO +27 -2
  10. {btgsolutions_dataservices_python_client-2.14.1 → btgsolutions_dataservices_python_client-2.16.0}/btgsolutions_dataservices_python_client.egg-info/SOURCES.txt +1 -0
  11. {btgsolutions_dataservices_python_client-2.14.1 → btgsolutions_dataservices_python_client-2.16.0}/setup.py +2 -2
  12. {btgsolutions_dataservices_python_client-2.14.1 → btgsolutions_dataservices_python_client-2.16.0}/LICENSE +0 -0
  13. {btgsolutions_dataservices_python_client-2.14.1 → btgsolutions_dataservices_python_client-2.16.0}/MANIFEST.in +0 -0
  14. {btgsolutions_dataservices_python_client-2.14.1 → btgsolutions_dataservices_python_client-2.16.0}/btgsolutions_dataservices/__init__.py +0 -0
  15. {btgsolutions_dataservices_python_client-2.14.1 → btgsolutions_dataservices_python_client-2.16.0}/btgsolutions_dataservices/exceptions.py +0 -0
  16. {btgsolutions_dataservices_python_client-2.14.1 → btgsolutions_dataservices_python_client-2.16.0}/btgsolutions_dataservices/rest/authenticator.py +0 -0
  17. {btgsolutions_dataservices_python_client-2.14.1 → btgsolutions_dataservices_python_client-2.16.0}/btgsolutions_dataservices/rest/bulk_data.py +0 -0
  18. {btgsolutions_dataservices_python_client-2.14.1 → btgsolutions_dataservices_python_client-2.16.0}/btgsolutions_dataservices/rest/company_data.py +0 -0
  19. {btgsolutions_dataservices_python_client-2.14.1 → btgsolutions_dataservices_python_client-2.16.0}/btgsolutions_dataservices/rest/corporate_events.py +0 -0
  20. {btgsolutions_dataservices_python_client-2.14.1 → btgsolutions_dataservices_python_client-2.16.0}/btgsolutions_dataservices/rest/hfn.py +0 -0
  21. {btgsolutions_dataservices_python_client-2.14.1 → btgsolutions_dataservices_python_client-2.16.0}/btgsolutions_dataservices/rest/historical_candles.py +0 -0
  22. {btgsolutions_dataservices_python_client-2.14.1 → btgsolutions_dataservices_python_client-2.16.0}/btgsolutions_dataservices/rest/intraday_tick_data.py +0 -0
  23. {btgsolutions_dataservices_python_client-2.14.1 → btgsolutions_dataservices_python_client-2.16.0}/btgsolutions_dataservices/rest/public_sources.py +0 -0
  24. {btgsolutions_dataservices_python_client-2.14.1 → btgsolutions_dataservices_python_client-2.16.0}/btgsolutions_dataservices/rest/quotes.py +0 -0
  25. {btgsolutions_dataservices_python_client-2.14.1 → btgsolutions_dataservices_python_client-2.16.0}/btgsolutions_dataservices/rest/reference_data.py +0 -0
  26. {btgsolutions_dataservices_python_client-2.14.1 → btgsolutions_dataservices_python_client-2.16.0}/btgsolutions_dataservices/rest/ticker_last_event.py +0 -0
  27. {btgsolutions_dataservices_python_client-2.14.1 → btgsolutions_dataservices_python_client-2.16.0}/btgsolutions_dataservices/websocket/__init__.py +0 -0
  28. {btgsolutions_dataservices_python_client-2.14.1 → btgsolutions_dataservices_python_client-2.16.0}/btgsolutions_dataservices/websocket/hfn_websocket_client.py +0 -0
  29. {btgsolutions_dataservices_python_client-2.14.1 → btgsolutions_dataservices_python_client-2.16.0}/btgsolutions_dataservices/websocket/websocket_default_functions.py +0 -0
  30. {btgsolutions_dataservices_python_client-2.14.1 → btgsolutions_dataservices_python_client-2.16.0}/btgsolutions_dataservices_python_client.egg-info/dependency_links.txt +0 -0
  31. {btgsolutions_dataservices_python_client-2.14.1 → btgsolutions_dataservices_python_client-2.16.0}/btgsolutions_dataservices_python_client.egg-info/requires.txt +0 -0
  32. {btgsolutions_dataservices_python_client-2.14.1 → btgsolutions_dataservices_python_client-2.16.0}/btgsolutions_dataservices_python_client.egg-info/top_level.txt +0 -0
  33. {btgsolutions_dataservices_python_client-2.14.1 → btgsolutions_dataservices_python_client-2.16.0}/pyproject.toml +0 -0
  34. {btgsolutions_dataservices_python_client-2.14.1 → btgsolutions_dataservices_python_client-2.16.0}/requirements.txt +0 -0
  35. {btgsolutions_dataservices_python_client-2.14.1 → btgsolutions_dataservices_python_client-2.16.0}/setup.cfg +0 -0
@@ -1,10 +1,10 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: btgsolutions-dataservices-python-client
3
- Version: 2.14.1
3
+ Version: 2.16.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
- Requires-Python: >=3.9,<3.13
7
+ Requires-Python: >=3.9,<3.14
8
8
  Description-Content-Type: text/markdown
9
9
  License-File: LICENSE
10
10
  Requires-Dist: pandas>=2.2.2
@@ -170,6 +170,21 @@ ws.run(on_message=lambda message: print(message))
170
170
  ws.instrument_status('PETR4')
171
171
  ws.instrument_status_history('PETR4')
172
172
 
173
+ ## The following is optional to keep the program running in a .py file:
174
+ # from time import sleep
175
+ # while True:
176
+ # sleep(1)
177
+ ```
178
+ ##### Settlement Price
179
+
180
+ ```python
181
+ import btgsolutions_dataservices as btg
182
+ ws = btg.MarketDataWebSocketClient(api_key='YOUR_API_KEY', data_type='settlement-price', instruments=['ABEVOU25', 'WINV25'])
183
+ ws.run(on_message=lambda message: print(message))
184
+
185
+ ## Getting the last event (settlement-price) of ABEVOU25:
186
+ # ws.get_last_event(['ABEVOU25'])
187
+
173
188
  ## The following is optional to keep the program running in a .py file:
174
189
  # from time import sleep
175
190
  # while True:
@@ -352,6 +367,16 @@ public_sources = btg.PublicSources(api_key='YOUR_API_KEY')
352
367
  public_sources.get_opas(start_date='2022-10-01', end_date='2024-10-01')
353
368
  ```
354
369
 
370
+ #### STOCK LOAN
371
+
372
+ ```python
373
+ import btgsolutions_dataservices as btg
374
+ stock_loan = btg.StockLoan(api_key='YOUR_API_KEY')
375
+ stock_loan.get_trades()
376
+ stock_loan.get_paginated_trades(page=1, limit=1000, ticker ='PETR4')
377
+ stock_loan.get_available_tickers()
378
+ ```
379
+
355
380
  #### Company Fundamentals
356
381
 
357
382
  ##### Company General Information
@@ -147,6 +147,21 @@ ws.run(on_message=lambda message: print(message))
147
147
  ws.instrument_status('PETR4')
148
148
  ws.instrument_status_history('PETR4')
149
149
 
150
+ ## The following is optional to keep the program running in a .py file:
151
+ # from time import sleep
152
+ # while True:
153
+ # sleep(1)
154
+ ```
155
+ ##### Settlement Price
156
+
157
+ ```python
158
+ import btgsolutions_dataservices as btg
159
+ ws = btg.MarketDataWebSocketClient(api_key='YOUR_API_KEY', data_type='settlement-price', instruments=['ABEVOU25', 'WINV25'])
160
+ ws.run(on_message=lambda message: print(message))
161
+
162
+ ## Getting the last event (settlement-price) of ABEVOU25:
163
+ # ws.get_last_event(['ABEVOU25'])
164
+
150
165
  ## The following is optional to keep the program running in a .py file:
151
166
  # from time import sleep
152
167
  # while True:
@@ -329,6 +344,16 @@ public_sources = btg.PublicSources(api_key='YOUR_API_KEY')
329
344
  public_sources.get_opas(start_date='2022-10-01', end_date='2024-10-01')
330
345
  ```
331
346
 
347
+ #### STOCK LOAN
348
+
349
+ ```python
350
+ import btgsolutions_dataservices as btg
351
+ stock_loan = btg.StockLoan(api_key='YOUR_API_KEY')
352
+ stock_loan.get_trades()
353
+ stock_loan.get_paginated_trades(page=1, limit=1000, ticker ='PETR4')
354
+ stock_loan.get_available_tickers()
355
+ ```
356
+
332
357
  #### Company Fundamentals
333
358
 
334
359
  ##### Company General Information
@@ -26,6 +26,7 @@ SECURITIES = 'securities'
26
26
  TRADES = 'trades'
27
27
  PROCESSEDTRADES = 'processed-trades'
28
28
  INSTRUMENTSTATUS = 'instrument_status'
29
+ SETTLEMENTPRICES = 'settlement-price'
29
30
  BOOKS = 'books'
30
31
  INDICES = 'indices'
31
32
  CANDLES1S = 'candles-1S'
@@ -49,7 +50,8 @@ VALID_MARKET_DATA_TYPES = [
49
50
  CANDLES1S,
50
51
  CANDLES1M,
51
52
  STOPLOSS,
52
- INSTRUMENTSTATUS
53
+ INSTRUMENTSTATUS,
54
+ SETTLEMENTPRICES
53
55
  ]
54
56
  VALID_MARKET_DATA_SUBTYPES = [ALL, STOCKS, OPTIONS, DERIVATIVES]
55
57
 
@@ -134,6 +136,11 @@ market_data_socket_urls = {
134
136
  DERIVATIVES: f"{url_ws}v2/marketdata/{INSTRUMENTSTATUS}/{DERIVATIVES}",
135
137
  OPTIONS: f"{url_ws}v2/marketdata/{INSTRUMENTSTATUS}/{OPTIONS}",
136
138
  }
139
+ },
140
+ SETTLEMENTPRICES: {
141
+ REALTIME: {
142
+ ALL: f"{url_ws}v2/marketdata/{SETTLEMENTPRICES}",
143
+ }
137
144
  }
138
145
  },
139
146
  BMV: {
@@ -9,4 +9,5 @@ from .ticker_last_event import TickerLastEvent
9
9
  from .corporate_events import CorporateEvents
10
10
  from .company_data import CompanyData
11
11
  from .public_sources import PublicSources
12
- from .reference_data import ReferenceData
12
+ from .reference_data import ReferenceData
13
+ from .stock_loan import StockLoan
@@ -58,7 +58,8 @@ class IntradayCandles:
58
58
  start:int=0,
59
59
  end:int=0,
60
60
  mode:str='absolute',
61
- raw_data:bool=False
61
+ raw_data:bool=False,
62
+ cross_filter:str='',
62
63
  ):
63
64
  """
64
65
  This method provides realtime intraday candles for a given ticker.
@@ -93,6 +94,10 @@ class IntradayCandles:
93
94
  Candle mode.
94
95
  Example: 'absolute', 'relative' or 'spark'.
95
96
  Default: absolute.
97
+ cross_filter: str
98
+ Filter trades by cross status. Available only when market_type is derivatives.
99
+ Options: 'all', 'only_cross' or 'without_cross'.
100
+ Default: 'all'.
96
101
  raw_data: bool
97
102
  If false, returns data in a dict of dataframes. If true, returns raw data.
98
103
  Default: False.
@@ -101,6 +106,8 @@ class IntradayCandles:
101
106
  if market_type not in ['stocks', 'derivatives', 'options', 'indices']: raise MarketTypeError(f"Must provide a valid 'market_type' parameter. Input: '{market_type}'. Accepted values: 'stocks', 'derivatives', 'options' or 'indices'.")
102
107
 
103
108
  if delay not in ['delayed', 'realtime']: raise DelayError(f"Must provide a valid 'delay' parameter. Input: '{delay}'. Accepted values: 'delayed' or 'realtime'.")
109
+
110
+ if cross_filter and market_type != 'derivatives': raise DelayError(f"The 'cross_filter' flag is only valid for market_type 'derivatives'.")
104
111
 
105
112
  tickers = ','.join(tickers) if type(tickers) is list else tickers
106
113
 
@@ -109,6 +116,8 @@ class IntradayCandles:
109
116
  if start: url += f'&start={start}'
110
117
 
111
118
  if end: url += f'&end={end}'
119
+
120
+ if cross_filter: url += f'&cross_filter={cross_filter}'
112
121
 
113
122
  response = requests.request("GET", url, headers=self.headers)
114
123
  if response.status_code == 200:
@@ -0,0 +1,110 @@
1
+
2
+ from typing import Optional
3
+ from ..exceptions import BadResponse
4
+ import requests
5
+ from ..config import url_api_v1
6
+ import json
7
+ from .authenticator import Authenticator
8
+ import pandas as pd
9
+
10
+ class StockLoan:
11
+ """
12
+ This class provides trades related to stock loan operations.
13
+
14
+ * Main use case:
15
+
16
+ >>> from btgsolutions_dataservices import StockLoan
17
+ >>> stock_loan = StockLoan(
18
+ >>> api_key='YOUR_API_KEY',
19
+ >>> )
20
+ >>> trades = stock_loan.get_trades(
21
+ >>> ticker = 'PETR4'
22
+ >>> )
23
+ >>> trades = stock_loan.get_paginated_trades(
24
+ >>> page = 1,
25
+ >>> limit = 1000
26
+ >>> )
27
+ >>> stock_loan.get_available_tickers()
28
+
29
+ Parameters
30
+ ----------------
31
+ api_key: str
32
+ User identification key.
33
+ Field is required.
34
+ """
35
+ def __init__(
36
+ self,
37
+ api_key: Optional[str]
38
+ ):
39
+ self.api_key = api_key
40
+ self.token = Authenticator(self.api_key).token
41
+ self.headers = {"authorization": f"authorization {self.token}"}
42
+
43
+ def get_trades(
44
+ self,
45
+ ticker:Optional[str]='',
46
+ ):
47
+ """
48
+ Returns trades related to stock loan operations.
49
+
50
+ Parameters
51
+ ----------------
52
+ ticker : str, optional
53
+ The ticker symbol to be returned.
54
+ Example: 'PETR4'
55
+
56
+ """
57
+ page = 1
58
+ df = pd.DataFrame()
59
+ while True:
60
+ url = f"{url_api_v1}/marketdata/stock-loan/daily-trades?page={page}&limit=20000"
61
+ if ticker: url += f'&ticker={ticker}'
62
+ response = requests.request("GET", url, headers=self.headers)
63
+ if response.status_code != 200: raise BadResponse(response.json())
64
+ response = response.json()
65
+ df = pd.concat([df, pd.DataFrame(response['data'])])
66
+ if response['totalPages'] <= page: break
67
+ page += 1
68
+
69
+ return df.reset_index(drop=True)
70
+
71
+ def get_paginated_trades(
72
+ self,
73
+ page:int,
74
+ limit:int,
75
+ ticker:Optional[str]='',
76
+ ):
77
+ """
78
+ Returns paginated trades related to stock loan operations.
79
+
80
+ Parameters
81
+ ----------------
82
+ ticker : str, optional
83
+ The ticker symbol to be returned.
84
+ Example: 'PETR4'
85
+
86
+ page : int
87
+ Page number for paginated results.
88
+ Example: 1
89
+
90
+ limit : int
91
+ Maximum number of items to return per page.
92
+ Example: 1000
93
+
94
+ """
95
+ url = f"{url_api_v1}/marketdata/stock-loan/daily-trades?page={page}&limit={limit}"
96
+ if ticker: url += f'&ticker={ticker}'
97
+ response = requests.request("GET", url, headers=self.headers)
98
+ if response.status_code == 200: return json.loads(response.text)
99
+ raise BadResponse(response.json())
100
+
101
+ def get_available_tickers(
102
+ self,
103
+ ):
104
+ """
105
+ This method provides all tickers available for query.
106
+ """
107
+ url = f"{url_api_v1}/marketdata/stock-loan/available-tickers"
108
+ response = requests.request("GET", url, headers=self.headers)
109
+ if response.status_code == 200: return json.loads(response.text)
110
+ raise BadResponse(response.json())
@@ -61,7 +61,7 @@ class MarketDataFeed:
61
61
  Field is not required. Default: 'b3'.
62
62
  data_type: str
63
63
  Market Data type.
64
- Options: 'trades', 'processed-trades', 'books', 'indices', 'securities', 'stoploss', 'candles-1S', 'candles-1M', 'instrument_status'.
64
+ Options: 'trades', 'processed-trades', 'books', 'indices', 'securities', 'stoploss', 'candles-1S', 'candles-1M', 'instrument_status', 'settlement-price'.
65
65
  Field is not required. Default: 'trades'.
66
66
  data_subtype: str
67
67
  Market Data subtype (when applicable).
@@ -2,7 +2,7 @@
2
2
  from typing import Optional, List
3
3
  from ..exceptions import WSTypeError, DelayedError, FeedError
4
4
  from ..rest import Authenticator
5
- from ..config import market_data_socket_urls, market_data_feedb_socket_urls, MAX_WS_RECONNECT_RETRIES, VALID_STREAM_TYPES, VALID_EXCHANGES, VALID_MARKET_DATA_TYPES, VALID_MARKET_DATA_SUBTYPES, REALTIME, B3, TRADES, INDICES, ALL, STOCKS, BOOKS, FEED_A, FEED_B
5
+ from ..config import market_data_socket_urls, market_data_feedb_socket_urls, MAX_WS_RECONNECT_RETRIES, VALID_STREAM_TYPES, VALID_EXCHANGES, VALID_MARKET_DATA_TYPES, VALID_MARKET_DATA_SUBTYPES, REALTIME, B3, TRADES, INDICES, ALL, STOCKS, BOOKS, FEED_A, FEED_B, SETTLEMENTPRICES
6
6
  from .websocket_default_functions import _on_open, _on_message, _on_error, _on_close
7
7
  import websocket
8
8
  import json
@@ -49,7 +49,7 @@ class MarketDataWebSocketClient:
49
49
 
50
50
  data_type: str
51
51
  Market Data type.
52
- Options: 'trades', 'processed-trades', 'books', 'indices', 'securities', 'stoploss', 'candles-1S', 'candles-1M', 'instrument_status'.
52
+ Options: 'trades', 'processed-trades', 'books', 'indices', 'securities', 'stoploss', 'candles-1S', 'candles-1M', 'instrument_status', 'settlement-price'.
53
53
  Field is not required. Default: 'trades'.
54
54
 
55
55
  data_subtype: str
@@ -93,7 +93,7 @@ class MarketDataWebSocketClient:
93
93
  self.__nro_reconnect_retries = 0
94
94
 
95
95
  if data_subtype is None:
96
- if exchange is B3 and data_type is not INDICES:
96
+ if exchange is B3 and not data_type in [INDICES, SETTLEMENTPRICES]:
97
97
  data_subtype = STOCKS
98
98
  else:
99
99
  data_subtype = ALL
@@ -1,10 +1,10 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: btgsolutions-dataservices-python-client
3
- Version: 2.14.1
3
+ Version: 2.16.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
- Requires-Python: >=3.9,<3.13
7
+ Requires-Python: >=3.9,<3.14
8
8
  Description-Content-Type: text/markdown
9
9
  License-File: LICENSE
10
10
  Requires-Dist: pandas>=2.2.2
@@ -170,6 +170,21 @@ ws.run(on_message=lambda message: print(message))
170
170
  ws.instrument_status('PETR4')
171
171
  ws.instrument_status_history('PETR4')
172
172
 
173
+ ## The following is optional to keep the program running in a .py file:
174
+ # from time import sleep
175
+ # while True:
176
+ # sleep(1)
177
+ ```
178
+ ##### Settlement Price
179
+
180
+ ```python
181
+ import btgsolutions_dataservices as btg
182
+ ws = btg.MarketDataWebSocketClient(api_key='YOUR_API_KEY', data_type='settlement-price', instruments=['ABEVOU25', 'WINV25'])
183
+ ws.run(on_message=lambda message: print(message))
184
+
185
+ ## Getting the last event (settlement-price) of ABEVOU25:
186
+ # ws.get_last_event(['ABEVOU25'])
187
+
173
188
  ## The following is optional to keep the program running in a .py file:
174
189
  # from time import sleep
175
190
  # while True:
@@ -352,6 +367,16 @@ public_sources = btg.PublicSources(api_key='YOUR_API_KEY')
352
367
  public_sources.get_opas(start_date='2022-10-01', end_date='2024-10-01')
353
368
  ```
354
369
 
370
+ #### STOCK LOAN
371
+
372
+ ```python
373
+ import btgsolutions_dataservices as btg
374
+ stock_loan = btg.StockLoan(api_key='YOUR_API_KEY')
375
+ stock_loan.get_trades()
376
+ stock_loan.get_paginated_trades(page=1, limit=1000, ticker ='PETR4')
377
+ stock_loan.get_available_tickers()
378
+ ```
379
+
355
380
  #### Company Fundamentals
356
381
 
357
382
  ##### Company General Information
@@ -19,6 +19,7 @@ btgsolutions_dataservices/rest/intraday_tick_data.py
19
19
  btgsolutions_dataservices/rest/public_sources.py
20
20
  btgsolutions_dataservices/rest/quotes.py
21
21
  btgsolutions_dataservices/rest/reference_data.py
22
+ btgsolutions_dataservices/rest/stock_loan.py
22
23
  btgsolutions_dataservices/rest/ticker_last_event.py
23
24
  btgsolutions_dataservices/websocket/__init__.py
24
25
  btgsolutions_dataservices/websocket/hfn_websocket_client.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.14.1',
25
+ version='2.16.0',
26
26
  description=description,
27
27
  long_description=long_description,
28
28
  long_description_content_type='text/markdown',
@@ -30,5 +30,5 @@ setup(
30
30
  packages=find_packages(),
31
31
  url="https://github.com/BTG-Pactual-Solutions/btgsolutions-dataservices-python-client",
32
32
  install_requires=install_requires,
33
- python_requires=">=3.9,<3.13",
33
+ python_requires=">=3.9,<3.14",
34
34
  )