Select Page

Installing and using CCXT

This article is a Spanish translation of the CCXT library installation manual.

Introduction

The CCXT library is used for connecting and exchanging cryptocurrencies and processing payments around the world. It provides quick access to market information for storage, analysis and visualization.

It is intended to be used by developers, financial analysts for the development of exchange algorithms.

List of features:

  • Support a lot of cryptocurrency exchanges.
  • Fully implemented public and private APIs.
  • Standardized information on exchanges and arbitration.
  • An easy-to-integrate unified API.
  • Works on Node 7.6+, Python 2, PHP 5.4+ and web browsers.

Certified cryptocurrency exchanges

Logo Id Name See Doc Certificate
Binance binance Binance * Api
Bitfinex bitfinex Bitfinex 1 Api
Bittrex bittrex Bittrex 1.1 Api
Coss.io Coss Coss 1 Api
Kraken Kraken Kraken 0 Api
KuCoin kucoin KuCoin 2 Api
TheOcean theocean The Ocean 1 Api
UPbit upbit Upbit 1 Api

Supported cryptocurrency markets

The CCXT library currently supports the following 134 APIs:

Logo Id Name See Doc Certificate
1BTCXE _1btcxe 1BTCXE * Api
Acx Acx Acx 2 Api
AllCoin allcoin Allcoin 1 Api
ANXPro anxpro ANXPro * Api
Anybits anybits Anybits * Api
BCEX bcex BCEX 1 Api
Bequant bequant Bequant 2 Api
Bibox bibox Bibox 1 Api
BigONE bigone BigONE 2 Api
Binance binance Binance * Api
Binance Jersey binanceje Binance Jersey * Api
Bit2c bit2c Bit2C * Api
Bitbank bitbank bitbank 1 Api
BitBay bitbay BitBay * Api
Bitfinex bitfinex Bitfinex 1 Api
Bitfinex2 bitfinex2 Bitfinex 2 Api
BitFlyer bitflyer bitFlyer 1 Api
BitForex bitforex Bitforex 1 Api
Bithumb bithumb Bithumb * Api
Bitibu bitibu Bitibu 2 Api
Bitkk bitkk bitkk 1 Api
Bitlish bitlish Bitlish 1 Api
BitMarket bitmarket BitMarket * Api
BitMEX bitmex BitMEX 1 Api
Bitsane bitsane Bitsane * Api
Bitso bitso Bitso 3 Api
Bitstamp bitstamp Bitstamp 2 Api
Bitstamp1 bitstamp1 Bitstamp 1 Api
Bittrex bittrex Bittrex 1.1 Api
Bit-Z Bitz Bit-Z 2 Api
BL3P bl3p BL3P 1 Api
BleuTrade bleutrade Bleutrade 2 Api
Braziliex braziliex Braziliex * Api
BTC-Alpha btcalpha BTC-Alpha 1 Api
BTCBox btcbox BtcBox 1 Api
BTCChina btcchina BTCChina 1 Api
BTCExchange btcexchange BTCExchange * Api
BTC Markets btcmarkets BTC Markets * Api
BTCTrade.im btctradeim BtcTrade.im * Api
BTC Trade UA btctradeua BTC Trade UA * Api
BTCTurk btcturk BTCTurk * Api
Buddha Buddha Buddha 2 Api
BX.in.th bxinth BX.in.th * Api
C-CEX ccex C-CEX * Api
Cex. IO Cex Cex. IO * Api
CHBTC chbtc CHBTC 1 Api
ChileBit chilebit ChileBit 1 Api
COBINHOOD cobinhood COBINHOOD 1 Api
Coinbase coinbase Coinbase 2 Api
Coinbase Prime coinbaseprime Coinbase Prime * Api
Coinbase Pro coinbasepro Coinbase Pro * Api
Coincheck coincheck coincheck * Api
CoinEgg coinegg CoinEgg * Api
CoinEx coinex CoinEx 1 Api
CoinExchange coinexchange CoinExchange * Api
CoinFalcon coinfalcon CoinFalcon 1 Api
CoinFloor coinfloor coinfloor * Api
Coingi coingi Coingi * Api
CoinMarketCap coinmarketcap CoinMarketCap 1 Api
CoinMate co-mate CoinMate * Api
CoinNest coinnest coinnest * Api
CoinOne coinone CoinOne 2 Api
CoinSpot coinspot CoinSpot * Api
CoinTiger cointiger CoinTiger 1 Api
CoolCoin coolcoin CoolCoin * Api
Cross Coss Coss 1 Api
CREX24 crex24 CREX24 2 Api
Crypton Crypton Crypton 1 Api
Cryptopia cryptopia Cryptopia * Api
Deribit deribit Deribit 1 Api
Dsx Dsx Dsx 2 Api
Ethfinex ethfinex Ethfinex 1 Api
EXMO exmo EXMO 1 Api
EXX exx EXX * Api
FCoin fcoin FCoin 2 Api
FCoinJP fcoinjp FCoinJP 2 Api
FlowBTC flowbtc flowBTC 1 Api
FoxBit foxbit FoxBit 1 Api
FYB-SE fybse FYB-SE * Api
FYB-SG fybsg FYB-SG * Api
Gate.io gateium Gate.io 2 Api
GDAX gdax GDAX * Api
Gemini gemini Gemini 1 Api
GetBTC getbtc GetBTC * Api
HADAX hadax HADAX 1 Api
HitBTC hitbtc HitBTC 1 Api
GitBTC2 hitbtc2 HitBTC 2 Api
Huobi Pro huobipro Huobi Pro 1 Api
Huobi Russia huobiru Huobi Russia 1 Api
ICE3X ice3x ICE3X 1 Api
Independent Reserve independentreserve Independent Reserve * Api
INDODAX indodax INDODAX 1.8 Api
ItBit itbit itBit 1 Api
jubi.com jubi jubi.com 1 Api
KKEX kkex KKEX 2 Api
Kraken Kraken Kraken 0 Api
KuCoin kucoin KuCoin 2 Api
Kuna Kuna Kuna 2 Api
LakeBTC lakebtc LakeBTC 2 Api
LBank lbank LBank 1 Api
Liqui Liqui Liqui 3 Api
Liquid liquid Liquid 2 Api
LiveCoin livecoin LiveCoin * Api
Luno luno luno 1 Api
Lykke Lykke Lykke 1 Api
Bitcoin Market Market Bitcoin Market 3 Api
MixCoins mixcoins MixCoins 1 Api
NegocieCoins negociecoins NegocieCoins 3 Api
NovaExchange Nova Novaexchange 2 Api
OKCoin CNY okcoincny OKCoin CNY 1 Api
OKCoin USD okcoinusd OKCoin USD 1 Api
OKEX okex OKEX 1 Api
Paymium paymium Paymium 1 Api
Poloniex poloniex Poloniex * Api
QuadrigaCX quadrigacx QuadrigaCX 2 Api
RightBTC rightbtc RightBTC * Api
SouthXchange southxchange SouthXchange * Api
Stronghold Stronghold Stronghold 1 Api
SurBitcoin surbitcoin SurBitcoin 1 Api
The Ocean theocean The Ocean 1 Api
TheRockTrading therock TheRockTrading 1 Api
TideBit tidebit TideBit 2 Api
Tidex tidex Tidex 3 Api
Uex Uex Uex 1.0.3 Api
UPbit upbit Upbit 1 Api
UrduBit urdubit UrduBit 1 Api
Vaultoro vaultoro Vaultoro 1 Api
VBTC vbtc VBTC 1 Api
Virwox Virwox Virwox * Api
xBTCe xbtce xBTCe 1 Api
YoBit yobit YoBit 3 Api
Zaif zaif Zaif 1 Api
Zb Zb Zb 1 Api  

Php

You need the following modules installed in PHP:

  • cURL
  • mbstring (Recommended use of UTF-8)
  • Pcre
  • Iconv
  • Gmp (This is a PHP 7.2+ extension)

Installation

The easiest way to install the CCXT library is to use the package manager:

The library can be implemented in an all-in-one module with minimal dependencies and requirements:

  • js/ in JavaScript
  • python/ in Python (generated from JS)
  • php/ in PHP (generated from JS)

You can also clone it to your project directory from:

git clone https://github.com/ccxt/ccxt.git

Javascript

Npm

The JavaScript version of CCXT works in Node and browsers. You need ES6 and asyc/await support (Node 7.6.0+). When compiling with Webpack and Babel, make sure it is not excluded in the build-loder settings.

npm install ccxt

var ccxt ? require ('ccxt')

console.log (ccxt.exchanges) //shows all available exchanges

For use with the label <script>

 

<script type="”text/javascipt”" src="”https://unpkg.com/ccxt”"></script>

console.log (ccxt.exchanges) //shows all available exchanges

Python

 

pip install ccxt

import ccxt

print(ccxt.exchanges) #muestra a list of all available exchanges

The library supports concurrent asynchronous mode with asyncio and async/await in Python 3.5.3+

import ccxt.async_support as ccxt #enlaza to an asynchronous version of ccxt

Php

You need the following modules installed in PHP:

  • cURL
  • mbstring (Recommended use of UTF-8)
  • Pcre
  • Iconv
  • Gmp (This is a PHP 7.2+ extension)

Include "ccxt.php";

Var_dump (-ccxt-Exchange::$exchanges);           shows the list of all exchanges

Docker

CCXT can be installed in a container along with all supported languages and dependencies. This can be useful if you want to contribute to CCXT.

Using docker-compose (in CCXT cloned repository):

Docker-compose run –rm ccxt

Use

The CCXT library consists of a public part and a private part. Everyone can use the public part immediately upon finishing the installation.

Public APIs give access to exchange information without registering with a user account or having a key.

Public APIs include the following:

  • Market information.
  • Trading instruments/pairs.
  • Exchange ratios.
  • Order books.
  • Exchange history.
  • Tickers.
  • OHLC(V).
  • Other public points.

If you are interested in the exchange by means of APIs keys, you will need to obtain this through the exchange house website. This usually results in access through a user account. Some exchanges require personal identification and verification. In this case the process will be manual, the library will not create accounts or keys for you.

Private APIs allow the following:

  • Manage personal account information.
  • Account balances.
  • Deposits and withdrawals of fiat and crypto.
  • Personal inquiries.
  • Get the gistorial of the general ledger.
  • Transfers between accounts.
  • Use market services.

This library implements the entire public and private part of REST APIs for all exchanges. Implementations for WebSocket and FIX for Python, JavaScript, and PHP are coming.

The CCXT library supports Camel notation (preferred by JavaScript) and underscore notation (preferred for Python and PHP). All methods can be called in both notations.

both methods work in JavaScript/Python/PHP

exchange.methodName ()

exchange.method_name()

Javascript

'use strict';
const ccxt ? require ('ccxt');

(async function()
    let kraken ? new ccxt.kraken ()
    let bitfinex ? new ccxt.bitfinex ('verbose: true')
    let huobi ? new ccxt.huobi ()
    let okcoinusd ? new ccxt.okcoinusd (A)
        apiKey: 'YOUR_PUBLIC_API_KEY',
        secret: 'YOUR_SECRET_PRIVATE_KEY',
    })

const exchangeId ? 'binance'
        , exchangeClass - cc[exchangeId]xt
        , exchange - new exchangeClass ( .
            'apiKey': 'YOUR_API_KEY',
            'secret': 'YOUR_SECRET',
            'timeout': 30000,
            'enableRateLimit': true,
        })

console.log (kraken.id, await kraken.loadMarkets ())
    console.log (bitfinex.id, await bitfinex.loadMarkets ())
    console.log (huobi.id, await huobi.loadMarkets ())

console.log (kraken.id, await kraken.fetchOrderBook (kraken.sym[0]bols))
    console.log (bitfinex.id, await bitfinex.fetchTicker ('BTC/USD'))
    console.log (huobi.id, await huobi.fetchTrades ('ETH/CNY'))

console.log (okcoinusd.id, await okcoinusd.fetchBalance())

sell 1 BTC/USD for market price, sell a bitcoin for dollars immediately
    console.log (okcoinusd.id, await okcoinusd.createMarketSellOrder ('BTC/USD', 1))

buy 1 BTC/USD for $2500, you pay $2500 and receive ฿1 when the order is closed
    console.log (okcoinusd.id, await okcoinusd.createLimitBuyOrder ('BTC/USD', 1, 2500.00))

pass/redefine custom exchange-specific order params: type, amount, price or whatever
    use a custom order type
    bitfinex.createLimitSellOrder ('BTC/USD', 1, 10, 'type': 'trailing-stop')

}) ();

Python

• coding-utf-8

import ccxt

hitbtc ? ccxt.hitbtc('verbose': True)
bitmex ? ccxt.bitmex()
huobi - ccxt.huobi()
exmo - ccxt.exmo(-
    'apiKey': 'YOUR_PUBLIC_API_KEY',
    'secret': 'YOUR_SECRET_PRIVATE_KEY',
})
kraken - ccxt.kraken(-
    'apiKey': 'YOUR_PUBLIC_API_KEY',
    'secret': 'YOUR_SECRET_PRIVATE_KEY',
})

exchange_id 'binance'
exchange_class ? getattr(ccxt, exchange_id)
exchange - exchange_class(-
    'apiKey': 'YOUR_API_KEY',
    'secret': 'YOUR_SECRET',
    'timeout': 30000,
    'enableRateLimit': True,
})

hitbtc_markets ? hitbtc.load_markets()

print(hitbtc.id, hitbtc_markets)
print(bitmex.id, bitmex.load_markets())
print(huobi.id, huobi.load_markets())

print(hitbtc.fetch_order_book(hitbtc.symbols[0]))
print(bitmex.fetch_ticker('BTC/USD'))
print(huobi.fetch_trades('LTC/CNY'))

print(exmo.fetch_balance())

• sell one ฿ for market price and receive $ right now
print(exmo.id, exmo.create_market_sell_order('BTC/USD', 1))

Limit buy BTC/EUR, you pay .2500 and receive ฿1 when the order is closed
print(exmo.id, exmo.create_limit_buy_order('BTC/EUR', 1, 2500.00))

• pass/redefine custom exchange-specific order params: type, amount, price, flags, etc...
kraken.create_market_buy_order('BTC/USD', 1, ''trading_agreement': 'agree')

Php

include 'ccxt.php';

$poloniex - new -ccxt-poloniex ();
$bittrex . > .
$quoinex s/he/they
$zaif .
    'apiKey' > 'YOUR_PUBLIC_API_KEY',
    'secret' > 'YOUR_SECRET_PRIVATE_KEY',
));
$hitbtc .
    'apiKey' > 'YOUR_PUBLIC_API_KEY',
    'secret' > 'YOUR_SECRET_PRIVATE_KEY',
));

$exchange_id ? 'binance';
$exchange_class ? "-ccxt-$exchange_id";
$exchange - new $exchange_class (array (
    'apiKey' '> 'YOUR_API_KEY',
    'secret' > 'YOUR_SECRET',
    'timeout' '> 30000,
    'enableRateLimit' .> true,
));

$poloniex_markets ? $poloniex->load_markets ();

var_dump ($poloniex_markets);
var_dump ($bittrex->load_markets ());
var_dump ($quoinex->load_markets ());

var_dump ($poloniex->fetch_order_book ($poloniex->symbols));
var_dump ($bittrex->fetch_trades ('BTC/USD'[0]));
var_dump ($quoinex->fetch_ticker ('ETH/EUR'));
var_dump ($zaif->fetch_ticker ('BTC/JPY'));

var_dump ($zaif->fetch_balance ());

sell 1 BTC/JPY for market price, you pay and receive ฿ immediately
var_dump ($zaif->id, $zaif->create_market_sell_order ('BTC/JPY', 1));

buy BTC/JPY, you receive ฿1 for .285000 when the order closes
var_dump ($zaif->id, $zaif->create_limit_buy_order ('BTC/JPY', 1, 285000));

set a custom user-defined id to your order
$hitbtc->create_order ('BTC/USD', 'limit', 'buy', 1, 3000, array ('clientOrderId' ?> '123'));

Call Now ButtonLLámanos