ccxt / ccxt

A JavaScript / TypeScript / Python / C# / PHP cryptocurrency trading API with support for more than 100 bitcoin/altcoin exchanges
https://docs.ccxt.com
MIT License
32.8k stars 7.5k forks source link

get Future (swap) markets and symbol from exchange #14761

Closed pier0074 closed 2 years ago

pier0074 commented 2 years ago

OS: linux Programming Language version: PHP 8.1 CCXT version: 1.92.48

Hello,

How do I get all future or swap symbols from a specific exchange. It seems to be working fine for binance but not for others. After reading a lot of issues and comments I did not find the exact answer to my question, closer one was this one.

When I instantiate a binance exchange like following, it limits markets and symbols to futureMarket.

$binance = new ccxt\binance( [ 'options' => [ 'defaultType' => 'future' ] ] );
$markets = $binance->load_markets();
$symbols = $binance->symbols;

However, when I do it to aax or ftx, there are all markets and symbols, exact as if I did not include [ 'options' => [ 'defaultType' => 'swap' ] ].

$aax = new ccxt\aax( [ 'options' => [ 'defaultType' => 'swap' ] ] );
$markets = $aax->load_markets();
$symbols = $aax->symbols;

$ftx = new ccxt\ftx( [ 'options' => [ 'defaultType' => 'swap' ] ] ); 
$markets = $ftx->load_markets();
$symbols = $ftx->symbols;

Both codes return all markets and symbols, include spot ones.

What is included in markets seems to be correct, as it includes the type, for example :

FTX : 
[1INCH/USD:USD] => Array
        (
            [id] => 1INCH-PERP
...
            [type] => swap
)

    [1INCH/USD:USD-220930] => Array
        (
            [id] => 1INCH-0930
            [symbol] => 1INCH/USD:USD-220930
...
            [type] => future
)

AAX: 
    [SOL/USDT:USDT] => Array
        (
            [id] => SOLUSDTFP
            [symbol] => SOL/USDT:USDT
...
            [type] => swap

So I think, it would be interesting that load_markets and symbols object would be filtered by type based on 'defaultType'.

samgermain commented 2 years ago

What was wrong with this answer?

pier0074 commented 2 years ago

There is nothing wrong with your answer. I just think there is inconsistency in the way markets and symbols are loaded when using options['defaultType']. As you pointed out, when you initialize ftx with the swap options, symbols return more than 800 symbols whereas -Perp (really swap symbols usable in ftx future) are less than 150. When loading ftx with options['defaultType']= 'swap', the markets and symbols array should be reduced to the ones that are actually future and tradable in ftx future (-perp one in the case of ftx). Ftx is not the only exchange where I think there is inconsistency between the exchange with parameters options['defaultType'] and array of symbols/markets returned.

samgermain commented 2 years ago

There is nothing wrong with your answer. I just think there is inconsistency in the way markets and symbols are loaded when using options['defaultType']. As you pointed out, when you initialize ftx with the swap options, symbols return more than 800 symbols whereas -Perp (really swap symbols usable in ftx future) are less than 150. When loading ftx with options['defaultType']= 'swap', the markets and symbols array should be reduced to the ones that are actually future and tradable in ftx future (-perp one in the case of ftx). Ftx is not the only exchange where I think there is inconsistency between the exchange with parameters options['defaultType'] and array of symbols/markets returned.

samgermain commented 2 years ago

I'm going to close this issue, feel free to reopen it if you have any more questions