@jmparsons/ccxt
Version:
A JavaScript / Python / PHP cryptocurrency trading library with support for 100+ exchanges
272 lines (247 loc) • 160 kB
Markdown
# Overview
The ccxt library is a collection of available crypto *exchanges* or exchange classes. Each class implements the public and private API for a particular crypto exchange. All exchanges are derived from the base Exchange class and share a set of common methods. To access a particular exchange from ccxt library you need to create an instance of corresponding exchange class. Supported exchanges are updated frequently and new exchanges are added regularly.
The structure of the library can be outlined as follows:
```
User
+-------------------------------------------------------------+
| CCXT |
+------------------------------+------------------------------+
| Public | Private |
+=============================================================+
│ . |
│ The Unified CCXT API |
│ . |
| loadMarkets . fetchBalance |
| fetchMarkets . createOrder |
| fetchTicker . cancelOrder |
| fetchTickers . fetchOrder |
| fetchOrderBook . fetchOrders |
| fetchOHLCV . fetchOpenOrders |
| fetchTrades . fetchClosedOrders |
| . fetchMyTrades |
| . deposit |
| . withdraw |
│ . |
+=============================================================+
│ . |
| Custom Exchange API |
| (Derived Classes) |
│ . |
| publicGet... . privateGet... |
| publicPost... . privatePost... |
| . privatePut... |
| . privateDelete... |
| . sign |
│ . |
+=============================================================+
│ . |
| Base Exchange Class |
│ . |
+=============================================================+
```
Full public and private HTTP REST APIs for all exchanges are implemented. WebSocket and FIX implementations in JavaScript, PHP, Python and other languages coming soon.
- [Exchanges](#exchanges)
- [Markets](#markets)
- [API Methods / Endpoints](#api-methods--endpoints)
- [Market Data](#market-data)
- [Trading](#trading)
# Exchanges
The ccxt library currently supports the following 115 cryptocurrency exchange markets and trading APIs:
| | id | name | ver | doc | countries |
|---------------------------------------------------------------------------------------------------------------------------|--------------------|------------------------------------------------------------------------------|:---:|:--------------------------------------------------------------------------------------------:|-----------------------------------------|
| | _1broker | [1Broker](https://1broker.com) | 2 | [API](https://1broker.com/?c=en/content/api-documentation) | US |
| | _1btcxe | [1BTCXE](https://1btcxe.com) | * | [API](https://1btcxe.com/api-docs.php) | Panama |
| | acx | [ACX](https://acx.io) | 2 | [API](https://acx.io/documents/api_v2) | Australia |
| | allcoin | [Allcoin](https://www.allcoin.com) | 1 | [API](https://www.allcoin.com/About/APIReference) | Canada |
| | anxpro | [ANXPro](https://anxpro.com) | 2 | [API](http://docs.anxv2.apiary.io) | Japan, Singapore, Hong Kong, New Zealand|
| | bibox | [Bibox](https://www.bibox.com) | 1 | [API](https://github.com/Biboxcom/api_reference/wiki/home_en) | China, US, South Korea |
| | binance | [Binance](https://www.binance.com) | * | [API](https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md) | Japan |
| | bit2c | [Bit2C](https://www.bit2c.co.il) | * | [API](https://www.bit2c.co.il/home/api) | Israel |
| | bitbank | [bitbank](https://bitbank.cc/) | 1 | [API](https://docs.bitbank.cc/) | Japan |
| | bitbay | [BitBay](https://bitbay.net) | * | [API](https://bitbay.net/public-api) | Poland, EU |
| | bitfinex | [Bitfinex](https://www.bitfinex.com) | 1 | [API](https://bitfinex.readme.io/v1/docs) | British Virgin Islands |
| | bitfinex2 | [Bitfinex v2](https://www.bitfinex.com) | 2 | [API](https://bitfinex.readme.io/v2/docs) | British Virgin Islands |
| | bitflyer | [bitFlyer](https://bitflyer.jp) | 1 | [API](https://bitflyer.jp/API) | Japan |
| | bithumb | [Bithumb](https://www.bithumb.com) | * | [API](https://www.bithumb.com/u1/US127) | South Korea |
| | bitkk | [bitkk](https://www.bitkk.com) | 1 | [API](https://www.bitkk.com/i/developer) | China |
| | bitlish | [Bitlish](https://bitlish.com) | 1 | [API](https://bitlish.com/api) | UK, EU, Russia |
| | bitmarket | [BitMarket](https://www.bitmarket.pl) | * | [API](https://www.bitmarket.net/docs.php?file=api_public.html) | Poland, EU |
| | bitmex | [BitMEX](https://www.bitmex.com) | 1 | [API](https://www.bitmex.com/app/apiOverview) | Seychelles |
| | bitso | [Bitso](https://bitso.com) | 3 | [API](https://bitso.com/api_info) | Mexico |
| | bitstamp | [Bitstamp](https://www.bitstamp.net) | 2 | [API](https://www.bitstamp.net/api) | UK |
| | bitstamp1 | [Bitstamp v1](https://www.bitstamp.net) | 1 | [API](https://www.bitstamp.net/api) | UK |
| | bittrex | [Bittrex](https://bittrex.com) | 1.1 | [API](https://bittrex.com/Home/Api) | US |
| | bitz | [Bit-Z](https://www.bit-z.com) | 1 | [API](https://www.bit-z.com/api.html) | Hong Kong |
| | bl3p | [BL3P](https://bl3p.eu) | 1 | [API](https://github.com/BitonicNL/bl3p-api/tree/master/docs) | Netherlands, EU |
| | bleutrade | [Bleutrade](https://bleutrade.com) | 2 | [API](https://bleutrade.com/help/API) | Brazil |
| | braziliex | [Braziliex](https://braziliex.com/) | * | [API](https://braziliex.com/exchange/api.php) | Brazil |
| | btcbox | [BtcBox](https://www.btcbox.co.jp/) | 1 | [API](https://www.btcbox.co.jp/help/asm) | Japan |
| | btcchina | [BTCChina](https://www.btcchina.com) | 1 | [API](https://www.btcchina.com/apidocs) | China |
| | btcexchange | [BTCExchange](https://www.btcexchange.ph) | * | [API](https://github.com/BTCTrader/broker-api-docs) | Philippines |
| | btcmarkets | [BTC Markets](https://btcmarkets.net/) | * | [API](https://github.com/BTCMarkets/API) | Australia |
| | btctradeim | [BtcTrade.im](https://www.btctrade.im) | * | [API](https://www.btctrade.im/help.api.html) | Hong Kong |
| | btctradeua | [BTC Trade UA](https://btc-trade.com.ua) | * | [API](https://docs.google.com/document/d/1ocYA0yMy_RXd561sfG3qEPZ80kyll36HUxvCRe5GbhE/edit) | Ukraine |
| | btcturk | [BTCTurk](https://www.btcturk.com) | * | [API](https://github.com/BTCTrader/broker-api-docs) | Turkey |
| | btcx | [BTCX](https://btc-x.is) | 1 | [API](https://btc-x.is/custom/api-document.html) | Iceland, US, EU |
| | bxinth | [BX.in.th](https://bx.in.th) | * | [API](https://bx.in.th/info/api) | Thailand |
| | ccex | [C-CEX](https://c-cex.com) | * | [API](https://c-cex.com/?id=api) | Germany, EU |
| | cex | [CEX.IO](https://cex.io) | * | [API](https://cex.io/cex-api) | UK, EU, Cyprus, Russia |
| | chbtc | [CHBTC](https://trade.chbtc.com/api) | 1 | [API](https://www.chbtc.com/i/developer) | China |
| | chilebit | [ChileBit](https://chilebit.net) | 1 | [API](https://blinktrade.com/docs) | Chile |
| | cobinhood | [COBINHOOD](https://cobinhood.com) | * | [API](https://cobinhood.github.io/api-public) | Taiwan |
| | coincheck | [coincheck](https://coincheck.com) | * | [API](https://coincheck.com/documents/exchange/api) | Japan, Indonesia |
| | coinegg | [CoinEgg](https://www.coinegg.com) | * | [API](https://www.coinegg.com/explain.api.html) | China, UK |
| | coinex | [CoinEx](https://www.coinex.com) | 1 | [API](https://github.com/coinexcom/coinex_exchange_api/wiki) | China |
| | coinexchange | [CoinExchange](https://www.coinexchange.io) | * | [API](https://coinexchangeio.github.io/slate/) | India, Japan, South Korea, Vietnam, US |
| | coinfloor | [coinfloor](https://www.coinfloor.co.uk) | * | [API](https://github.com/coinfloor/api) | UK |
| | coingi | [Coingi](https://coingi.com) | * | [API](http://docs.coingi.apiary.io/) | Panama, Bulgaria, China, US |
| | coinmarketcap | [CoinMarketCap](https://coinmarketcap.com) | 1 | [API](https://coinmarketcap.com/api) | US |
| | coinmate | [CoinMate](https://coinmate.io) | * | [API](http://docs.coinmate.apiary.io) | UK, Czech Republic, EU |
| | coinnest | [coinnest](https://www.coinnest.co.kr) | * | [API](https://www.coinnest.co.kr/doc/intro.html) | South Korea |
| | coinone | [CoinOne](https://coinone.co.kr) | 2 | [API](https://doc.coinone.co.kr) | South Korea |
| | coinsecure | [Coinsecure](https://coinsecure.in) | 1 | [API](https://api.coinsecure.in) | India |
| | coinspot | [CoinSpot](https://www.coinspot.com.au) | * | [API](https://www.coinspot.com.au/api) | Australia |
| | cointiger | [CoinTiger](https://www.cointiger.com/exchange/register.html?refCode=FfvDtt) | 1 | [API](https://github.com/cointiger/api-docs-en/wiki) | China |
| | coolcoin | [CoolCoin](https://www.coolcoin.com) | * | [API](https://www.coolcoin.com/help.api.html) | Hong Kong |
| | cryptopia | [Cryptopia](https://www.cryptopia.co.nz/Register?referrer=kroitor) | * | [API](https://www.cryptopia.co.nz/Forum/Category/45) | New Zealand |
| | dsx | [DSX](https://dsx.uk) | 3 | [API](https://api.dsx.uk) | UK |
| | ethfinex | [Ethfinex](https://www.ethfinex.com) | 1 | [API](https://bitfinex.readme.io/v1/docs) | British Virgin Islands |
| | exmo | [EXMO](https://exmo.me/?ref=131685) | 1 | [API](https://exmo.me/en/api_doc?ref=131685) | Spain, Russia |
| | exx | [EXX](https://www.exx.com/) | * | [API](https://www.exx.com/help/restApi) | China |
| | flowbtc | [flowBTC](https://trader.flowbtc.com) | 1 | [API](http://www.flowbtc.com.br/api/) | Brazil |
| | foxbit | [FoxBit](https://foxbit.exchange) | 1 | [API](https://blinktrade.com/docs) | Brazil |
| | fybse | [FYB-SE](https://www.fybse.se) | * | [API](http://docs.fyb.apiary.io) | Sweden |
| | fybsg | [FYB-SG](https://www.fybsg.com) | * | [API](http://docs.fyb.apiary.io) | Singapore |
| | gatecoin | [Gatecoin](https://gatecoin.com) | * | [API](https://gatecoin.com/api) | Hong Kong |
| | gateio | [Gate.io](https://gate.io/) | 2 | [API](https://gate.io/api2) | China |
| | gdax | [GDAX](https://www.gdax.com) | * | [API](https://docs.gdax.com) | US |
| | gemini | [Gemini](https://gemini.com) | 1 | [API](https://docs.gemini.com/rest-api) | US |
| | getbtc | [GetBTC](https://getbtc.org) | * | [API](https://getbtc.org/api-docs.php) | St. Vincent & Grenadines, Russia |
| | hadax | [HADAX](https://www.hadax.com) | 1 | [API](https://github.com/huobiapi/API_Docs/wiki) | China |
| | hitbtc | [HitBTC](https://hitbtc.com) | 1 | [API](https://github.com/hitbtc-com/hitbtc-api/blob/master/APIv1.md) | Hong Kong |
| | hitbtc2 | [HitBTC v2](https://hitbtc.com/?ref_id=5a5d39a65d466) | 2 | [API](https://api.hitbtc.com) | Hong Kong |
| | huobi | [Huobi](https://www.huobi.com) | 3 | [API](https://github.com/huobiapi/API_Docs_en/wiki) | China |
| | huobicny | [Huobi CNY](https://www.huobi.com) | 1 | [API](https://github.com/huobiapi/API_Docs/wiki/REST_api_reference) | China |
| | huobipro | [Huobi Pro](https://www.huobipro.com) | 1 | [API](https://github.com/huobiapi/API_Docs/wiki/REST_api_reference) | China |
| | ice3x | [ICE3X](https://ice3x.com) | * | [API](https://ice3x.co.za/ice-cubed-bitcoin-exchange-api-documentation-1-june-2017) | South Africa |
| | independentreserve | [Independent Reserve](https://www.independentreserve.com) | * | [API](https://www.independentreserve.com/API) | Australia, New Zealand |
| | indodax | [INDODAX](https://www.indodax.com) | 1.7 | [API](https://indodax.com/downloads/BITCOINCOID-API-DOCUMENTATION.pdf) | Indonesia |
| | itbit | [itBit](https://www.itbit.com) | 1 | [API](https://api.itbit.com/docs) | US |
| | jubi | [jubi.com](https://www.jubi.com) | 1 | [API](https://www.jubi.com/help/api.html) | China |
| | kraken | [Kraken](https://www.kraken.com) | 0 | [API](https://www.kraken.com/en-us/help/api) | US |
| | kucoin | [Kucoin](https://www.kucoin.com/?r=E5wkqe) | 1 | [API](https://kucoinapidocs.docs.apiary.io) | Hong Kong |
| | kuna | [Kuna](https://kuna.io) | 2 | [API](https://kuna.io/documents/api) | Ukraine |
| | lakebtc | [LakeBTC](https://www.lakebtc.com) | 2 | [API](https://www.lakebtc.com/s/api_v2) | US |
| | lbank | [LBank](https://www.lbank.info) | 1 | [API](https://www.lbank.info/api/api-overview) | China |
| | liqui | [Liqui](https://liqui.io) | 3 | [API](https://liqui.io/api) | Ukraine |
| | livecoin | [LiveCoin](https://www.livecoin.net) | * | [API](https://www.livecoin.net/api?lang=en) | US, UK, Russia |
| | luno | [luno](https://www.luno.com) | 1 | [API](https://www.luno.com/en/api) | UK, Singapore, South Africa |
| | lykke | [Lykke](https://www.lykke.com) | 1 | [API](https://hft-api.lykke.com/swagger/ui/) | Switzerland |
| | mercado | [Mercado Bitcoin](https://www.mercadobitcoin.com.br) | 3 | [API](https://www.mercadobitcoin.com.br/api-doc) | Brazil |
| | mixcoins | [MixCoins](https://mixcoins.com) | 1 | [API](https://mixcoins.com/help/api/) | UK, Hong Kong |
| | negociecoins | [NegocieCoins](https://www.negociecoins.com.br) | 3 | [API](https://www.negociecoins.com.br/documentacao-tradeapi) | Brazil |
| | nova | [Novaexchange](https://novaexchange.com) | 2 | [API](https://novaexchange.com/remote/faq) | Tanzania |
| | okcoincny | [OKCoin CNY](https://www.okcoin.cn) | 1 | [API](https://www.okcoin.cn/rest_getStarted.html) | China |
| | okcoinusd | [OKCoin USD](https://www.okcoin.com) | 1 | [API](https://www.okcoin.com/rest_getStarted.html) | China, US |
| | okex | [OKEX](https://www.okex.com) | 1 | [API](https://github.com/okcoin-okex/API-docs-OKEx.com) | China, US |
| | paymium | [Paymium](https://www.paymium.com) | 1 | [API](https://github.com/Paymium/api-documentation) | France, EU |
| | poloniex | [Poloniex](https://poloniex.com) | * | [API](https://poloniex.com/support/api/) | US |
| | qryptos | [QRYPTOS](https://www.qryptos.com) | 2 | [API](https://developers.quoine.com) | China, Taiwan |
| | quadrigacx | [QuadrigaCX](https://www.quadrigacx.com) | 2 | [API](https://www.quadrigacx.com/api_info) | Canada |
| | quoinex | [QUOINEX](https://quoinex.com/) | 2 | [API](https://developers.quoine.com) | Japan, Singapore, Vietnam |
| | southxchange | [SouthXchange](https://www.southxchange.com) | * | [API](https://www.southxchange.com/Home/Api) | Argentina |
| | surbitcoin | [SurBitcoin](https://surbitcoin.com) | 1 | [API](https://blinktrade.com/docs) | Venezuela |
| | therock | [TheRockTrading](https://therocktrading.com) | 1 | [API](https://api.therocktrading.com/doc/v1/index.html) | Malta |
| | tidebit | [TideBit](https://www.tidebit.com) | 2 | [API](https://www.tidebit.com/documents/api_v2) | Hong Kong |
| | tidex | [Tidex](https://tidex.com) | 3 | [API](https://tidex.com/exchange/public-api) | UK |
| | urdubit | [UrduBit](https://urdubit.com) | 1 | [API](https://blinktrade.com/docs) | Pakistan |
| | vaultoro | [Vaultoro](https://www.vaultoro.com) | 1 | [API](https://api.vaultoro.com) | Switzerland |
| | vbtc | [VBTC](https://vbtc.exchange) | 1 | [API](https://blinktrade.com/docs) | Vietnam |
| | virwox | [VirWoX](https://www.virwox.com) | * | [API](https://www.virwox.com/developers.php) | Austria, EU |
| | wex | [WEX](https://wex.nz) | 3 | [API](https://wex.nz/api/3/docs) | New Zealand |
| | xbtce | [xBTCe](https://www.xbtce.com) | 1 | [API](https://www.xbtce.com/tradeapi) | Russia |
| | yobit | [YoBit](https://www.yobit.net) | 3 | [API](https://www.yobit.net/en/api/) | Russia |
| | yunbi | [YUNBI](https://yunbi.com) | 2 | [API](https://yunbi.com/documents/api/guide) | China |
| | zaif | [Zaif](https://zaif.jp) | 1 | [API](http://techbureau-api-document.readthedocs.io/ja/latest/index.html) | Japan |
| | zb | [ZB](https://www.zb.com) | 1 | [API](https://www.zb.com/i/developer) | China |
Besides making basic market and limit orders, some exchanges offer margin trading (leverage), various derivatives (like futures contracts and options) and also have [dark pools](https://en.wikipedia.org/wiki/Dark_pool), [OTC](https://en.wikipedia.org/wiki/Over-the-counter_(finance)) (over-the-counter trading), merchant APIs and much more.
## Instantiation
To connect to an exchange and start trading you need to instantiate an exchange class from ccxt library.
To get the full list of ids of supported exchanges programmatically:
```JavaScript
// JavaScript
const ccxt = require ('ccxt')
console.log (ccxt.exchanges)
```
```Python
# Python
import ccxt
print (ccxt.exchanges)
```
```PHP
// PHP
include 'ccxt.php';
var_dump (\ccxt\Exchange::$exchanges);
```
An exchange can be instantiated like shown in the examples below:
```JavaScript
// JavaScript
const ccxt = require ('ccxt')
let exchange = new ccxt.kraken () // default id
let kraken1 = new ccxt.kraken ({ id: 'kraken1' })
let kraken2 = new ccxt.kraken ({ id: 'kraken2' })
let id = 'gdax'
let gdax = new ccxt[id] ();
```
```Python
# Python
import ccxt
exchange = ccxt.okcoinusd () # default id
okcoin1 = ccxt.okcoinusd ({ 'id': 'okcoin1' })
okcoin2 = ccxt.okcoinusd ({ 'id': 'okcoin2' })
id = 'btcchina'
btcchina = eval ('ccxt.%s ()' % id)
gdax = getattr (ccxt, 'gdax') ()
```
The ccxt library in PHP uses builtin UTC/GMT time functions, therefore you are required to set date.timezone in your php.ini or call [date_default_timezone_set ()](http://php.net/manual/en/function.date-default-timezone-set.php) function before using the PHP version of the library. The recommended timezone setting is `"UTC"`.
```PHP
// PHP
date_default_timezone_set ('UTC');
include 'ccxt.php';
$bitfinex = new \ccxt\bitfinex (); // default id
$bitfinex1 = new \ccxt\bitfinex (array ('id' => 'bitfinex1'));
$bitfinex2 = new \ccxt\bitfinex (array ('id' => 'bitfinex2'));
$id = 'kraken';
$exchange = '\\ccxt\\' . $id
$kraken = new $exchange ();
```
## Exchange Structure
Every exchange has a set of properties and methods, most of which you can override by passing an associative array of params to an exchange constructor. You can also make a subclass and override everything.
Here's an overview of base exchange properties with values added for example:
```JavaScript
{
'id': 'exchange' // lowercase string exchange id
'name': 'Exchange' // human-readable string
'countries': [ 'US', 'CN', 'EU' ], // string or array of ISO country codes
'urls': {
'api': 'https://api.example.com/data', // string or dictionary of base API URLs
'www': 'https://www.example.com' // string website URL
'doc': 'https://docs.example.com/api', // string URL or array of URLs
},
'version': 'v1', // string ending with digits
'api': { ... }, // dictionary of api endpoints
'has': { // exchange capabilities
'CORS': false,
'publicAPI': true,
'privateAPI': true,
'cancelOrder': true,
'createDepositAddress': false,
'createOrder': true,
'deposit': false,
'fetchBalance': true,
'fetchClosedOrders': false,
'fetchCurrencies': false,
'fetchDepositAddress': false,
'fetchMarkets': true,
'fetchMyTrades': false,
'fetchOHLCV': false,