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

Method fetch_markets

python/ccxt/binance.py:3194–3485  ·  view source on GitHub ↗

retrieves data on all markets for binance https://developers.binance.com/docs/binance-spot-api-docs/rest-api/general-endpoints#exchange-information # spot https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Exchange-Informati

(self, params={})

Source from the content-addressed store, hash-verified

3192 })
3193
3194 def fetch_markets(self, params={}) -> List[Market]:
3195 """
3196 retrieves data on all markets for binance
3197
3198 https://developers.binance.com/docs/binance-spot-api-docs/rest-api/general-endpoints#exchange-information # spot
3199 https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Exchange-Information # swap
3200 https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Exchange-Information # future
3201 https://developers.binance.com/docs/derivatives/option/market-data/Exchange-Information # option
3202 https://developers.binance.com/docs/margin_trading/market-data/Get-All-Cross-Margin-Pairs # cross margin
3203 https://developers.binance.com/docs/margin_trading/market-data/Get-All-Isolated-Margin-Symbol # isolated margin
3204
3205 :param dict [params]: extra parameters specific to the exchange API endpoint
3206 :returns dict[]: an array of objects representing market data
3207 """
3208 promisesRaw = []
3209 rawFetchMarkets = None
3210 defaultTypes = ['spot', 'linear', 'inverse']
3211 fetchMarketsOptions = self.safe_dict(self.options, 'fetchMarkets')
3212 if fetchMarketsOptions is not None:
3213 rawFetchMarkets = self.safe_list(fetchMarketsOptions, 'types', defaultTypes)
3214 else:
3215 # for backward-compatibility
3216 rawFetchMarkets = self.safe_list(self.options, 'fetchMarkets', defaultTypes)
3217 # handle loadAllOptions option
3218 loadAllOptions = self.safe_bool(self.options, 'loadAllOptions', False)
3219 if loadAllOptions:
3220 if not self.in_array('option', rawFetchMarkets):
3221 rawFetchMarkets.append('option')
3222 sandboxMode = self.safe_bool(self.options, 'sandboxMode', False)
3223 demoMode = self.safe_bool(self.options, 'enableDemoTrading', False)
3224 isDemoEnv = demoMode or sandboxMode
3225 fetchMarkets = []
3226 for i in range(0, len(rawFetchMarkets)):
3227 type = rawFetchMarkets[i]
3228 if type == 'option' and isDemoEnv:
3229 continue
3230 fetchMarkets.append(type)
3231 fetchMargins = self.safe_bool(self.options, 'fetchMargins', False)
3232 for i in range(0, len(fetchMarkets)):
3233 marketType = fetchMarkets[i]
3234 if marketType == 'spot':
3235 promisesRaw.append(self.publicGetExchangeInfo(params))
3236 if fetchMargins and self.check_required_credentials(False) and not isDemoEnv:
3237 promisesRaw.append(self.sapiGetMarginAllPairs(params))
3238 promisesRaw.append(self.sapiGetMarginIsolatedAllPairs(params))
3239 elif marketType == 'linear':
3240 promisesRaw.append(self.fapiPublicGetExchangeInfo(params))
3241 elif marketType == 'inverse':
3242 promisesRaw.append(self.dapiPublicGetExchangeInfo(params))
3243 elif marketType == 'option':
3244 promisesRaw.append(self.eapiPublicGetExchangeInfo(params))
3245 else:
3246 raise ExchangeError(self.id + ' fetchMarkets() self.options fetchMarkets "' + marketType + '" is not a supported market type')
3247 results = promisesRaw
3248 markets = []
3249 self.options['crossMarginPairsData'] = []
3250 self.options['isolatedMarginPairsData'] = []
3251 for i in range(0, len(results)):

Callers 1

fetch_trading_limitsMethod · 0.95

Calls 15

publicGetExchangeInfoMethod · 0.95
sapiGetMarginAllPairsMethod · 0.95
parse_marketMethod · 0.95
ExchangeErrorClass · 0.90
safe_dictMethod · 0.80
safe_listMethod · 0.80
safe_boolMethod · 0.80
in_arrayMethod · 0.80

Tested by

no test coverage detected