CCXT – CryptoCurrency eXchange Trading Library

in #btc8 years ago (edited)


Code Issues 47 Pull requests 20 Projects 0 Wiki InsightsA JavaScript / Python / PHP cryptocurrency trading library with support for more than 90 bitcoin/altcoin exchangesaltcoinapiarbitragebitcoinbotcryptocurrencycryptoe-commerceethereumexchangeinvestlibrarystrategytradingbtcethtrademerchantmarket-data

  1. JavaScript 59.1%
  2. Python 26.1%
  3. PHP 14.8%

JavaScriptPythonPHPClone or download Create new fileUpload filesFind fileBranch: master New pull requestLatest commit a31be29 42 minutes ago Travis CI 1.10.709build1.10.70942 minutes agodoc1.10.7064 hours agoexamplescli: now handles 'params' arg2 days agojsUse the correct fetch for ServiceWorker2 hours agophp1.10.70942 minutes agopython1.10.70942 minutes agowiki1.10.7064 hours ago.eslintrceslint: allow symbol to be optional arg2 hours ago.gitattributeseol=lf in .gitattributes2 months ago.gitignore.gitignore: ignore vendor (PHP)28 days ago.npmignoreadded python and php to npmignore to minimize the footprint2 months ago.travis.ymltravis does not want to upload to pypi legacy url5 days agoCHANGELOG.mdupdated changelog2 months agoCONTRIBUTING.mdminor corrections to CONTRIBUTING.md2 days agoISSUE_TEMPLATE.mdminor edit to ISSUE_TEMPLATE.md3 days agoLICENSE.txt#106 removed whitespace from LICENSE.txt5 months agoREADME.md1.10.7064 hours agoappveyor.ymlPHP stuff for appveyor5 days agoccxt.browser.jsremoved references to ccxt.es5.js from anywhere I could find (example…4 months agoccxt.d.ts1.10.6762 days agoccxt.js1.10.70942 minutes agoccxt.phpccxt: drop unused25 days agocomposer.jsonfix #876, fix#862, fix#89127 days agocomposer.lockcomposer: PSR4 autoloader28 days agoconvert-md-2-rstvss paths + refactoring3 months agocountries.jsvc shorter definitiona month agoexample.jsadded clarifying comment about runkit to example.js9 days agoexport-exchanges.jsexport-exchanges.js: fix due to path change28 days agokeys.jsonMerge branch 'okerrors' of https://github.com/mkutny/ccxt into mkutny…a day agopackage.json1.10.70942 minutes agopush-wiki.shupdated repo urls in push*.sh3 months agopush.shshould improve tag descriptions readbility2 months agorun-tests.jsclear error logging for bitfinex gzipped responses #4412 months agosetup.cfgadded tox flake8 cd .. and python bitfinex example2 months agotranspile.jsbinance fetchTickers → fetchBidsAsks, fetchFullTickers → fetchTickers #…2 hours agoupdate-badges.jsupdate-badges Windows fix #4452 months agovss.jsccxt: drop unused25 days ago

README.md

CCXT – CryptoCurrency eXchange Trading Library

     A JavaScript / Python / PHP library for cryptocurrency trading and e-commerce with support for many bitcoin/ether/altcoin exchange markets and merchant APIs.The CCXT library is used to connect and trade with cryptocurrency / altcoin exchanges and payment processing services worldwide. It provides quick access to market data for storage, analysis, visualization, indicator development, algorithmic trading, strategy backtesting, bot programming, webshop integration and related software engineering.It is intended to be used by coders, developers, technically-skilled traders, data-scientists and financial analysts for building trading algorithms on top of it.Current feature list:

  • support for many exchange markets, even more upcoming soon
  • fully implemented public and private APIs for all exchanges
  • all currencies, altcoins and symbols, prices, order books, trades, tickers, etc...
  • optional normalized data for cross-exchange or cross-currency analytics and arbitrage
  • an out-of-the box unified all-in-one API extremely easy to integrate
  • works in Node 7.6+, Python 2 and 3, PHP 5.3+, web browsers

ccxt on GitHub | Install | Usage | Manual | Examples | Changelog | Contributing

Supported Cryptocurrency Exchange Markets

The ccxt library currently supports the following 98 cryptocurrency exchange markets and trading APIs:idnameverdoccountries_1broker1Broker2APIUS_1btcxe1BTCXE*APIPanamaacxACX2APIAustraliaallcoinAllcoin1APICanadaanxproANXPro2APIJapan, Singapore, Hong Kong, New ZealandbiboxBibox1APIChina, US, South KoreabinanceBinance*APIJapanbit2cBit2C*APIIsraelbitbayBitBay*APIPoland, EUbitcoincoidBitcoin.co.id1.7APIIndonesiabitfinexBitfinex1APIBritish Virgin Islandsbitfinex2Bitfinex v22APIBritish Virgin IslandsbitflyerbitFlyer1APIJapanbithumbBithumb*APISouth KoreabitlishBitlish1APIUK, EU, RussiabitmarketBitMarket*APIPoland, EUbitmexBitMEX1APISeychellesbitsoBitso3APIMexicobitstampBitstamp2APIUKbitstamp1Bitstamp v11APIUKbittrexBittrex1.1APIUSbl3pBL3P1APINetherlands, EUbleutradeBleutrade2APIBrazilbraziliexBraziliex*APIBrazilbtcboxBtcBox1APIJapanbtcchinaBTCChina1APIChinabtcexchangeBTCExchange*APIPhilippinesbtcmarketsBTC Markets*APIAustraliabtctradeuaBTC Trade UA*APIUkrainebtcturkBTCTurk*APITurkeybtcxBTCX1APIIceland, US, EUbterBter2APIBritish Virgin Islands, ChinabxinthBX.in.th*APIThailandccexC-CEX*APIGermany, EUcexCEX.IO*APIUK, EU, Cyprus, RussiachbtcCHBTC1APIChinachilebitChileBit1APIChilecoincheckcoincheck*APIJapan, IndonesiacoinexchangeCoinExchange*APIIndia, Japan, South Korea, Vietnam, UScoinfloorcoinfloor*APIUKcoingiCoingi*APIPanama, Bulgaria, China, UScoinmarketcapCoinMarketCap1APIUScoinmateCoinMate*APIUK, Czech Republic, EUcoinsecureCoinsecure1APIIndiacoinspotCoinSpot*APIAustraliacryptopiaCryptopia*APINew ZealanddsxDSX3APIUKexmoEXMO1APISpain, RussiaflowbtcflowBTC1APIBrazilfoxbitFoxBit1APIBrazilfybseFYB-SE*APISwedenfybsgFYB-SG*APISingaporegatecoinGatecoin*APIHong KonggateioGate.io2APIChinagdaxGDAX*APIUSgeminiGemini1APIUSgetbtcGetBTC*APISt. Vincent & Grenadines, RussiahitbtcHitBTC1APIUKhitbtc2HitBTC v22APIUKhuobiHuobi3APIChinahuobicnyHuobi CNY1APIChinahuobiproHuobi Pro1APIChinaindependentreserveIndependent Reserve*APIAustralia, New ZealanditbititBit1APIUSjubijubi.com1APIChinakrakenKraken0APIUSkucoinKucoin1APIHong KongkunaKuna2APIUkrainelakebtcLakeBTC2APIUSliquiLiqui3APIUkrainelivecoinLiveCoin*APIUS, UK, Russialunoluno1APIUK, Singapore, South AfricalykkeLykke1APISwitzerlandmercadoMercado Bitcoin3APIBrazilmixcoinsMixCoins1APIUK, Hong KongnovaNovaexchange2APITanzaniaokcoincnyOKCoin CNY1APIChinaokcoinusdOKCoin USD1APIChina, USokexOKEX1APIChina, USpaymiumPaymium1APIFrance, EUpoloniexPoloniex*APIUSqryptosQRYPTOS2APIChina, TaiwanquadrigacxQuadrigaCX2APICanadaquoineQUOINE2APIJapan, Singapore, VietnamsouthxchangeSouthXchange*APIArgentinasurbitcoinSurBitcoin1APIVenezuelatherockTheRockTrading1APIMaltatidexTidex3APIUKurdubitUrduBit1APIPakistanvaultoroVaultoro1APISwitzerlandvbtcVBTC1APIVietnamvirwoxVirWoX*APIAustria, EUwexWEX3APINew ZealandxbtcexBTCe1APIRussiayobitYoBit3APIRussiayunbiYUNBI2APIChinazaifZaif1APIJapanzbZB1APIChinaThe list above is updated frequently, new crypto markets, altcoin exchanges, bug fixes, API endpoints are introduced and added on a regular basis. See the Manual for details. If you don't find a cryptocurrency exchange market in the list above and/or want another exchange to be added, post or send us a link to it by opening an issue here on GitHub or via email.The library is under MIT license, that means it's absolutely free for any developer to build commercial and opensource software on top of it, but use it at your own risk with no warranties, as is.

Install

The easiest way to install the ccxt library is to use builtin package managers:

This library is shipped as an all-in-one module implementation with minimalistic dependencies and requirements:

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

You can also clone it into your project directory from ccxt GitHub repository:

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

An alternative way of installing this library into your code is to copy a single file manually into your working directory with language extension appropriate for your environment.

JavaScript (NPM)

JavaScript version of CCXT works both in Node and web browsers. Requires ES6 and async/await syntax support (Node 7.6.0+). When compiling with Webpack and Babel, make sure it is not excluded in your babel-loader config.ccxt in NPM

npm install ccxt
var ccxt = require ('ccxt')



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

JavaScript (for use with the <script> tag):

All-in-one browser bundle (dependencies included), served from unpkg CDN, which is a fast, global content delivery network for everything on NPM.

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

Creates a global ccxt object:

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

Python

ccxt in PyPI

pip install ccxt
import ccxt

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

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

import ccxt.async as ccxt # link against the asynchronous version of ccxt

PHP

The ccxt library in PHP: ccxt.phpIt requires common PHP modules:

  • cURL
  • mbstring (using UTF-8 is highly recommended)
  • PCRE
  • iconv
include "ccxt.php";

var_dump (\ccxt\Exchange::$exchanges); // print a list of all available exchange classes

Documentation

Read the Manual for more details.

Usage

Intro

The ccxt library consists of a public part and a private part. Anyone can use the public part out-of-the-box immediately after installation. Public APIs open access to public information from all exchange markets without registering user accounts and without having API keys.Public APIs include the following:

  • market data
  • instruments/trading pairs
  • price feeds (exchange rates)
  • order books
  • trade history
  • tickers
  • OHLC(V) for charting
  • other public endpoints

For trading with private APIs you need to obtain API keys from/to exchange markets. It often means registering with exchanges and creating API keys with your account. Most exchanges require personal info or identification. Some kind of verification may be necessary as well. If you want to trade you need to register yourself, this library will not create accounts or API keys for you. Some exchange APIs expose interface methods for registering an account from within the code itself, but most of exchanges don't. You have to sign up and create API keys with their websites.Private APIs allow the following:

  • manage personal account info
  • query account balances
  • trade by making market and limit orders
  • deposit and withdraw fiat and crypto funds
  • query personal orders
  • get ledger history
  • transfer funds between accounts
  • use merchant services

This library implements full public and private REST APIs for all exchanges. WebSocket and FIX implementations in JavaScript, PHP, Python and other languages coming soon.The ccxt library supports both camelcase notation (preferred in JavaScript) and underscore notation (preferred in Python and PHP), therefore all methods can be called in either notation or coding style in any language.

// both of these notations work in JavaScript/Python/PHP

exchange.methodName ()  // camelcase pseudocode

exchange.method_name () // underscore pseudocode

Read the Manual for more details.

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 ({

        apiKey: 'YOUR_PUBLIC_API_KEY',

        secret: 'YOUR_SECRET_PRIVATE_KEY',

    })



    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.symbols[0]))

    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',

})



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  = new \ccxt\bittrex  (array ('verbose' => true));

$quoine   = new \ccxt\quoine   ();

$zaif     = new \ccxt\zaif     (array (

    'apiKey' => 'YOUR_PUBLIC_API_KEY',

    'secret' => 'YOUR_SECRET_PRIVATE_KEY',

));



$poloniex_markets = $poloniex->load_markets ();



var_dump ($poloniex_markets);

var_dump ($bittrex->load_markets ());

var_dump ($quoine->load_markets ());



var_dump ($poloniex->fetch_order_book ($poloniex->symbols[0]));

var_dump ($bittrex->fetch_trades ('BTC/USD'));

var_dump ($quoine->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'));

Contributing

Please read the CONTRIBUTING document before making changes that you would like adopted in the code. Also, read the Manual for more details.

Support Developer Team

We are investing a significant amount of time into the development of this library. If CCXT made your life easier and you like it and want to help us improve it further or if you want to speed up new features and exchanges, please, support us with a tip. We appreciate all contributions!

Sponsors

Become our sponsor and get your logo on our Github page with a link to your site.

Supporters

Become our supporter with a monthly payment and get your nick/link on our GitHub page.

Backers

Become a backer with a small monthly donation and help us continue our activities.