Skip to content

Install

Travis CI User edited this page May 21, 2024 · 9647 revisions

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:

You can also clone it into your project directory from ccxt GitHub repository and copy files manually into your working directory with language extension appropriate for your environment.

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

An alternative way of installing this library is to build a custom bundle from source. Choose exchanges you need in exchanges.cfg.

JavaScript (NPM)

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

ccxt crypto trading library 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 a CDN of your choice:

You can obtain a live-updated version of the bundle by removing the version number from the URL (the @a.b.c thing) or the /latest/ on our cdn — however, we do not recommend to do that, as it may break your app eventually. Also, please keep in mind that we are not responsible for the correct operation of those CDN servers.

<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/ccxt@4.3.29/dist/ccxt.browser.min.js"></script>

We also provide webpack minified and tree-shaken versions of the library starting from version 3.0.35 - Visit https://cdn.ccxt.com to browse the prebundled versions we distribute.

name size
binance.min.js ~300kb
bitget.min.js ~200kb
bitmart.min.js ~200kb
bybit.min.js ~300kb
ccxt.min.js ~3mb
huobi.min.js ~300kb
kucoin.min.js ~200kb
mexc.min.js ~200kb
okx.min.js ~250kb

Note: the file sizes are subject to change.

<script type="text/javascript" src="https://cdn.ccxt.com/3.0.35/ccxt.min.js"></script>

Here is an example using a custom bybit bundle from our cdn in the browser

<html>
<head>
<script type="text/javascript" src="https://cdn.ccxt.com/latest/bybit.min.js"></script>
<script>
async function update () {
    const bid = document.querySelector ('#bid')
    const ask = document.querySelector ('#ask')
    const updates = document.querySelector ('#updates')

    const bybit = new ccxt.pro.bybit ()
    window.bybit = bybit
    const ticker = await bybit.fetchTicker ('BTC/USDT:USDT')
    bid.innerText = ticker.bid.toFixed (2)
    ask.innerText = ticker.ask.toFixed (2)
    while (true) {
        const trades = await bybit.watchTrades ('BTC/USDT:USDT')
        // const trades = await bybit.fetchTrades ('BTC/USDT:USDT', 1)
        const trade = trades[0]

        const notify = document.createElement ('li')
        notify.innerHTML = `<strong>${trade.datetime.slice (11, 19)}</strong> &nbsp; ${trade.amount.toFixed (3)} btc was bought at ${trade.price.toFixed (1)}`
        notify.style = 'padding-top: 8px;'
        updates.appendChild (notify)
    }
}
</script>
</head>

<body onload="update()">
<h3>The current bitcoin bid on bybit is <span id="bid"></span><br><br>and the best ask is <span id="ask"></span></h3>
<ul id="updates" style="color: red;"></ul>
</body>
</html>

The default entry point for the browser is window.ccxt and it creates a global ccxt object:

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

Custom JavaScript Builds

It takes time to load all scripts and resources. The problem with in-browser usage is that the entire CCXT library weighs a few megabytes which is a lot for a web application. Sometimes it is also critical for a Node app. Therefore to lower the loading time you might want to make your own custom build of CCXT for your app with just the exchanges you need. CCXT uses webpack to remove dead code paths to make the package smaller.

Follow these steps:

# 1. clone the repository

git clone --depth 1 https://github.com/ccxt/ccxt.git

# 2. go to the cloned repository

cd ccxt

# 3. install dependencies

npm install

# 4. edit exchanges.cfg for the exchanges of your interest

echo -e "binance\nokx" > exchanges.cfg

# 5. build the library

npm run export-exchanges
npm run bundle-browser

# 6a. copy the browser file to your project folder if you are buildig a web application

cp dist/ccxt.browser.js path/to/your/html/project

# 6b. or link against the library if you are building a Node.js application
npm link
cd path/to/your/node/project
npm link ccxt

# 6c. directly import ccxt from the entry point
touch app.js

# inside of app.js

import ccxt from './js/ccxt.js'
console.log (ccxt)

# now you can run your app like so

node app.js

Python

ccxt algotrading library 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.3+

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

PHP

The autoloadable version of ccxt can be installed with Packagist/Composer (PHP 7.0+).

It can also be installed from the source code: ccxt.php

It requires common PHP modules:

  • cURL
  • mbstring (using UTF-8 is highly recommended)
  • PCRE
  • iconv
  • gmp (this is a built-in extension as of PHP 7.2+)
include "ccxt.php";
var_dump (\ccxt\Exchange::$exchanges); // print a list of all available exchange classes

The library supports concurrent asynchronous mode using tools from RecoilPHP and ReactPHP in PHP 7.2+. Read the Manual for more details.

.net/C#

ccxt in C# with Nugget (netstandard 2.0 and netstandard 2.1)

using ccxt;
Console.WriteLine(ccxt.Exchanges) // check this later

Docker

You can get CCXT installed in a container along with all the supported languages and dependencies. This may be useful if you want to contribute to CCXT (e.g. run the build scripts and tests — please see the Contributing document for the details on that).

You don't need the Docker image if you're not going to develop CCXT. If you just want to use CCXT – just install it as a regular package into your project.

Using docker-compose (in the cloned CCXT repository):

docker-compose run --rm ccxt

Alternatively:

docker build . --tag ccxt
docker run -it ccxt

Proxy

If you are unable to obtain data from CCXT due to some location restrictions, you can make read proxy section.