Core Components API Reference¶
This page documents the core classes and functions of the Candles Feed framework.
CandlesFeed¶
Main class that coordinates data collection from exchanges.
This class is responsible for creating and managing the components needed to fetch and process candle data from exchanges.
Source code in candles_feed/core/candles_feed.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 |
|
first_timestamp
property
¶
Get the timestamp of the oldest candle.
Returns:
Type | Description |
---|---|
int | None
|
Timestamp in seconds, or None if no candles available |
last_timestamp
property
¶
Get the timestamp of the most recent candle.
Returns:
Type | Description |
---|---|
int | None
|
Timestamp in seconds, or None if no candles available |
ready
property
¶
Check if the feed is ready.
Returns:
Type | Description |
---|---|
bool
|
True if the feed is ready, False otherwise |
__init__(exchange, trading_pair, interval='1m', max_records=150, logger=None)
¶
Initialize the candles feed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
exchange
|
str
|
Name of the exchange |
required |
trading_pair
|
str
|
Trading pair |
required |
interval
|
str
|
Candle interval |
'1m'
|
max_records
|
int
|
Maximum number of candles to store |
150
|
logger
|
Logger | None
|
Logger instance |
None
|
Source code in candles_feed/core/candles_feed.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
|
_create_rest_strategy()
¶
Create a REST polling strategy instance.
This is a helper method that can be mocked in tests.
Source code in candles_feed/core/candles_feed.py
85 86 87 88 89 90 91 92 93 94 95 96 97 |
|
_create_ws_strategy()
¶
Create a WebSocket strategy instance.
This is a helper method that can be mocked in tests.
Source code in candles_feed/core/candles_feed.py
71 72 73 74 75 76 77 78 79 80 81 82 83 |
|
add_candle(candle)
¶
Add a candle to the store.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
candle
|
CandleData
|
Candle data to add |
required |
Source code in candles_feed/core/candles_feed.py
231 232 233 234 235 236 237 |
|
fetch_candles(start_time=None, end_time=None)
async
¶
Fetch historical candles.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start_time
|
int | None
|
Start time in seconds (optional) |
None
|
end_time
|
int | None
|
End time in seconds (optional) |
None
|
Returns:
Type | Description |
---|---|
list[CandleData]
|
List of candle data objects |
Source code in candles_feed/core/candles_feed.py
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
|
get_candles()
¶
Get raw candle data.
Returns:
Type | Description |
---|---|
list[CandleData]
|
List of CandleData objects |
Source code in candles_feed/core/candles_feed.py
223 224 225 226 227 228 229 |
|
get_candles_df()
¶
Get candles as a pandas DataFrame.
Returns:
Type | Description |
---|---|
DataFrame
|
DataFrame with candle data |
Source code in candles_feed/core/candles_feed.py
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
|
start(strategy='auto')
async
¶
Start the feed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
strategy
|
str
|
Strategy to use ("auto", "websocket", or "polling") |
'auto'
|
Source code in candles_feed/core/candles_feed.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
|
stop()
async
¶
Stop the feed.
Source code in candles_feed/core/candles_feed.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
|
CandleData¶
Standardized candle data representation.
This class provides a structured and type-safe representation of candle data with automatic timestamp normalization.
Attributes:
Name | Type | Description |
---|---|---|
timestamp |
int
|
The candle timestamp in seconds |
open |
float
|
Opening price |
high |
float
|
Highest price during period |
low |
float
|
Lowest price during period |
close |
float
|
Closing price |
volume |
float
|
Trading volume |
quote_asset_volume |
float
|
Quote asset volume (optional) |
n_trades |
int
|
Number of trades (optional) |
taker_buy_base_volume |
float
|
Base asset volume from taker buys (optional) |
taker_buy_quote_volume |
float
|
Quote asset volume from taker buys (optional) |
Source code in candles_feed/core/candle_data.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
|
timestamp_ms
property
¶
Convert timestamp to milliseconds.
__post_init__(timestamp_raw)
¶
Convert timestamp to integer seconds after initialization.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
timestamp_raw
|
int | float | str | datetime
|
Raw timestamp input in various formats |
required |
Source code in candles_feed/core/candle_data.py
57 58 59 60 61 62 63 |
|
_normalize_timestamp(ts)
staticmethod
¶
Convert various timestamp formats to integer seconds.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ts
|
int | float | str | datetime
|
Timestamp in various formats |
required |
Returns:
Type | Description |
---|---|
int
|
Timestamp as integer seconds |
Raises:
Type | Description |
---|---|
ValueError
|
If timestamp cannot be converted |
Source code in candles_feed/core/candle_data.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
|
from_array(data)
classmethod
¶
Create from array format for backward compatibility.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
list[float]
|
Array of candle values |
required |
Returns:
Type | Description |
---|---|
CandleData
|
CandleData instance |
Source code in candles_feed/core/candle_data.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
|
from_dict(data)
classmethod
¶
Create CandleData from a dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
dict
|
Dictionary containing candle data |
required |
Returns:
Type | Description |
---|---|
CandleData
|
CandleData instance |
Raises:
Type | Description |
---|---|
ValueError
|
If required fields are missing or invalid |
Source code in candles_feed/core/candle_data.py
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
|
to_array()
¶
Convert to array format for backward compatibility.
Returns:
Type | Description |
---|---|
list[float]
|
List of candle values |
Source code in candles_feed/core/candle_data.py
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
|
to_utc_seconds(dt)
staticmethod
¶
Convert datetime to UTC timestamp in seconds.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dt
|
datetime
|
Datetime to convert |
required |
Returns:
Type | Description |
---|---|
int
|
UTC timestamp in seconds |
Source code in candles_feed/core/candle_data.py
104 105 106 107 108 109 110 111 112 113 114 115 116 |
|
ExchangeRegistry¶
Registry for exchange adapters with auto-discovery.
Source code in candles_feed/core/exchange_registry.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
|
discover_adapters(package_path=None)
classmethod
¶
Discover and register adapters in the given package.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
package_path
|
str | None
|
Path to package to search for adapters |
None
|
Source code in candles_feed/core/exchange_registry.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
|
get_adapter(name)
classmethod
¶
Get adapter instance by name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Adapter name |
required |
Returns:
Type | Description |
---|---|
CandleDataAdapter
|
Adapter instance |
Raises:
Type | Description |
---|---|
ValueError
|
If no adapter is registered with the given name |
Source code in candles_feed/core/exchange_registry.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
|
get_adapter_class(name)
classmethod
¶
Get adapter class by name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Adapter name |
required |
Returns:
Type | Description |
---|---|
type[CandleDataAdapter]
|
Adapter class |
Raises:
Type | Description |
---|---|
ValueError
|
If no adapter is registered with the given name |
Source code in candles_feed/core/exchange_registry.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
|
get_adapter_instance(name, *args, **kwargs)
classmethod
¶
Get adapter instance by name with custom args.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Adapter name |
required |
*args
|
Positional arguments to pass to the adapter constructor |
()
|
|
**kwargs
|
Keyword arguments to pass to the adapter constructor |
{}
|
Returns:
Type | Description |
---|---|
CandleDataAdapter
|
Adapter instance |
Source code in candles_feed/core/exchange_registry.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
|
get_registered_exchanges()
classmethod
¶
Get list of registered exchange names.
Returns:
Type | Description |
---|---|
list[str]
|
List of registered exchange names |
Source code in candles_feed/core/exchange_registry.py
107 108 109 110 111 112 113 114 |
|
list_available_adapters()
classmethod
¶
List all registered adapter names.
Returns:
Type | Description |
---|---|
list[str]
|
List of adapter names |
Source code in candles_feed/core/exchange_registry.py
146 147 148 149 150 151 152 153 |
|
list_available_markets()
classmethod
¶
List all available markets by adapter.
Returns:
Type | Description |
---|---|
dict[str, list[str]]
|
Dictionary mapping adapter names to list of supported trading pairs |
Source code in candles_feed/core/exchange_registry.py
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
|
logger()
classmethod
¶
Get the logger.
Returns:
Type | Description |
---|---|
Logger
|
Logger instance |
Source code in candles_feed/core/exchange_registry.py
25 26 27 28 29 30 31 32 33 34 |
|
register(name)
classmethod
¶
Decorator for registering exchange adapters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Adapter name |
required |
Returns:
Type | Description |
---|---|
Decorator function |
Source code in candles_feed/core/exchange_registry.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
|
NetworkClient¶
Handles network communication with exchanges.
This class provides methods for communicating with exchange APIs, handling both REST and WebSocket connections.
Source code in candles_feed/core/network_client.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
|
__aenter__()
async
¶
Async context manager enter method.
Source code in candles_feed/core/network_client.py
46 47 48 49 |
|
__aexit__(exc_type, exc_val, exc_tb)
async
¶
Async context manager exit method.
Source code in candles_feed/core/network_client.py
51 52 53 |
|
__init__(logger=None)
¶
Initialize the NetworkClient.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
logger
|
Logger | None
|
Logger instance |
None
|
Source code in candles_feed/core/network_client.py
22 23 24 25 26 27 28 29 |
|
_ensure_session()
async
¶
Ensure aiohttp session exists.
Source code in candles_feed/core/network_client.py
31 32 33 34 |
|
close()
async
¶
Close the client session.
Should be called when the network client is no longer needed to properly clean up resources.
Source code in candles_feed/core/network_client.py
36 37 38 39 40 41 42 43 44 |
|
establish_ws_connection(url)
async
¶
Establish a websocket connection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url
|
str
|
WebSocket URL |
required |
Returns:
Type | Description |
---|---|
WSAssistant
|
WSAssistant instance |
Raises:
Type | Description |
---|---|
Exception
|
If the connection fails |
Source code in candles_feed/core/network_client.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
|
get_rest_data(url, params=None, data=None, headers=None, method='GET')
async
¶
Get data from REST API.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url
|
str
|
REST API URL |
required |
params
|
dict[str, Any] | None
|
Query parameters |
None
|
data
|
dict[str, Any] | None
|
Request body data |
None
|
headers
|
dict[str, str] | None
|
Request headers |
None
|
method
|
str
|
HTTP method |
'GET'
|
Returns:
Type | Description |
---|---|
Any
|
REST API response |
Raises:
Type | Description |
---|---|
Exception
|
If the request fails |
Source code in candles_feed/core/network_client.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
|
send_ws_message(ws_assistant, payload)
async
¶
Send a message over WebSocket.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ws_assistant
|
WSAssistant
|
WebSocket assistant |
required |
payload
|
dict[str, Any]
|
Message payload |
required |
Raises:
Type | Description |
---|---|
Exception
|
If sending fails |
Source code in candles_feed/core/network_client.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
|
NetworkStrategies¶
WebSocketStrategy¶
Implementation for websocket-based candle retrieval.
Source code in candles_feed/core/network_strategies.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
|
__init__(network_client, adapter, trading_pair, interval, data_processor, candles_store, logger=None)
¶
Initialize the WebSocketStrategy.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
network_client
|
NetworkClient
|
Network client for API communication |
required |
adapter
|
CandleDataAdapter
|
Exchange adapter |
required |
trading_pair
|
str
|
Trading pair |
required |
interval
|
str
|
Candle interval |
required |
data_processor
|
DataProcessor
|
Data processor |
required |
candles_store
|
Deque[CandleData]
|
Deque for storing candles |
required |
logger
|
Logger | None
|
Logger instance |
None
|
Source code in candles_feed/core/network_strategies.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
|
_initialize_candles()
async
¶
Initialize candles using REST API.
Source code in candles_feed/core/network_strategies.py
163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
|
_listen_for_updates()
async
¶
Listen for websocket updates.
Source code in candles_feed/core/network_strategies.py
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
|
_update_candles(new_candles)
¶
Update the candles store with new data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
new_candles
|
list[CandleData]
|
New candles to update |
required |
Source code in candles_feed/core/network_strategies.py
178 179 180 181 182 183 184 185 186 187 188 189 |
|
poll_once(start_time=None, end_time=None, limit=None)
async
¶
Fetch candles for a specific time range (one-time poll).
For WebSocket strategy, this falls back to REST API for historical data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start_time
|
int | None
|
Start time in seconds |
None
|
end_time
|
int | None
|
End time in seconds |
None
|
limit
|
int | None
|
Maximum number of candles to return |
None
|
Returns:
Type | Description |
---|---|
list[CandleData]
|
List of CandleData objects |
Source code in candles_feed/core/network_strategies.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
|
start()
async
¶
Start listening for websocket updates.
Source code in candles_feed/core/network_strategies.py
56 57 58 59 60 |
|
stop()
async
¶
Stop listening for websocket updates.
Source code in candles_feed/core/network_strategies.py
62 63 64 65 66 67 68 69 70 71 72 |
|
RESTPollingStrategy¶
Implementation for REST-based polling candle retrieval.
Source code in candles_feed/core/network_strategies.py
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 |
|
__init__(network_client, adapter, trading_pair, interval, data_processor, candles_store, logger=None)
¶
Initialize the RESTPollingStrategy.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
network_client
|
NetworkClient
|
Network client for API communication |
required |
adapter
|
CandleDataAdapter
|
Exchange adapter |
required |
trading_pair
|
str
|
Trading pair |
required |
interval
|
str
|
Candle interval |
required |
data_processor
|
DataProcessor
|
Data processor |
required |
candles_store
|
Deque[CandleData]
|
Deque for storing candles |
required |
logger
|
Logger | None
|
Logger instance |
None
|
Source code in candles_feed/core/network_strategies.py
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
|
_poll_for_updates()
async
¶
Poll for updates at regular intervals.
Source code in candles_feed/core/network_strategies.py
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 |
|
_update_candles(new_candles)
¶
Update the candles store with new data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
new_candles
|
list[CandleData]
|
New candles to update |
required |
Source code in candles_feed/core/network_strategies.py
340 341 342 343 344 345 346 347 348 349 350 |
|
poll_once(start_time=None, end_time=None, limit=None)
async
¶
Fetch candles for a specific time range (one-time poll).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start_time
|
int | None
|
Start time in seconds |
None
|
end_time
|
int | None
|
End time in seconds |
None
|
limit
|
int | None
|
Maximum number of candles to return |
None
|
Returns:
Type | Description |
---|---|
list[CandleData]
|
List of CandleData objects |
Source code in candles_feed/core/network_strategies.py
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 |
|
start()
async
¶
Start polling for updates.
Source code in candles_feed/core/network_strategies.py
228 229 230 231 232 |
|
stop()
async
¶
Stop polling for updates.
Source code in candles_feed/core/network_strategies.py
234 235 236 237 238 239 |
|
Protocols¶
Bases: Protocol
Protocol for exchange adapters.
This protocol defines the interface that all exchange adapters must implement.
Source code in candles_feed/core/protocols.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
|
get_rest_params(trading_pair, interval, start_time=None, end_time=None, limit=None)
¶
Get parameters for REST API request.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
trading_pair
|
str
|
Trading pair |
required |
interval
|
str
|
Candle interval |
required |
start_time
|
int | None
|
Start time in seconds |
None
|
end_time
|
int | None
|
End time in seconds |
None
|
limit
|
int | None
|
Maximum number of candles to return |
None
|
Returns:
Type | Description |
---|---|
dict
|
Dictionary of parameters for REST API request |
Source code in candles_feed/core/protocols.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
|
get_rest_url()
¶
Get REST API URL for candles.
Returns:
Type | Description |
---|---|
str
|
REST API URL |
Source code in candles_feed/core/protocols.py
32 33 34 35 36 37 38 |
|
get_supported_intervals()
¶
Get supported intervals and their durations in seconds.
Returns:
Type | Description |
---|---|
dict[str, int]
|
Dictionary mapping interval strings to their duration in seconds |
Source code in candles_feed/core/protocols.py
104 105 106 107 108 109 110 |
|
get_trading_pair_format(trading_pair)
¶
Convert standard trading pair format to exchange format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
trading_pair
|
str
|
Trading pair in standard format (e.g., "BTC-USDT") |
required |
Returns:
Type | Description |
---|---|
str
|
Trading pair in exchange-specific format |
Source code in candles_feed/core/protocols.py
21 22 23 24 25 26 27 28 29 30 |
|
get_ws_subscription_payload(trading_pair, interval)
¶
Get WebSocket subscription payload.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
trading_pair
|
str
|
Trading pair |
required |
interval
|
str
|
Candle interval |
required |
Returns:
Type | Description |
---|---|
dict
|
WebSocket subscription payload |
Source code in candles_feed/core/protocols.py
81 82 83 84 85 86 87 88 89 90 91 |
|
get_ws_supported_intervals()
¶
Get intervals supported by WebSocket API.
Returns:
Type | Description |
---|---|
list[str]
|
List of interval strings supported by WebSocket API |
Source code in candles_feed/core/protocols.py
112 113 114 115 116 117 118 |
|
get_ws_url()
¶
Get WebSocket URL.
Returns:
Type | Description |
---|---|
str
|
WebSocket URL |
Source code in candles_feed/core/protocols.py
40 41 42 43 44 45 46 |
|
parse_rest_response(data)
¶
Parse REST API response into CandleData objects.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
Any
|
REST API response |
required |
Returns:
Type | Description |
---|---|
list[CandleData]
|
List of CandleData objects |
Source code in candles_feed/core/protocols.py
70 71 72 73 74 75 76 77 78 79 |
|
parse_ws_message(data)
¶
Parse WebSocket message into CandleData objects.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
Any
|
WebSocket message |
required |
Returns:
Type | Description |
---|---|
list[CandleData] | None
|
List of CandleData objects or None if message is not a candle update |
Source code in candles_feed/core/protocols.py
93 94 95 96 97 98 99 100 101 102 |
|
Bases: Protocol
Protocol for network connection strategies.
Source code in candles_feed/core/protocols.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
|
poll_once(start_time=None, end_time=None, limit=None)
async
¶
Fetch candles for a specific time range.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start_time
|
int | None
|
Start time in seconds |
None
|
end_time
|
int | None
|
End time in seconds |
None
|
limit
|
int | None
|
Maximum number of candles to return |
None
|
Returns:
Type | Description |
---|---|
list[CandleData]
|
List of CandleData objects |
Source code in candles_feed/core/protocols.py
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
|
start()
async
¶
Start the network strategy.
Source code in candles_feed/core/protocols.py
172 173 174 |
|
stop()
async
¶
Stop the network strategy.
Source code in candles_feed/core/protocols.py
176 177 178 |
|
Bases: Protocol
Protocol for loggers.
Source code in candles_feed/core/protocols.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
|
debug(msg, *args, **kwargs)
¶
Log debug message.
Source code in candles_feed/core/protocols.py
184 185 186 |
|
error(msg, *args, **kwargs)
¶
Log error message.
Source code in candles_feed/core/protocols.py
196 197 198 |
|
exception(msg, *args, **kwargs)
¶
Log exception message.
Source code in candles_feed/core/protocols.py
200 201 202 |
|
info(msg, *args, **kwargs)
¶
Log info message.
Source code in candles_feed/core/protocols.py
188 189 190 |
|
warning(msg, *args, **kwargs)
¶
Log warning message.
Source code in candles_feed/core/protocols.py
192 193 194 |
|