Open Source Unified REST API of 100+ Crypto Exchange Sites !
- CCXT REST
CCXT is a popular open source library to connect to over 100 cryptocurrency exchange sites via a unified API. And the APIs are available by importing a nodejs, python or a PHP library. So if you're using any of those 3 programming languages, you'd be able to import and use ccxt.
However, if you are not using those 3 programming languages, you can use ccxt-rest in order to connect to a ccxt's unified API via REST.
For example, if you want to get the list of support exchanges of ccxt, in nodejs, you would do the following
var ccxt = require ('ccxt')
console.log (ccxt.exchanges) // print all available exchanges..and you will get..
[ '_1broker',
'_1btcxe',
'acx',
'allcoin',
...
]In ccxt-rest, you can do the following:
$ curl http://localhost:3000/exchanges..and you will get..
[
"_1broker",
"_1btcxe",
"acx",
...
]Furthermore, ccxt-rest allows you complete access to the ccxt APIs by exposing all of a ccxt exchange object's method as REST API.
You can install this as a global node package, or run the server via docker
$ npm install -g ccxt-rest
$ ccxt-rest$ docker run -p 3000:3000 franzsee/ccxt-rest-
List supported exchanges (all possible values for
{{exchangeName}})$ curl http://localhost:3000/exchanges
-
List all exchange instance ids (all possible values for
{{exchangeId}})$ curl http://localhost:3000/exchanges/{{exchangeName}} -
Create an exchange instance (creating an
{{exchangeId}})$ curl -X POST http://localhost:3000/exchanges/{{exchangeName}} -d '{"id":"myExchangeId","appKey":"myAppKey","secret":"myAppSecret"}' -
Deleting an exchange instance
$ curl -X DELETE http://localhost:3000/exchanges/{{exchangeName}}/{{exchangeId}} -
Calling an exchange instance method (the REST API format for most of the interesting stuff like retreival of trades, order book, your wallet/balances, creating an order, canceling an order, etc)
$ curl -X POST http://localhost:3000/exchanges/{{exchangeName}}/{{exchangeId}}/{{methodName}} -d '["1stParameter", {"2ndParameter":"value"}, "etc"]'
Note:
- CCXT REST
Once ccxt-rest is running, but before we can integrate with any exchange site, we first need to create an exchange instance. An exchange instance is what is needed to define the connection with a particular exchange, and it is through the integration would be made.
Before we create an exchange instance, we can first list all avaiable exchange sites we can create an instance from
$ curl http://localhost:3000/exchanges[
"_1broker",
"_1btcxe",
"acx",
"allcoin",
"anxpro",
"bibox",
"binance",
"bit2c",
"bitbank",
"bitbay",
"bitfinex",
"bitfinex2",
"bitflyer",
"bithumb",
"bitkk",
"bitlish",
"bitmarket",
"bitmex",
"bitso",
"bitstamp",
"bitstamp1",
"bittrex",
"bitz",
"bl3p",
"bleutrade",
"braziliex",
"btcbox",
"btcchina",
"btcexchange",
"btcmarkets",
"btctradeim",
"btctradeua",
"btcturk",
"btcx",
"bxinth",
"ccex",
"cex",
"chbtc",
"chilebit",
"cobinhood",
"coincheck",
"coinegg",
"coinex",
"coinexchange",
"coinfloor",
"coingi",
"coinmarketcap",
"coinmate",
"coinnest",
"coinone",
"coinsecure",
"coinspot",
"cointiger",
"coolcoin",
"cryptopia",
"dsx",
"ethfinex",
"exmo",
"exx",
"flowbtc",
"foxbit",
"fybse",
"fybsg",
"gatecoin",
"gateio",
"gdax",
"gemini",
"getbtc",
"hadax",
"hitbtc",
"hitbtc2",
"huobi",
"huobicny",
"huobipro",
"ice3x",
"independentreserve",
"indodax",
"itbit",
"jubi",
"kraken",
"kucoin",
"kuna",
"lakebtc",
"lbank",
"liqui",
"livecoin",
"luno",
"lykke",
"mercado",
"mixcoins",
"negociecoins",
"nova",
"okcoincny",
"okcoinusd",
"okex",
"paymium",
"poloniex",
"qryptos",
"quadrigacx",
"quoinex",
"southxchange",
"surbitcoin",
"therock",
"tidebit",
"tidex",
"urdubit",
"vaultoro",
"vbtc",
"virwox",
"wex",
"xbtce",
"yobit",
"yunbi",
"zaif",
"zb"
]Once you have picked which exchange site you would like to create an instance of, you then need to take note of that as the exchangeName. Also, once you have created the exchange instance, you need to take note of the id of that exchange instance because that would be the exchangeId you will need for the other REST API calls.
From the list of available exchange sites, you pick one and used that in the following REST API
$ curl -X POST http://localhost:3000/exchanges/{{exchangeName}} -d '{"parameters":"here"}'For example, if you choose bitso, you would do
$ curl -X POST http://localhost:3000/exchanges/bitso -d '{"id":"myBitso","apikey":"mYapIKEy","secret":"6d792061706920736563726574"}'Which would then respond with the JSON representation of the Exchange instance - something like this
{
...
"id": "myBitso",
"name": "Bitso",
"countries": "MX",
"enableRateLimit": false,
"rateLimit": 2000,
...
"apikey": "mYapIKEy",
"secret": "6d792061706920736563726574",
"hasCORS": true,
"hasPublicAPI": true,
"hasPrivateAPI": true,
"hasCancelOrder": true,
"hasCancelOrders": false,
"hasCreateDepositAddress": false,
"hasCreateOrder": true,
"hasCreateMarketOrder": true,
"hasCreateLimitOrder": true,
"hasDeposit": false,
"hasEditOrder": true,
"hasFetchBalance": true,
"hasFetchBidsAsks": false,
"hasFetchClosedOrders": false,
"hasFetchCurrencies": false,
"hasFetchDepositAddress": false,
"hasFetchFundingFees": false,
"hasFetchL2OrderBook": true,
"hasFetchMarkets": true,
"hasFetchMyTrades": true,
"hasFetchOHLCV": true,
"hasFetchOpenOrders": true,
"hasFetchOrder": false,
"hasFetchOrderBook": true,
"hasFetchOrderBooks": false,
"hasFetchOrders": false,
"hasFetchTicker": true,
"hasFetchTickers": false,
"hasFetchTrades": true,
"hasFetchTradingFees": false,
"hasWithdraw": false,
"tokenBucket": {
"refillRate": 0.0005,
"delay": 1,
"capacity": 1,
"defaultCost": 1,
"maxCapacity": 1000
}
}Note: The exchangeId here is myBitso. This and the exchangeName bitso would both be used most of the other REST API calls so those two need to be noted.
To see the ids of all instances of a paritcular exchange site, we run the following command:
$ curl http://localhost:3000/exchanges/{{exchangeName}}Again, if we use bitso, the REST API call would look like this
$ curl http://localhost:3000/exchanges/bitsoWhich would return an array of instance ids. Something like this
[
"myBisto"
]And with this, you can now use the id that you supplied in order to control this exchange instance.
If we want to retrieve the details of an exhange, we just need to supply both exchange name and exchange id in a GET REST API call. The format is
$ curl http://localhost:3000/exchanges/{{exchangeName}}/{{exchangeId}}For example. Given an exchangeName of bitso and exchangeId of myBitso, we can do the following REST API call
$ curl http://localhost:3000/exchanges/bitso/myBitsoIf we want to delete an exchange instance, we do the following REST API call.
$ curl -X DELETE http://localhost:3000/exchanges/{{exchangeName}}/{{exchangeId}}For example. Given an exchangeName of bitso and exchangeId of myBitso, we can do the following REST API call
$ curl -X DELETE http://localhost:3000/exchanges/bitso/myBitsoOnce you have an exchange instance, you can then start calling methods of that exchange instance by supplying the following:
- CCXT REST
The format to call any exchange instance method is the following:
$ curl -X POST http://localhost:3000/exchanges/{{exchangeName}}/{{exchangeId}}/{{method}} -d '["1stParameter", {"2ndParameter":"value"}, "etc"]'Note: The HTTP Method for calling exchange instance method is always POST. Also the POST body is always of JSON format. Particularly, it's always an array wherein each entry represents the sequential parameter list of the method you are invoking.
$ curl -X POST http://localhost:3000/exchanges/bitso/myBitso/fetchMarkets$ curl -X POST http://localhost:3000/exchanges/bitso/myBitso/fetchTicker -d '["BTC/MXN"]'$ curl -X POST http://localhost:3000/exchanges/bitso/myBitso/createOrder -d '["BTC/MXN", "limit", "buy", 1, 500]'$ curl -X POST http://localhost:3000/exchanges/bitso/myBitso/fetchOpenOrders$ curl -X POST http://localhost:3000/exchanges/bitso/myBitso/fetchOpenOrders -d '["myOpenOrderId"]'The list of APIs as of this writing are the following
User
+-------------------------------------------------------------+
| CCXT |
+------------------------------+------------------------------+
| Public | Private |
+=============================================================+
│ . |
│ The Unified CCXT API |
│ . |
| loadMarkets . fetchBalance |
| fetchMarkets . createOrder |
| fetchCurrencies . cancelOrder |
| fetchTicker . fetchOrder |
| fetchTickers . fetchOrders |
| fetchOrderBook . fetchOpenOrders |
| fetchOHLCV . fetchClosedOrders |
| fetchTrades . fetchMyTrades |
| . deposit |
| . withdraw |
│ . |
+=============================================================+
│ . |
| Custom Exchange API |
| (Derived Classes) |
│ . |
| publicGet... . privateGet... |
| publicPost... . privatePost... |
| . privatePut... |
| . privateDelete... |
| . sign |
│ . |
+=============================================================+
│ . |
| Base Exchange Class |
│ . |
+=============================================================+
Again, the format to call a ccxt exchange method is the following
$ curl -X POST http://localhost:3000/exchanges/{{exchangeName}}/{{exchangeId}}/{{method}} -d '["1stParameter", {"2ndParameter":"value"}, "etc"]'- CCXT REST
As of this writing, these are the documented methods in CCXT.
fetchMarkets (): Fetches a list of all available markets from an exchange and returns an array of markets (objects with properties such assymbol,base,quoteetc.). Some exchanges do not have means for obtaining a list of markets via their online API. For those, the list of markets is hardcoded.$ curl -X POST http://localhost:3000/exchanges/{{exchangeName}}/{{exchangeId}}/fetchMarketsloadMarkets ([reload]): Returns the list of markets as an object indexed by symbol and caches it with the exchange instance. Returns cached markets if loaded already, unless thereload = trueflag is forced.$ curl -X POST http://localhost:3000/exchanges/{{exchangeName}}/{{exchangeId}}/loadMarkets -d '[reload]'fetchOrderBook (symbol[, limit = undefined[, params = {}]]): Fetch L2/L3 order book for a particular market trading symbol.$ curl -X POST http://localhost:3000/exchanges/{{exchangeName}}/{{exchangeId}}/fetchOrderBook -d '[symbol[, limit = undefined[, params = {}]]]'fetchL2OrderBook (symbol[, limit = undefined[, params]]): Level 2 (price-aggregated) order book for a particular symbol.$ curl -X POST http://localhost:3000/exchanges/{{exchangeName}}/{{exchangeId}}/fetchL2OrderBook -d '[symbol[, limit = undefined[, params]]]'fetchTrades (symbol[, since[, [limit, [params]]]]): Fetch recent trades for a particular trading symbol.$ curl -X POST http://localhost:3000/exchanges/{{exchangeName}}/{{exchangeId}}/fetchTrades -d '[symbol[, since[, [limit, [params]]]]]'fetchTicker (symbol): Fetch latest ticker data by trading symbol.$ curl -X POST http://localhost:3000/exchanges/{{exchangeName}}/{{exchangeId}}/fetchTicker -d '[symbol]'fetchBalance (): Fetch Balance.$ curl -X POST http://localhost:3000/exchanges/{{exchangeName}}/{{exchangeId}}/fetchBalancecreateOrder (symbol, type, side, amount[, price[, params]])$ curl -X POST http://localhost:3000/exchanges/{{exchangeName}}/{{exchangeId}}/createOrder -d '[symbol, type, side, amount[, price[, params]]]'createLimitBuyOrder (symbol, amount, price[, params])$ curl -X POST http://localhost:3000/exchanges/{{exchangeName}}/{{exchangeId}}/createLimitBuyOrder -d '[symbol, amount, price[, params]]'createLimitSellOrder (symbol, amount, price[, params])$ curl -X POST http://localhost:3000/exchanges/{{exchangeName}}/{{exchangeId}}/createLimitSellOrder -d '[symbol, amount, price[, params]]'createMarketBuyOrder (symbol, amount[, params])$ curl -X POST http://localhost:3000/exchanges/{{exchangeName}}/{{exchangeId}}/createMarketBuyOrder -d '[symbol, amount[, params]]'createMarketSellOrder (symbol, amount[, params])$ curl -X POST http://localhost:3000/exchanges/{{exchangeName}}/{{exchangeId}}/createMarketSellOrder -d '[symbol, amount[, params]]'cancelOrder (id[, symbol[, params]])$ curl -X POST http://localhost:3000/exchanges/{{exchangeName}}/{{exchangeId}}/cancelOrder -d '[id[, symbol[, params]]]'fetchOrder (id[, symbol[, params]])$ curl -X POST http://localhost:3000/exchanges/{{exchangeName}}/{{exchangeId}}/fetchOrder -d '[id[, symbol[, params]]]'fetchOrders ([symbol[, since[, limit[, params]]]])$ curl -X POST http://localhost:3000/exchanges/{{exchangeName}}/{{exchangeId}}/fetchOrders -d '[[symbol[, since[, limit[, params]]]]]'fetchOpenOrders ([symbol[, since, limit, params]]]])$ curl -X POST http://localhost:3000/exchanges/{{exchangeName}}/{{exchangeId}}/fetchOpenOrders -d '[[symbol[, since, limit, params]]]]]'fetchClosedOrders ([symbol[, since[, limit[, params]]]])$ curl -X POST http://localhost:3000/exchanges/{{exchangeName}}/{{exchangeId}}/fetchClosedOrders -d '[[symbol[, since[, limit[, params]]]]]'fetchMyTrades ([symbol[, since[, limit[, params]]]])$ curl -X POST http://localhost:3000/exchanges/{{exchangeName}}/{{exchangeId}}/fetchMyTrades -d '[[symbol[, since[, limit[, params]]]]]'
For more information, kindly see the CCXT Manual
Need a feature or need support? Reach out and let us know what you need.