CCXT Library Integration Guide

CCXT (CryptoCurrency eXchange Trading Library) is an open-source library that integrates APIs of cryptocurrency exchanges worldwide into a single interface. This allows you to utilize features such as algorithmic trading and strategic backtesting across various programming languages.

Get Started

CCXT (CryptoCurrency eXchange Trading Library) is an exchange integration library that provides a unified interface for accessing APIs from over 100 global digital asset exchanges. It supports various programming languages and makes API integration easier with minimal code, without requiring you to implement every detail of each exchange’s API. This guide shows how to use the CCXT library to call the Upbit API in Python and Node.js environments.


CCXT Official Documentation

CCXT provides official documentation. You can use the links below to access the official sites.

  • CCXT Upbit API Guide: https://docs.ccxt.com/#/exchanges/upbit
    • This page in the CCXT developer documentation introduces the Upbit API. It describes the APIs available via CCXT and explains how to use them.
  • CCXT Source Code: https://github.com/ccxt/ccxt
  • This is the official GitHub repository, where you can clone the entire CCXT source code, check the commit history, and review changes.
  • CCXT Docs: https://docs.ccxt.com/
    • This is the official documentation website for CCXT. It provides information on supported exchanges, available APIs, and integration methods.

Python Integration Guide

  • Minimum version: Python 3.7.0+

Setting Up a Virtual Environment and Installing the CCXT Library

Python recommends creating a project-specific virtual environment for development. A virtual environment ensures that each project has an isolated setup, effectively preventing package conflicts and version issues. The steps to set up and run the CCXT library within a virtual environment are as follows:

  1. Create the project directory and file

Open the terminal and enter the following commands to create a ccxt_project directory and inside it, create a file named ccxt_upbit.py.

mkdir ccxt_project
cd ccxt_project

touch ccxt_upbit.py

  1. Create Virtual Environment

enter the following commands at the terminal to create a virtual environment.

python3 -m venv .venv

  1. Activate Virtual Environment

The commands to activate the virtual environment depending on your operating system are as follows. Run the corresponding command in your terminal to activate the virtual environment:

  • Linux/MacOS: source .venv/bin/activate
  • Window: .venv\Scripts\activate

If the virtual environment is successfully activated, the name of the virtual environment will appear at the beginning of the terminal prompt.

(.venv) user@computer:~/project$

  1. Download the CCXT Library

Download the CCXT library within your virtual environment. This package will be available only inside the activated virtual environment. Run the following command in the terminal where the virtual environment is activated:

pip install ccxt

  1. Set up the CCXT Instance

CCXT is designed to maintain state, including exchange-specific settings and authentication information. Therefore, it is common practice to create and use an instance as shown below. When creating an instance, you can manage authentication tokens by providing your Access Key and Secret Key. CCXT also supports additional configuration options such as request rate limits and proxy settings.

# ccxt_upbit.py
import ccxt

access_key = "<YOUR_ACCESS_KEY>"
secret_key = "<YOUR_SECRET_KEY>"

client = ccxt.upbit({
        "apiKey": access_key,
        "secret": secret_key
    })

You can check the Upbit API available through CCXT by clicking the link below.


  1. Confirm Instance Configuration

To verify that the instance is configured correctly, add the following code to the ccxt_upbit.py file and run it. If the configuration is valid, the API will return a response; if not, an error will be returned.

# ccxt_upbit.py
import ccxt

access_key = "<YOUR_ACCESS_KEY>"
secret_key = "<YOUR_SECRET_KEY>"

def get_balance():
client = ccxt.upbit({
    "apiKey": access_key,
    "secret": secret_key,
})

    balance = client.fetchBalance()
    print(balance)

if __name__ == "__main__":
    get_balance()
# ccxt_upbit.py
import ccxt

def list_markets(symbols: list[str]):
    client = ccxt.upbit()

    market_list = client.fetchMarkets()
    return [item for item in market_list if item.get('symbol') in symbols]

if __name__ == "__main__":
    symbols = ["BTC/SGD", "ETH/SGD", "SOL/SGD"]
    markets = list_markets(symbols)
    print(markets)

You can view the results of the Upbit API calls executed through CCXT as shown below.

{
  "info": [
    {
      "currency": "BTC",
      "balance": "1.0",
      "locked": "0",
      "avg_buy_price": "153559.00",
      "avg_buy_price_modified": False,
      "unit_currency": "SGD"
    },
...
  ],
  "timestamp": None,
  "datetime": None,
  "BTC": {
    "free": 1.04e-6,
    "used": 0.0,
    "total": 1.04e-6
  },
  "total": {
    "BTC": 1.04e-6,
  }
}
[
  {
    "id": "{fiat}-ETH",
    "lowercaseId": None,
    "symbol": "ETH/{fiat}",
    "base": "ETH",
    "quote": "{fiat}",
    "settle": None,
    "baseId": "ETH",
    "quoteId": "{fiat}",
    "settleId": None,
    "type": "spot",
    "spot": True,
    "margin": False,
    "swap": False,
    "future": False,
    "option": False,
    "index": False,
    "active": True,
    "contract": False,
    "linear": None,
    "inverse": None,
    "subType": None,
    "taker": 0.0005,
    "maker": 0.0005,
    "contractSize": None,
    "expiry": None,
    "expiryDatetime": None,
    "strike": None,
    "optionType": None,
    "precision": {
      "price": 1e-8,
      "amount": 1e-8
    },
    "limits": {
      "leverage": {
        "min": None,
        "max": None
      },
      "amount": {
        "min": None,
        "max": None
      },
      "price": {
        "min": None,
        "max": None
      },
      "cost": {
        "min": None,
        "max": None
      }
    },
    "marginModes": {
      "cross": None,
      "isolated": None
    },
    "created": None,
    "info": {
      "market": "{fiat}-ETH",
      "english_name": "Ethereum"
    }
  },
  {
    "id": "{fiat}-SOL",
    "lowercaseId": None,
    "symbol": "SOL/{fiat}",
    "base": "SOL",
    "quote": "{fiat}",
    "settle": None,
    "baseId": "SOL",
    "quoteId": "{fiat}",
    "settleId": None,
    "type": "spot",
    "spot": True,
    "margin": False,
    "swap": False,
    "future": False,
    "option": False,
    "index": False,
    "active": True,
    "contract": False,
    "linear": None,
    "inverse": None,
    "subType": None,
    "taker": 0.0005,
    "maker": 0.0005,
    "contractSize": None,
    "expiry": None,
    "expiryDatetime": None,
    "strike": None,
    "optionType": None,
    "precision": {
      "price": 1e-8,
      "amount": 1e-8
    },
    "limits": {
      "leverage": {
        "min": None,
        "max": None
      },
      "amount": {
        "min": None,
        "max": None
      },
      "price": {
        "min": None,
        "max": None
      },
      "cost": {
        "min": None,
        "max": None
      }
    },
    "marginModes": {
      "cross": None,
      "isolated": None
    },
    "created": None,
    "info": {
      "market": "{fiat}-SOL",
      "english_name": "Solana"
    }
  },
  {
    "id": "{fiat}-BTC",
    "lowercaseId": None,
    "symbol": "BTC/{fiat}",
    "base": "BTC",
    "quote": "{fiat}",
    "settle": None,
    "baseId": "BTC",
    "quoteId": "{fiat}",
    "settleId": None,
    "type": "spot",
    "spot": True,
    "margin": False,
    "swap": False,
    "future": False,
    "option": False,
    "index": False,
    "active": True,
    "contract": False,
    "linear": None,
    "inverse": None,
    "subType": None,
    "taker": 0.0005,
    "maker": 0.0005,
    "contractSize": None,
    "expiry": None,
    "expiryDatetime": None,
    "strike": None,
    "optionType": None,
    "precision": {
      "price": 1e-8,
      "amount": 1e-8
    },
    "limits": {
      "leverage": {
        "min": None,
        "max": None
      },
      "amount": {
        "min": None,
        "max": None
      },
      "price": {
        "min": None,
        "max": None
      },
      "cost": {
        "min": None,
        "max": None
      }
    },
    "marginModes": {
      "cross": None,
      "isolated": None
    },
    "created": None,
    "info": {
      "market": "SGD-BTC",
      "english_name": "Bitcoin"
    }
  }
]

  1. Deactivate the Virtual Environment

After finishing your program, you can deactivate the virtual environment by entering the command below. The deactivation command is the same regardless of the operating system.

deactivate

Node.js Integration Guide

  • Minimum version: Node v7.6+

Downloading CCXT Library via NPM

Node.js uses NPM (Node Package Manager), the package manager for the Node.js environment, to easily download the CCXT library. The steps for downloading the CCXT library with NPM are as follows:

  1. Create Project Directory and File

Open the terminal and enter the following commands to create a ccxt_project directory and inside it, create a file named ccxt.js.

mkdir ccxt_project
cd ccxt_project

touch ccxt.js

  1. Download CCXT Library

Use NPM to download the CCXT library by running the following command in your terminal:

npm install ccxt

  1. Set up the CCXT Instance

CCXT is designed to maintain state, including exchange-specific settings and authentication information. Therefore, the common approach is to create and use an instance as shown below. When creating an instance, you can manage authentication tokens by providing your Access Key and Secret Key. You can also configure additional options such as request rate limits and proxy settings.

// ccxt.js
const ccxt = require('ccxt');

accessKey = "<YOUR_ACCESS_KEY>";
secretKey = "<YOUR_SECRET_KEY>";

const client = new ccxt.upbit({
    apiKey: accessKey,
    secret: secretKey,
});

You can check the Upbit API available through CCXT by clicking the link below.


  1. Confirm Instance Configuration

To verify that the instance is configured correctly, add the following code to the ccxt.js file and run it. If the configuration is valid, it will return an API response; if not, it will return an error.

const ccxt = require('ccxt');

const accessKey = "<YOUR_ACCESS_KEY>";
const secretKey = "<YOUR_SECRET_KEY>";

const client = new ccxt.upbit({
    apiKey: accessKey,
    secret: secretKey,
});
async function listBalances() {
    const balance = await client.fetchBalance();
    console.log(balance);
}

listBalances();
// ccxt.js
const ccxt = require('ccxt');

const upbit = new ccxt.upbit();
const symbols = ["BTC/{fiat}", "ETH/{fiat}", "SOL/{fiat}"];

async function listMarkets(symbols) {
    const markets = await upbit.fetchMarkets();
    return markets.filter(market => symbols.includes(market.symbol));
}

listMarkets(symbols).then(markets => {
    console.log(markets);
});

You can view the results of the Upbit API calls executed through CCXT as shown below.

{
  "info": [
    {
      "currency": "BTC",
      "balance": "1.0",
      "locked": "0",
      "avg_buy_price": "153559.00",
      "avg_buy_price_modified": False,
      "unit_currency": "SGD"
    },
...
  ],
  "timestamp": None,
  "datetime": None,
  "BTC": {
    "free": 1.04e-6,
    "used": 0.0,
    "total": 1.04e-6
  },
  "total": {
    "BTC": 1.04e-6,
  }
}
[
  {
    "id": "{fiat}-ETH",
    "lowercaseId": None,
    "symbol": "ETH/{fiat}",
    "base": "ETH",
    "quote": "{fiat}",
    "settle": None,
    "baseId": "ETH",
    "quoteId": "{fiat}",
    "settleId": None,
    "type": "spot",
    "spot": True,
    "margin": False,
    "swap": False,
    "future": False,
    "option": False,
    "index": False,
    "active": True,
    "contract": False,
    "linear": None,
    "inverse": None,
    "subType": None,
    "taker": 0.0005,
    "maker": 0.0005,
    "contractSize": None,
    "expiry": None,
    "expiryDatetime": None,
    "strike": None,
    "optionType": None,
    "precision": {
      "price": 1e-8,
      "amount": 1e-8
    },
    "limits": {
      "leverage": {
        "min": None,
        "max": None
      },
      "amount": {
        "min": None,
        "max": None
      },
      "price": {
        "min": None,
        "max": None
      },
      "cost": {
        "min": None,
        "max": None
      }
    },
    "marginModes": {
      "cross": None,
      "isolated": None
    },
    "created": None,
    "info": {
      "market": "{fiat}-ETH",
      "english_name": "Ethereum"
    }
  },
  {
    "id": "{fiat}-SOL",
    "lowercaseId": None,
    "symbol": "SOL/{fiat}",
    "base": "SOL",
    "quote": "{fiat}",
    "settle": None,
    "baseId": "SOL",
    "quoteId": "{fiat}",
    "settleId": None,
    "type": "spot",
    "spot": True,
    "margin": False,
    "swap": False,
    "future": False,
    "option": False,
    "index": False,
    "active": True,
    "contract": False,
    "linear": None,
    "inverse": None,
    "subType": None,
    "taker": 0.0005,
    "maker": 0.0005,
    "contractSize": None,
    "expiry": None,
    "expiryDatetime": None,
    "strike": None,
    "optionType": None,
    "precision": {
      "price": 1e-8,
      "amount": 1e-8
    },
    "limits": {
      "leverage": {
        "min": None,
        "max": None
      },
      "amount": {
        "min": None,
        "max": None
      },
      "price": {
        "min": None,
        "max": None
      },
      "cost": {
        "min": None,
        "max": None
      }
    },
    "marginModes": {
      "cross": None,
      "isolated": None
    },
    "created": None,
    "info": {
      "market": "{fiat}-SOL",
      "english_name": "Solana"
    }
  },
  {
    "id": "{fiat}-BTC",
    "lowercaseId": None,
    "symbol": "BTC/{fiat}",
    "base": "BTC",
    "quote": "{fiat}",
    "settle": None,
    "baseId": "BTC",
    "quoteId": "{fiat}",
    "settleId": None,
    "type": "spot",
    "spot": True,
    "margin": False,
    "swap": False,
    "future": False,
    "option": False,
    "index": False,
    "active": True,
    "contract": False,
    "linear": None,
    "inverse": None,
    "subType": None,
    "taker": 0.0005,
    "maker": 0.0005,
    "contractSize": None,
    "expiry": None,
    "expiryDatetime": None,
    "strike": None,
    "optionType": None,
    "precision": {
      "price": 1e-8,
      "amount": 1e-8
    },
    "limits": {
      "leverage": {
        "min": None,
        "max": None
      },
      "amount": {
        "min": None,
        "max": None
      },
      "price": {
        "min": None,
        "max": None
      },
      "cost": {
        "min": None,
        "max": None
      }
    },
    "marginModes": {
      "cross": None,
      "isolated": None
    },
    "created": None,
    "info": {
      "market": "{fiat}-BTC",
      "english_name": "Bitcoin"
    }
  }
]