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:

ExchangeExchangeExchangeExchangeExchange
aaxalpacaascendexbequantbibox
bigonebinancebinancecoinmbinanceusbinanceusdm
bit2cbitbankbitbaybitbnsbitcoincom
bitfinexbitfinex2bitflyerbitforexbitget
bithumbbitmartbitmexbitoprobitpanda
bitruebitsobitstampbitstamp1bittrex
bitvavobkexbl3pblockchaincombtcalpha
btcboxbtcexbtcmarketsbtctradeuabtcturk
budabwbybitbytetradecex
coinbasecoinbaseprimecoinbaseprocoincheckcoinex
coinfalconcoinmatecoinonecoinspotcrex24
cryptocomcurrencycomdeltaderibitdigifinex
eqonexexmoflowbtcfmfwioftx
ftxusgategateiogeminihitbtc
hitbtc3hollaexhuobihuobijphuobipro
idexindependentreserveindodaxitbitkraken
kucoinkucoinfutureskunalatokenlbank
lbank2liquidlunolykkemercado
mexcmexc3ndaxnovadaxoceanex
okcoinokexokex5okxpaymium
phemexpoloniexprobitqtraderipio
stextherocktidebittidextimex
tokocryptoupbitwavesexchangewazirxwhitebit
wooyobitzaifzbzipmex
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)

  • 🎯 Market Data: fetch_ticker, fetch_tickers, fetch_markets, fetch_currencies
  • 📊 Price History: fetch_ohlcvs (OHLCV candlestick data)
  • 📈 Trading Data: fetch_trades, fetch_order_book, fetch_l2_order_book
  • 🔍 Exchange Info: exchanges(), fetch_status, load_markets
  • 📉 Derivatives: fetch_open_interest, fetch_funding_rates, fetch_greeks
  • 🏦 Options: fetch_option, fetch_option_chain
  • 💱 Convert: fetch_convert_quote

Private APIs (Authentication required) 🔐

  • 💰 Account: fetch_balance
  • 🛒 Orders: create_order, cancel_order, fetch_orders, fetch_open_orders, fetch_closed_orders, fetch_canceled_orders
  • 📋 Order Types: create_limit_buy_order, create_limit_sell_order, create_market_buy_order, create_market_sell_order
  • 💸 Trading History: fetch_my_trades, fetch_my_liquidations
  • 🏛️ Lending: fetch_cross_borrow_rate, fetch_cross_borrow_rates, fetch_isolated_borrow_rate, fetch_isolated_borrow_rates
  • 💱 Convert Trading: create_convert_trade

✅ 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

  • All unified API functions implemented (40+ functions!)
  • Full authentication support for private APIs 🔐
  • Complete market data access (public APIs)
  • Full trading functionality (create, cancel, manage orders)
  • Proper Elixir structs with type safety
  • Account management (balance, trading history)
  • Advanced trading features (lending rates, liquidations, convert trading)

🚧 What's Coming

  • Better error handling and retries
  • WebSocket support for real-time data
  • More examples and tutorials
  • Performance optimizations
  • Better documentation

💡 What's Not Here (Yet)

  • Real-time streaming (WebSockets)
  • Portfolio management helpers
  • Advanced order types beyond CCXT unified API

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! 📈