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