MCPcopy Create free account
hub / github.com/ccxt/ccxt / fetch_ohlcv

Method fetch_ohlcv

python/ccxt/ascendex.py:1253–1319  ·  view source on GitHub ↗

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={})

Source from the content-addressed store, hash-verified

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",

Callers

nothing calls this directly

Calls 12

safe_stringMethod · 0.80
parse_timeframeMethod · 0.80
safe_dictMethod · 0.80
safe_integerMethod · 0.80
safe_listMethod · 0.80
v1PublicGetBarhistMethod · 0.65
load_marketsMethod · 0.45
marketMethod · 0.45
sumMethod · 0.45
omitMethod · 0.45
extendMethod · 0.45
parse_ohlcvsMethod · 0.45

Tested by

no test coverage detected