CryptoMarket-javascript
main page
sign up in CryptoMarket.
Installation
To install Cryptomarket use npm
npm install cryptomarket
Documentation
This sdk makes use of the api version 2 of cryptomarket.
Quick Start
rest client
const { Client } = require('cryptomarket')
let apiKey='AB32B3201'
let api_secret='21b12401'
let client = new Client(apiKey, api_secret)
let currencies = await client.getCurrencies()
let orderBook = await client.getOrderBook('EOSETH')
let accountBalance = await client.getAccountBalance()
let tradingBalance = await client.getTradingBalance()
let result = await client.transferMoneyFromAccountBalanceToTradingBalance('ETH', '3.2')
let orders = await client.getActiveOrders('EOSETH')
let newOrder = await client.createOrder({'symbol':'EOSETH', 'side':'buy', 'quantity':'10', 'price':'10'})
websocket client
There are three websocket clients, one for public request (WSPublicClient), one for trading request (WSTradingClient) and one for the account requests (WSAccountClient).
Clients work with promises
Clients must be connected before any request. Authentication for WSTradingClient and WSAccountClient is automatic.
const { WSPublicClient, WSTradingClient, WSAccountClient} = require('cryptomarket')
let publicClient = new WSPublicClient()
await publicClient.connect()
await publicClient.getCurrencies()
let apiKey='AB32B3201'
let apiSecret='21b12401'
let tradingClient = new WSTradingClient(apiKey, apiSecret)
await tradingClient.connect()
let balance = await tradingClient.getTradingBalance()
let activeOrders = await tradingClient.getActiveOrders()
await tradingClient.createOrder({
clientOrderId:"qqwe123qwe",
symbol:'EOSETH',
side:'buy',
quantity:'10',
price:'10'
})
let accountClient = new WSAccountClient(apiKey, apiSecret)
await accountClient.connect()
let accBalance = await accountCilent.getAccountBalance()
subscriptions
all subscriptions take a callback argument to call with each feed of the subscription
function callback(feed) {
console.log(feed)
}
await publicClient.subscribeToOrderBook('EOSETH', callabck)
await accountClient.subscribeToTransactions(callback)
error handling
{ CryptomarketSDKException, Client, WSPublicClient } = require('cryptomarket')
client = new Client()
try {
order = client.createOrder({
'symbol':'EOSETHH',
'side':'sell',
'quantity':'10',
'price':'10'})
} catch (error) {
console.log(error)
}
wsclient = new WSPublicClient()
await wsclient.connect()
try {
await wsclient.subscribeToOrderbook('ETHBTC')
} catch (error) {
console.log(error)
}
try {
let trades = await wsclient.getTrades("abcde", myCallback)
} catch (err) {
console.log(err)
}
Checkout our other SDKs
python sdk
java sdk
go sdk
ruby sdk