All Projects → krystianity → node-bitstamp

krystianity / node-bitstamp

Licence: MIT license
bitstamp REST and WS API Node.js client 💵

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to node-bitstamp

Coinpricebar
💰 Cryptocurrency prices on MacBook Touch Bar
Stars: ✭ 290 (+400%)
Mutual labels:  ripple, litecoin
Cryptocurrency Cli
💰 Cryptocurrency Portfolio On The Command Line 💰
Stars: ✭ 99 (+70.69%)
Mutual labels:  ripple, litecoin
Ta4j Origins
A Java library for technical analysis ***Not maintained anymore, kept for archival purposes, see #192***
Stars: ✭ 354 (+510.34%)
Mutual labels:  ripple, litecoin
artunis-mobile
XRP Wallet app for Android and iOS, built in React Native.
Stars: ✭ 23 (-60.34%)
Mutual labels:  ripple, xrp
XpringKit
XpringKit provides a Swift SDK for interacting with Xpring Protocols (XRP/PayID/ILP). This library is deprecated.
Stars: ✭ 23 (-60.34%)
Mutual labels:  ripple, xrp
crypto-quotes
100+ Best of Crypto Quotes - I HODL, you HODL, we HODL! - BREAKING: BITCOIN JUST BROKE $22 000!
Stars: ✭ 12 (-79.31%)
Mutual labels:  ripple, xrp
Cryptolights
Live visualisation of blockchain transactions for popular cryptocurrencies
Stars: ✭ 54 (-6.9%)
Mutual labels:  ripple, litecoin
CryptoCurrency
Page to keep track of value & profits of a portfolio of cryptocurrency (based on Coinmarketcap, Bitfinex and Binance)
Stars: ✭ 27 (-53.45%)
Mutual labels:  ripple, litecoin
EasyFileTransfer
An easy way to transfer file with any size on network with tcp protocol.
Stars: ✭ 30 (-48.28%)
Mutual labels:  socket, transfer
Coinbin.org
₿ A Human–Friendly API Service for Crypto Currency Information.
Stars: ✭ 253 (+336.21%)
Mutual labels:  ripple, litecoin
TheWorldExchange
A purely client-side wallet and direct interface showcasing the full functionality of Ripple / blockchain.
Stars: ✭ 34 (-41.38%)
Mutual labels:  ripple, xrp
GenericProtocol
⚡️ A fast TCP event based buffered server/client protocol for transferring data over the (inter)net in .NET 🌐
Stars: ✭ 38 (-34.48%)
Mutual labels:  socket, transfer
xrpl-dev-portal
Source code for xrpl.org including developer documentation
Stars: ✭ 330 (+468.97%)
Mutual labels:  ripple, xrp
explorer
Open Source XRP Ledger Explorer
Stars: ✭ 18 (-68.97%)
Mutual labels:  ripple, xrp
wallet-address-validator
Useful library for validation of Bitcoin, Litecoin, Ethereum and other cryptocoin addresses
Stars: ✭ 240 (+313.79%)
Mutual labels:  ripple, litecoin
Ta4j
A Java library for technical analysis.
Stars: ✭ 948 (+1534.48%)
Mutual labels:  ripple, litecoin
coinbin.org
₿ A Human–Friendly API Service for Crypto Currency Information.
Stars: ✭ 255 (+339.66%)
Mutual labels:  ripple, litecoin
CoinGecko
A C++20 library for CoinGecko--a cryptocurrency data service.
Stars: ✭ 69 (+18.97%)
Mutual labels:  ripple, litecoin
Moneda Cli
Command line to track cryptocurrency prices
Stars: ✭ 114 (+96.55%)
Mutual labels:  ripple, litecoin
cryptocoins-desklet-cinnamon
Cryptocurrency Ticker (Desklet) for Cinnamon Desktop that displays the current price for thousands of cryptocurrencies, and their daily percent changes.
Stars: ✭ 18 (-68.97%)
Mutual labels:  ripple, litecoin

node-bitstamp

bitstamp REST and WS API Node.js client 💵

README Overview

Offers

  • version 1 and version 2 of the bistamp REST API
  • supports all new api endpoints
  • 100% promise based
  • optional full control of response status and headers
  • all bitstamp currencies available: Bitcoin, Ethereum, Litecoin, Ripple, XRP
  • also implements the websocket API v2 to listen for live trade, order book and live order events
  • streams reconnect automatically and respect Forced reconnection via bts:request_reconnect
  • takes care of signature and nonce automatically
  • takes care of max. request quotas automatically (prevents bans)
  • install via npm i node-bitstamp or yarn add node-bitstamp

Example

  • you can find a runnable api example here, run via yarn example:api
  • you can find a runnable stream example here, run via yarn example:stream
"use strict";

const {BitstampStream, Bitstamp, CURRENCY} = require("node-bitstamp");

//printing available currencies
console.log(CURRENCY);

/* STREAMS */
// @ https://www.bitstamp.net/websocket/v2/

// Live trades
const bitstampStream = new BitstampStream();

/*
    as the stream is re-usable (subscribe to multiple currencies and channel types)
    every subscribe actions returns a channel name, which is the actual event you
    can listen to after subscription
*/

bitstampStream.on("connected", () => {
    const ethEurTickerChannel = bitstampStream.subscribe(bitstampStream.CHANNEL_LIVE_TRADES, CURRENCY.ETH_EUR);
    bitstampStream.on(ethEurTickerChannel, ({ data, event }) => {
        console.log(data);
        /* e.g.
            { 
                amount: 0.01513062,
                buy_order_id: 297260696,
                sell_order_id: 297260910,
                amount_str: '0.01513062',
                price_str: '212.80',
                timestamp: '1505558814',
                price: 212.8,
                type: 1,
                id: 21565524,
                cost: 3.219795936
            }
        */
    });
});
bitstampStream.on("disconnected", () => {});

// Live orderBook updates
bitstampStream.on("connected", () => {
    const btcEurOrderBookChannel = bitstampStream.subscribe(bitstampStream.CHANNEL_ORDER_BOOK, CURRENCY.BTC_EUR);

    bitstampStream.on(btcEurOrderBookChannel, ({ data, event }) => {
        console.log(data);
        /* e.g.
            { bids:
            [ 
                [ '3284.06000000', '0.16927410' ],
                [ '3284.05000000', '1.00000000' ],
                [ '3284.02000000', '0.72755647' ],
                .....
            ],
            asks:
            [ 
                [ '3289.00000000', '3.16123001' ],
                [ '3291.99000000', '0.22000000' ],
                [ '3292.00000000', '49.94312963' ],
                .....
            ] }
        */
    });
});

bitstampStream.on("error", (e) => console.error(e));

bitstampStream.close();

/* REST-API */
// @ https://www.bitstamp.net/api/

// @ https://www.bitstamp.net/account/login/
// To get an API key, go to "Account", "Security" and then "API Access". 
// Set permissions and click "Generate key"
// Dont forget to active the key and confirm the email.
const key = "abc3def4ghi5jkl6mno7";
const secret = "abcdefghijklmno";
const clientId = "123123";

const bitstamp = new Bitstamp({
    key,
    secret,
    clientId,
    timeout: 5000,
    rateLimit: true //turned on by default
});

const run = async () => {

    /*
        Every api function returns a bluebird promise.
        The promise only rejects on network errors or timeouts.
        A successfull promise always resolves in an object containing status, headers and body.
        status is the http status code as number, headers is an object of http response headers
        and body is the parsed JSON response body of the api, you dont need to parse the results
        yourself you can simply continue by accessing the object.
    */

    /* PUBLIC */
    const ticker = await bitstamp.ticker(CURRENCY.ETH_BTC).then(({status, headers, body}) => console.log(body));
    await bitstamp.tickerHour(CURRENCY.ETH_BTC);
    await bitstamp.orderBook(CURRENCY.ETH_BTC);
    await bitstamp.transactions(CURRENCY.ETH_BTC, "hour");
    await bitstamp.conversionRate();

    /* PRIVATE */
    const balance = await bitstamp.balance().then(({body:data}) => data);
    await bitstamp.userTransaction(CURRENCY.ETH_BTC, {offset, limit, sort});

    await bitstamp.openOrders(CURRENCY.ETH_BTC);
    await bitstamp.openOrdersAll();
    await bitstamp.orderStatus(id);
    await bitstamp.cancelOrder(id);
    await bitstamp.cancelOrdersAll();

    await bitstamp.buyLimitOrder(amount, price, currency, limit_price, daily_order);
    await bitstamp.sellLimitOrder(amount, price, currency, limit_price, daily_order);
    await bitstamp.buyMarketOrder(amount, currency);
    await bitstamp.sellMarketOrder(amount, currency);

    await bitstamp.withDrawalRequests(timedelta);
    await bitstamp.bitcoinWithdrawal(amount, address, instant);
    await bitstamp.bchWithdrawal(amount, address);
    await bitstamp.litecoinWithdrawal(amount, address);
    await bitstamp.ethereumWithdrawal(amount, address);
    await bitstamp.rippleWithdrawal(amount, address, currency);
    await bitstamp.xrpWithdrawal(amount, address, destination_tag);

    await bitstamp.bitcoinDepositAdress().then(({body}) => console.log(body));
    await bitstamp.bchDepositAdress().then(({body}) => console.log(body));
    await bitstamp.litecoinDepositAdress().then(({body}) => console.log(body));
    await bitstamp.ethereumDepositAdress().then(({body}) => console.log(body));
    await bitstamp.rippleDepositAdress().then(({body}) => console.log(body));
    await bitstamp.xrpDepositAdress().then(({body}) => console.log(body));

    await bitstamp.unconfirmedBitcoinDeposits();
    await bitstamp.transferSubToMain(amount, currency, subAccount);
    await bitstamp.transferMainToSub(amount, currency, subAccount);

    await bitstamp.openBankWithdrawal(/* {..} */);
    await bitstamp.bankWithdrawalStatus(id);
    await bitstamp.cancelBankWithdrawal(id);

    await bitstamp.newLiquidationAddress(currency);
    await bitstamp.liquidationAddressInfo(address);
};

run().then(() => {
    console.log(bitstamp.getStats());
    bitstamp.close();
});

Debug Info

DEBUG=node-bitstamp:* npm start

A word on parallel requests

  • The client will never generate the same nonce for two requests.
  • But a new request must always contain a higher nonce, than the last request before.
  • When you make multiple calls in parallel (pretty easy in node..) there is a chance that the later calls reach the bitstamp api earlier than the first, causing the first requests to fail with an invalid nonce error.
  • To prevent this you should make these calls sequentially.
  • Besides chaining promises, this is another way to do it:
const async = require("async"); // npm i async or yarn add async

async.series([
    cb => bitstamp.bitcoinDepositAdress()
        .then(r => cb(null, "BTC: " + r.body)).catch(e => cb(e)),
    cb => bitstamp.ethereumDepositAdress()
        .then(r => cb(null, "ETH: " + r.body.address)).catch(e => cb(e)),
    cb => bitstamp.litecoinDepositAdress()
        .then(r => cb(null, "LTC: " + r.body.address)).catch(e => cb(e))
], (error, data) => {

    if(error){
        return console.error(error);
    }

    console.log(data); // [ "BTC: ..", "ETH: ..", "LTC: .." ]
});

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].