btc-id
A Node.js-based Implementation of Bitcoin Indonesia's Trade API
Compatibility
This implementation is compatible with Trade API v1.7. All API request methods are implemented using Request and Bluebird.
Important Notes
- A private and secret key must be set before making private API requests. See this link.
- Correct order of parallel private API requests cannot be guaranteed because of asynchronous nature of JavaScript and network latency. Some requests will fail because of incorrect nonce. Tell your nice trading bot to handle errors carefully and just don't go too fast.
- It is recommended to use proven third party library to parse numbers and do arithmetic calculations, such as
bignumber.js
. You know, JavaScript is bad at math and I am pretty sure you don't want to lose even only a small fraction of your precious digital golds. - I am not responsible for any future profits, losses or damages caused by this library. Cryptocurrency trading is always considered to be high-risk activity. By using this library, it is assumed that you know exactly what you are doing.
Usage
const btcid = require('btc-id');
const API = new btcid();
Methods
General
version
Get Trade API compatibility version. Example:
console.log(API.version);
baseUrl
Get/set base URL for API requests. Example:
console.log(API.baseUrl);
API.baseUrl = 'http://a-trading-proxy.com';
console.log(API.baseUrl);
key
Set API key. Example:
API.key = 'AAAAAAAA-BBBBBBBB-CCCCCCCC-DDDDDDDD-EEEEEEEE';
secret
Set secret key. Example:
API.secret = '1263e5a57b853024509bf94ff466ec6a2a733ad83a2aa6ceb5cc14301713b4a77f2bb154a66cde73';
pair(coinA, coinB)
An easy way to generate coin pair string for use with API requests. Example:
console.log(API.pair('BTC', 'IDR'));
Public API
getTicker(pair)
Example:
API.getTicker(API.pair('BTC','IDR'))
.then(function(response) {
console.log(response);
})
.catch(function(err) {
console.error(err);
});
getTrades(pair)
Example:
API.getTrades(API.pair('BTC','IDR'))
.then(function(response) {
console.log(response);
})
.catch(function(err) {
console.error(err);
});
getDepth(pair)
Example:
API.getDepth(API.pair('BTC','IDR'))
.then(function(response) {
console.log(response);
})
.catch(function(err) {
console.error(err);
});
Private
getInfo()
Example:
API.getInfo()
.then(function(response) {
console.log(response);
})
.catch(function(err) {
console.error(err);
});
getTransHistory()
Example:
API.getTransHistory()
.then(function(response) {
console.log(response);
})
.catch(function(err) {
console.error(err);
});
getTradeHistory({pair, [count, from_id, end_id, order, since, end]})
Example:
API.getTradeHistory({pair: API.pair('BTC', 'IDR'), count: 100, order: 'desc'})
.then(function(response) {
console.log(response);
})
.catch(function(err) {
console.error(err);
});
getOpenOrders({[pair]})
Example A (get all open orders of all pairs):
API.getOpenOrders({})
.then(function(response) {
console.log(response);
})
.catch(function(err) {
console.error(err);
});
Example B (get open orders of specific pair):
API.getOpenOrders({pair: API.pair('BTC', 'IDR')})
.then(function(response) {
console.log(response);
})
.catch(function(err) {
console.error(err);
});
getOrderHistory({pair, [count, from]})
Example:
API.getOrderHistory({pair: API.pair('BTC', 'IDR'), count: 100})
.then(function(response) {
console.log(response);
})
.catch(function(err) {
console.error(err);
});
getOrder({pair, order_id})
Example:
API.getOrder({pair: API.pair('BTC', 'IDR'), order_id: 94428})
.then(function(response) {
console.log(response);
})
.catch(function(err) {
console.error(err);
});