ExCcxt ๐Ÿš€

Because you want to connect to multiple cryptocurrency exchanges API, but still want to do it in Elixir

This is a fork of the sadly abandoned ccxtex. It is a bridge to ccxt library, the JavaScript part. The way it works is via nodejs instance run with hex.pm nodejs package via supervisor.

ExCcxt is your friendly Elixir bridge to the amazing CCXT library - the Swiss Army knife of cryptocurrency exchange APIs. Think of it as a translator that speaks both Elixir and JavaScript, so you donโ€™t have to suffer through npm install nightmares.

With ExCcxt, you can query market data, fetch tickers, and do all sorts of crypto wizardry across 130+ exchanges including Binance, Coinbase, Kraken, and that one exchange your friend keeps telling you about.

Supported Exchanges ๐ŸŒ

ExCcxt supports 130+ cryptocurrency exchanges through the CCXT library. Hereโ€™s the complete list:

Exchange Exchange Exchange Exchange Exchange
aax alpaca ascendex bequant bibox
bigone binance binancecoinm binanceus binanceusdm
bit2c bitbank bitbay bitbns bitcoincom
bitfinex bitfinex2 bitflyer bitforex bitget
bithumb bitmart bitmex bitopro bitpanda
bitrue bitso bitstamp bitstamp1 bittrex
bitvavo bkex bl3p blockchaincom btcalpha
btcbox btcex btcmarkets btctradeua btcturk
buda bw bybit bytetrade cex
coinbase coinbaseprime coinbasepro coincheck coinex
coinfalcon coinmate coinone coinspot crex24
cryptocom currencycom delta deribit digifinex
eqonex exmo flowbtc fmfwio ftx
ftxus gate gateio gemini hitbtc
hitbtc3 hollaex huobi huobijp huobipro
idex independentreserve indodax itbit kraken
kucoin kucoinfutures kuna latoken lbank
lbank2 liquid luno lykke mercado
mexc mexc3 ndax novadax oceanex
okcoin okex okex5 okx paymium
phemex poloniex probit qtrade ripio
stex therock tidebit tidex timex
tokocrypto upbit wavesexchange wazirx whitebit
woo yobit zaif zb zipmex
zonda

All exchanges support public APIs. Private API support depends on the exchangeโ€™s authentication requirements.

Installation ๐Ÿ“ฆ

Step 1: Add to your mix.exs

def deps do
  [
    {:ex_ccxt, "~> 0.1.1"}
  ]
end

Step 2: Make sure you have Node.js

Youโ€™ll need Node.js (>= 14) installed because, well, CCXT is written in JavaScript and we havenโ€™t figured out how to rewrite 100+ exchange APIs in pure Elixir yet. ๐Ÿ˜…

# Check if you have Node.js
node --version

# If not, install it (macOS with Homebrew)
brew install node

# Or use your favorite package manager

Step 3: Profit! ๐Ÿ’ฐ

mix deps.get

How To Call Public API

For Public API function, just call right away.

Get a list of all supported exchanges

iex> ExCcxt.exchanges()
{:ok, ["aax", "alpaca", "ascendex", "bequant", "bibox", "bigone", "binance", ...]} # 130+ exchanges!

Fetch a ticker (current price info)

iex> ExCcxt.fetch_ticker("binance", "BTC", "USDT")
{:ok,
 %ExCcxt.Ticker{
   symbol: "BTC/USDT",
   last: 43250.50,
   bid: 43245.10,
   ask: 43255.90,
   high: 44100.00,
   low: 42800.75,
   # ... lots more juicy data
 }}

Get all tickers from an exchange

iex> ExCcxt.fetch_tickers("binance")
{:ok, %{
  "BTC/USDT" => %ExCcxt.Ticker{...},
  "ETH/USDT" => %ExCcxt.Ticker{...},
  # ... hundreds of trading pairs
}}

Fetch historical OHLCV data (candlesticks)

iex> opts = %ExCcxt.OhlcvOpts{
...>   exchange: "binance",
...>   base: "BTC",
...>   quote: "USDT",
...>   timeframe: "1h",
...>   since: ~N[2023-01-01 00:00:00],
...>   limit: 100
...> }
iex> ExCcxt.fetch_ohlcvs(opts)
{:ok, [%ExCcxt.OHLCV{...}, ...]} # Sweet, sweet candlestick data

Get order book (live buy/sell orders)

iex> ExCcxt.fetch_order_book("kraken", "BTC/USD")
{:ok,
 %ExCcxt.OrderBook{
   bids: [[43240.5, 1.2], [43235.0, 0.8], ...], # [price, amount]
   asks: [[43250.1, 0.5], [43255.2, 1.1], ...],
   symbol: "BTC/USD"
 }}

List all available markets

iex> ExCcxt.fetch_markets("coinbase")
{:ok, [
  %ExCcxt.Market{
    symbol: "BTC/USD",
    base: "BTC",
    quote: "USD",
    active: true,
    type: "spot"
  }, ...
]}

How to Call Private API.

Authentication :

To call Private API, depends on your Exchange, it might require different type of authentication. The most common one is API Key and API Secret. To check what type of authentication your exchange requires, you can use ExCcxt.required_credentials/1.

Example:

iex> ExCcxt.required_credentials("binance")

This will return

{:ok,
 %{
   "apiKey" => true,
   "login" => false,
   "password" => false,
   "privateKey" => false,
   "secret" => true,
   "token" => false,
   "twofa" => false,
   "uid" => false,
   "walletAddress" => false
 }}

This means you need to provide apiKey and secret to call private API.

From here after obtain your API Key and API Secret, you can create credential data:

{:ok, credential} = ExCcxt.Credential.new(name: "binance", apiKey: "your-api-key", secret: "your-api-secret")

{:ok,
 %ExCcxt.Credential{
   walletAddress: nil,
   uid: nil,
   twofa: nil,
   token: nil,
   secret: "your-api-secret",
   privateKey: nil,
   password: nil,
   login: nil,
   apiKey: "your-api-key",
   name: "binance"
 }}

Now you can use it to call any private API. CCXT already handling the authentication logic for you.

Example:

ExCcxt.fetch_balance(credential)

Thatโ€™s it!

Other Private API Examples:

# Fetch account balance
ExCcxt.fetch_balance(credential)

# Fetch open orders
ExCcxt.fetch_open_orders(credential)

# Create a limit buy order
ExCcxt.create_order(credential, "BTC/USDT", "limit", "buy", 0.001, 43250.0)

# Cancel an order
ExCcxt.cancel_order(credential, "order_id", "BTC/USDT")

# Fetch your trading history
ExCcxt.fetch_my_trades(credential)

# Fetch all orders (open, closed, canceled)
ExCcxt.fetch_orders(credential)

# Create market orders
ExCcxt.create_market_buy_order(credential, "BTC/USDT", 0.001)
ExCcxt.create_market_sell_order(credential, "BTC/USDT", 0.001)

What Works Right Now โœ…

Weโ€™ve implemented the full CCXT unified API! Hereโ€™s what you can do:

Public APIs (No authentication needed)

Private APIs (Authentication required) ๐Ÿ”

โœ… Authentication Supported: All private APIs now support full authentication using the ExCcxt.Credential struct. Just pass your API credentials and start trading! ๐Ÿš€

Current Status ๐Ÿš€

This library is NOT production-ready. Due to the nature of exchanges change their API any time, new product appear, old product terminated, exchanges closing down, and the fact this also depends on CCXT library catching up, this library may never be stable. Use at your own risk.

โœ… Whatโ€™s Solid

๐Ÿšง Whatโ€™s Coming

๐Ÿ’ก Whatโ€™s Not Here (Yet)

Contributing ๐Ÿค

Found a bug? Want to add a feature? PRs welcome! This library is a work in progress and weโ€™re always looking for help. Or do you think we should totally implement the full CCXT in Elixir instead of wrapping the JavaScript library? Yeah somebody need to do that. Not me for now though.

Disclaimer โš ๏ธ

This library can help you lose money very efficiently. Trade responsibly, test thoroughly, and remember: past performance does not guarantee future results. We are not responsible for your trading decisions or any losses incurred.

May your profits be high and your gas fees be low! ๐Ÿ“ˆ