bitstamp-kiss
is a Bitstamp API v2 wrapper with the joy of kiss literate programming
API | Annotated source | License
API
The following methods are implemented:
Annotated source
See Bitstamp API as a reference.
// This code is generated by command: npm run markdown2code
Dependencies
Required dependencies are all core packages.
const crypto = const https = const querystring =
Environment
Customer id is your Bitstamp username. You can get API key and secret going to Account > Settings > API Access.
const BITSTAMP_APIKEY = processenvBITSTAMP_APIKEYconst BITSTAMP_APISECRET = processenvBITSTAMP_APISECRETconst BITSTAMP_CUSTOMERID = processenvBITSTAMP_CUSTOMERID
Utils
coerceTick
Convert raw tick Object<String>
into numeric values.
{ return high: last: timestamp: bid: vwap: volume: low: ask: open: }
getNonce
Get a unique progressive value. Current UTC timestamp is used, as usual. It is also to return value in milliseconds, to make the nonce unique.
{ const now = const nonce = now now now now now now return nonce + now}
getSignature
{ const hmac = crypto const message = nonce + BITSTAMP_CUSTOMERID + BITSTAMP_APIKEY hmac const signature = hmac return signature}
limitTo5Decimals
Truncate value to avoid Bitstamp API errors on sell limit order.
{ const decimals = value1 if decimals && decimalslength > 5 return value else return value }
limitTo8Decimals
Truncate value to avoid Bitstamp API error:
Ensure that there are no more than 8 decimal places.
{ const decimals = value1 if decimals && decimalslength > 8 return value else return value }
Public API
publicRequest
{ https}
orderBook
Returns a JSON dictionary like the ticker call, with the calculated values being from within an hour.
{ } exportsorderBook = orderBook
ticker
Returns data for the given currency pair.
/** * @param * @param * * @returns * @returns * @returns * @returns * @returns * @returns * @returns * @returns * @returns * @returns */ { } exportsticker = ticker
hourlyTicker
Returns a JSON dictionary like the ticker call, with the calculated values being from within an hour.
{ } exportshourlyTicker = hourlyTicker
transactions
/** * @param * @param * @params */ { const path = `v2/transactions//?time=` } exportstransactions = transactions
Private API
These calls will be executed on the account (Sub or Main), to which the used API key is bound to.
privateRequest
{ const nonce = const signature = const requestData = querystring const requestOptions = hostname: 'www.bitstamp.net' port: 443 path: `/api/` method: 'POST' headers: 'Content-Type': 'application/x-www-form-urlencoded' 'Content-Length': requestDatalength 'Accept': 'application/json' const request = https request request request}
accountBalance
This API call is cached for 10 seconds.
/** * @param * @returns * * Balance * * @returns * @returns * @returns * @returns * @returns * @returns * @returns * * Reserved. * * @returns * @returns * @returns * @returns * @returns * @returns * @returns * * Available for trading. * * @returns * @returns * @returns * @returns * @returns * @returns * @returns * * Customer trading fees. * * @returns * @returns * @returns * @returns * @returns * @returns * @returns * @returns * @returns * @returns * @returns * @returns * @returns * @returns * @returns */ { } exportsaccountBalance = accountBalance
buyLimitOrder
This call will be executed on the account (Sub or Main), to which the used API key is bound to.
/** * @param * @param * @param * @param * @param * @param * @returns * @returns * @returns * @returns * @returns * @returns */ { const params = amount: price: if paramlimit_price if paramlimit_price <= paramprice paramslimit_price = } exportsbuyLimitOrder = buyLimitOrder
buyMarketOrder
By placing a market order you acknowledge that the execution of your order depends on the market conditions and that these conditions may be subject to sudden changes that cannot be foreseen.
/** * @param * @param * @param * @returns * @returns * @returns * @returns * @returns * @returns */ { const params = amount: } exportsbuyMarketOrder = buyMarketOrder
sellLimitOrder
This call will be executed on the account (Sub or Main), to which the used API key is bound to.
Note that daily_order param is not supported, since Bistamp API complains with error
Both limit_price and any optional parameter cannot be set.
/** * @param * @param * @param * @param * @param * @param * @returns * @returns * @returns * @returns * @returns * @returns */ { const params = amount: price: if paramlimit_price if paramlimit_price >= paramprice paramslimit_price = } exportssellLimitOrder = sellLimitOrder
sellMarketOrder
By placing a market order you acknowledge that the execution of your order depends on the market conditions and that these conditions may be subject to sudden changes that cannot be foreseen. This call will be executed on the account (Sub or Main), to which the used API key is bound to.
/** * @param * @param * @param * @returns * @returns * @returns * @returns * @returns * @returns */ { const params = amount: } exportssellMarketOrder = sellMarketOrder
userTransactions
Returns a descending list of transactions, represented as dictionaries.
For example, to get latest 100 BTC/USD market trade transactions
bitstamp
The currencyPair parameter can be also all
to get transactions for all currency pairs.
/** * @param * @param * @param * @param * @param * * @returns * * Every transaction has the following properties: * * @prop * @prop * @prop * @prop * @prop * @prop * @prop * @prop * @prop * @prop * @prop * @prop * @prop */ { const params = offset limit sort const path = currencyPair === 'all' ? 'v2/user_transactions/' : `v2/user_transactions//` } exportsuserTransactions = userTransactions
Helpers
computeFee
/** * @param * * @returns */ { const percentage = 025 const fee = value * percentage / 100 // 0.25% return Math / 100 // rounded to two decimals} exportscomputeFee = computeFee