fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market :param str symbol: unified symbol of the market to fetch OHLCV data for :param str timeframe: the length of time each candle represents :param int [since]:
(self, symbol: str, timeframe: str = '1m', since: Int = None, limit: Int = None, params={})
| 1251 | ] |
| 1252 | |
| 1253 | def fetch_ohlcv(self, symbol: str, timeframe: str = '1m', since: Int = None, limit: Int = None, params={}) -> List[list]: |
| 1254 | """ |
| 1255 | fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market |
| 1256 | :param str symbol: unified symbol of the market to fetch OHLCV data for |
| 1257 | :param str timeframe: the length of time each candle represents |
| 1258 | :param int [since]: timestamp in ms of the earliest candle to fetch |
| 1259 | :param int [limit]: the maximum amount of candles to fetch |
| 1260 | :param dict [params]: extra parameters specific to the exchange API endpoint |
| 1261 | :param int [params.until]: timestamp in ms of the latest candle to fetch |
| 1262 | :returns int[][]: A list of candles ordered, open, high, low, close, volume |
| 1263 | """ |
| 1264 | self.load_markets() |
| 1265 | market = self.market(symbol) |
| 1266 | request = { |
| 1267 | 'symbol': market['id'], |
| 1268 | 'interval': self.safe_string(self.timeframes, timeframe, timeframe), |
| 1269 | } |
| 1270 | # if since and limit are not specified |
| 1271 | # the exchange will return just 1 last candle by default |
| 1272 | duration = self.parse_timeframe(timeframe) |
| 1273 | options = self.safe_dict(self.options, 'fetchOHLCV', {}) |
| 1274 | defaultLimit = self.safe_integer(options, 'limit', 500) |
| 1275 | until = self.safe_integer(params, 'until') |
| 1276 | if since is not None: |
| 1277 | request['from'] = since |
| 1278 | if limit is None: |
| 1279 | limit = defaultLimit |
| 1280 | else: |
| 1281 | limit = min(limit, defaultLimit) |
| 1282 | toWithLimit = self.sum(since, limit * duration * 1000, 1) |
| 1283 | if until is not None: |
| 1284 | request['to'] = min(toWithLimit, until + 1) |
| 1285 | else: |
| 1286 | request['to'] = toWithLimit |
| 1287 | elif until is not None: |
| 1288 | request['to'] = until + 1 |
| 1289 | if limit is None: |
| 1290 | limit = defaultLimit |
| 1291 | else: |
| 1292 | limit = min(limit, defaultLimit) |
| 1293 | request['from'] = until - (limit * duration * 1000) |
| 1294 | elif limit is not None: |
| 1295 | request['n'] = limit # max 500 |
| 1296 | params = self.omit(params, 'until') |
| 1297 | response = self.v1PublicGetBarhist(self.extend(request, params)) |
| 1298 | # |
| 1299 | # { |
| 1300 | # "code":0, |
| 1301 | # "data":[ |
| 1302 | # { |
| 1303 | # "m":"bar", |
| 1304 | # "s":"BTC/USDT", |
| 1305 | # "data":{ |
| 1306 | # "i":"1", |
| 1307 | # "ts":1590228000000, |
| 1308 | # "o":"9139.59", |
| 1309 | # "c":"9131.94", |
| 1310 | # "h":"9139.99", |
nothing calls this directly
no test coverage detected