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
33.4k stars 7.57k forks source link

Load Markets. Spot, Margin, Futures #10520

Closed YuriyTigiev closed 2 years ago

YuriyTigiev commented 3 years ago

Hello,

How to get a list of markets which support an Exchange and load a piece of market information only for the selected market? For example only for spot, margin, or future?

'use strict';
const ccxt = require('ccxt');
var jp = require('jsonpath');

let kucoin     = new ccxt.kucoin();
let ftx           = new ccxt.ftx();
let binance   = new ccxt.binance();

(async function () {

    let data = await kucoin.loadMarkets();
    var dataString = Array.from(new Set(jp.query(data, '$..type')));
    console.log('kucoin: ', dataString);

    data = await ftx.loadMarkets();
    dataString = Array.from(new Set(jp.query(data, '$..type')));
    console.log('ftx: ',dataString);

    data = await binance.loadMarkets();
    dataString = Array.from(new Set(jp.query(data, '$..type')));
    console.log('binance: ',dataString);

}) ();
ttodua commented 2 years ago

At this moment, there is no unified codebase in CCXT that can return the spot/margin/futures markets (like: exch.spot_markets_list/exch.margin_markets_list/exch.futures_markets_list properties). [@kroitor do I miss anything?] At this moment, you have to manually look into your desired exchange's loaded-markets and find out the specific custom flag (some of exchanges have i.e. marginable:true flag into pair-properties, or something like that).

However, in the future this might get unified into CCXT, which might be obtainable using by smth like my mentioned functions (i.e. exch.spot_markets_list).
Stay subscribed to this issue and whenever that is implemented, you will get notification.

kroitor commented 2 years ago

@YuriyTigiev you can do that like this:

const ftx = new ccxt.ftx();
const kucoin = new ccxt.kucoin();
const binance = new ccxt.binance();
const binanceusdm = new ccxt.binanceusdm ();
// or const binanceusdm = new ccxt.binance({ 'options': { 'defaultType': 'future' }})
const binancecoinm = new ccxt.binancecoinm()
// or const binancecoinm = new ccxt.binance({ 'options': { 'defaultType': 'delivery' }})

const allMarkets = await Promise.all ([
    ftx.loadMarkets (),
    kucoin.loadMarkets (),
    binance.loadMarkets (),
    binanceusdm.loadMarkets (),
    binancecoinm.loadMarkets ()
])

console.log (ftx.markets)
console.log (binance.markets)
console.log (binanceusdm.markets)
console.log (binancecoinm.markets)
// ...
zeki-kadiroglu commented 1 year ago

Currently, Is it working? Because, I couldn't get the correct data seperately from python version of your script with ccxt.binance({ 'options': { 'defaultType': 'delivery' }})