data.storage.store_market_data
data.storage.store_market_data
DataStorage
DataStorage(database_path: str | Path | None = None)
Allows for the storage of OHLCV data to prevent re-polling API data that has already been received before.
Initializes DataStorage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
database_path
|
str | Path | None
|
Where to store the database. If not provided, falls back to the OS-standard user data directory %LOCALAPPDATA%\contango\contango on Windows). |
None
|
Source code in src\contango\data\storage\store_market_data.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | |
add_data_to_storage
add_data_to_storage(interval: str, data: list[MarketDataEvent]) -> None
Adds market data to storage. Existing candles with the same symbol/interval/timestamp are ignored.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
interval
|
str
|
The interval to save the data as (i.e. |
required |
data
|
list[MarketDataEvent]
|
The data to save into the database. |
required |
Source code in src\contango\data\storage\store_market_data.py
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 | |
close
close() -> None
Closes the connection to the database.
Source code in src\contango\data\storage\store_market_data.py
248 249 250 251 252 | |
get_data
get_data(symbol: str, interval: str, start_timestamp: int, end_timestamp: int) -> list[MarketDataEvent]
Retrieves market data in chronological order by timestamp.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
The symbol to derive data from. |
required |
interval
|
str
|
The interval to retrieve data from for the symbol (i.e. |
required |
start_timestamp
|
int
|
The start timestamp in unix ms. |
required |
end_timestamp
|
int
|
The end timestamp in unix ms. |
required |
Returns:
| Type | Description |
|---|---|
list[MarketDataEvent]
|
list[MarketDataEvent]: The data for the provided parameters, if any. |
Source code in src\contango\data\storage\store_market_data.py
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 | |
get_missing_timestamps
get_missing_timestamps(symbol: str, interval: str, expected_timestamps: Iterable[datetime]) -> list[int]
Returns the timestamps that are NOT currently stored for the given symbol/interval, out of a caller-supplied set of expected timestamps. Callers are responsible for generating the correct expected schedule.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
The symbol to check. |
required |
interval
|
str
|
The interval to check (i.e. |
required |
expected_timestamps
|
Iterable[datetime]
|
The datetimes candles are expected to exist for. Must be timezone-aware (or assumed UTC if naive) since stored timestamps are unix ms in UTC. |
required |
Returns:
| Type | Description |
|---|---|
list[int]
|
list[int]: Sorted list of missing timestamps (unix ms). Empty if fully cached. |
Source code in src\contango\data\storage\store_market_data.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 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 | |