CryptoMarket-javascript
main page
sign up in CryptoMarket.
Installation
To install Cryptomarket use npm
npm install cryptomarket@3.2.0
Documentation
This sdk makes use of the api version 3 of cryptomarket.
Quick Start
rest client
const { Client } = require("cryptomarket");
const apiKey = "AB32B3201";
const apiSecret = "21b12401";
const client = new Client(apiKey, apiSecret);
const currencies = await client.getCurrencies();
const orderBook = await client.getOrderBook("EOSETH");
const accountBalances = await client.getWalletBalances();
const tradingBalances = await client.getSpotTradingBalances();
const result = await client.transferBetweenWalletAndExchange({
currency: "EOS",
amount: "3.2",
source: Account.Wallet,
destination: Account.Spot,
});
const activeOrders = await client.getAllActiveSpotOrders("EOSETH");
const newOrder = await client.createOrder({
symbol: "EOSETH",
side: "buy",
quantity: "10",
price: "10",
});
websocket client
There are three websocket clients, the market data client, the spot trading client and the wallet client.
The market data client requires no authentication, while the spot trading client and the wallet client do require it.
All websocket methods return promises. Subscriptions also take in a function of two parameters, the notification data, and the notification type. The notification type is of type NOTIFICATION_TYPE, and is either SNAPSHOT, NOTIFICATION or DATA.
The documentation of a specific subscriptions explains with of this types of
notification uses.
MarketDataClient
Example of use of the market data client
const wsclient = new WSMarketDataClient();
await marketDataClient.subscribeToPartialOrderBook(
callback:(notification, type) => {
if (type === NOTIFICATION_TYPE.DATA) {
System.out.println("this subscription only recieves data notifications");
}
for (const symbol in notification) {
console.log(symbol);
const orderbook = notification[symbol];
console.log(orderbook);
}
},
params: {
speed: ORDER_BOOK_SPEED._100_MS,
depth: DEPTH._5,
symbols: ["EOSETH", "ETHBTC"],
}
);
SpotTradingClient
Example of use of the spot trading client
const apiKey = "AB32B3201";
const apiSecret= "21b12401";
const wsclient = new WSTradingClient(apiKey, apiSecret, 10_000);
await wsclient.connect();
const balanceList = await tradingClient.getSpotTradingBalances()
console.log(balanceList);
let clientOrderID = Math.floor(Date.now() / 1000).toString();
const report = await tradingClient.createSpotOrder({
clientOrderId: clientOrderID,
symbol: "EOSETH",
side: "sell",
quantity: "0.01",
price: "1000",
}
console.log(report);
WalletClient
Example of use of the wallet client
const wsclient = new WSWalletClient(keys.apiKey, keys.apiSecret);
const transactionList = await walletClient.getTransactions({
currencies: ["EOS"],
limit: 3,
});
console.log(transactionList);
await walletClient.subscribeToTransactions((notification, type) => {
if (type === NOTIFICATION_TYPE.UPDATE) {
console.log("this subscription only recieves update notifications");
}
console.log(notification);
});
error handling
{ CryptomarketSDKException, Client, WSMarketDataClient } = require('cryptomarket')
const client = new Client()
try {
const order = await client.createOrder({
'symbol':'EOSETHH',
'side':'sell',
'quantity':'10',
'price':'10'})
} catch (error) {
console.log(error)
}
const wsclient = new WSMarketDataClient()
await wsclient.connect();
try {
await wsclient.subscribeToMiniTickers()
} catch (error) {
console.log(error)
}
Constants
All constants used for calls are in the constants
module.
Checkout our other SDKs
python sdk
java sdk
go sdk
ruby sdk