{"id":16703309,"url":"https://github.com/krystianity/node-bitstamp","last_synced_at":"2025-05-07T15:10:36.763Z","repository":{"id":50926352,"uuid":"103701325","full_name":"krystianity/node-bitstamp","owner":"krystianity","description":"bitstamp REST and WS API Node.js client :dollar:","archived":false,"fork":false,"pushed_at":"2022-12-08T19:09:04.000Z","size":86,"stargazers_count":59,"open_issues_count":9,"forks_count":36,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-03-31T11:21:08.258Z","etag":null,"topics":["api","bitcoin","bitstamp","ethereum","litecoin","order","rest","ripple","socket","transfer","xrp"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/krystianity.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-09-15T21:05:20.000Z","updated_at":"2024-06-01T23:38:39.000Z","dependencies_parsed_at":"2023-01-25T06:55:14.375Z","dependency_job_id":null,"html_url":"https://github.com/krystianity/node-bitstamp","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krystianity%2Fnode-bitstamp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krystianity%2Fnode-bitstamp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krystianity%2Fnode-bitstamp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krystianity%2Fnode-bitstamp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/krystianity","download_url":"https://codeload.github.com/krystianity/node-bitstamp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252902615,"owners_count":21822262,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","bitcoin","bitstamp","ethereum","litecoin","order","rest","ripple","socket","transfer","xrp"],"created_at":"2024-10-12T19:07:48.166Z","updated_at":"2025-05-07T15:10:36.721Z","avatar_url":"https://github.com/krystianity.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# node-bitstamp\n\nbitstamp REST and WS API Node.js client :dollar:\n\n## README Overview\n\n* [Offers](#offers)\n* [Example](#example)\n* [Debug Info](#debug-info)\n* [A word on parallel requests](#a-word-on-parallel-requests)\n* [License](#license)\n\n## Offers\n\n* version 1 and version 2 of the bistamp REST API\n* supports all new api endpoints\n* 100% promise based\n* optional full control of response status and headers\n* all bitstamp currencies available: Bitcoin, Ethereum, Litecoin, Ripple, XRP\n* also implements the websocket API v2 to listen for live trade, order book and live order events\n* streams reconnect automatically and respect Forced reconnection via `bts:request_reconnect`\n* takes care of signature and nonce automatically\n* takes care of max. request quotas automatically (prevents bans)\n* install via `npm i node-bitstamp` or `yarn add node-bitstamp`\n\n## Example\n\n* you can find a runnable api example [here](example/api.js), run via `yarn example:api`\n* you can find a runnable stream example [here](example/stream.js), run via `yarn example:stream`\n\n```javascript\n\"use strict\";\n\nconst {BitstampStream, Bitstamp, CURRENCY} = require(\"node-bitstamp\");\n\n//printing available currencies\nconsole.log(CURRENCY);\n\n/* STREAMS */\n// @ https://www.bitstamp.net/websocket/v2/\n\n// Live trades\nconst bitstampStream = new BitstampStream();\n\n/*\n    as the stream is re-usable (subscribe to multiple currencies and channel types)\n    every subscribe actions returns a channel name, which is the actual event you\n    can listen to after subscription\n*/\n\nbitstampStream.on(\"connected\", () =\u003e {\n    const ethEurTickerChannel = bitstampStream.subscribe(bitstampStream.CHANNEL_LIVE_TRADES, CURRENCY.ETH_EUR);\n    bitstampStream.on(ethEurTickerChannel, ({ data, event }) =\u003e {\n        console.log(data);\n        /* e.g.\n            { \n                amount: 0.01513062,\n                buy_order_id: 297260696,\n                sell_order_id: 297260910,\n                amount_str: '0.01513062',\n                price_str: '212.80',\n                timestamp: '1505558814',\n                price: 212.8,\n                type: 1,\n                id: 21565524,\n                cost: 3.219795936\n            }\n        */\n    });\n});\nbitstampStream.on(\"disconnected\", () =\u003e {});\n\n// Live orderBook updates\nbitstampStream.on(\"connected\", () =\u003e {\n    const btcEurOrderBookChannel = bitstampStream.subscribe(bitstampStream.CHANNEL_ORDER_BOOK, CURRENCY.BTC_EUR);\n\n    bitstampStream.on(btcEurOrderBookChannel, ({ data, event }) =\u003e {\n        console.log(data);\n        /* e.g.\n            { bids:\n            [ \n                [ '3284.06000000', '0.16927410' ],\n                [ '3284.05000000', '1.00000000' ],\n                [ '3284.02000000', '0.72755647' ],\n                .....\n            ],\n            asks:\n            [ \n                [ '3289.00000000', '3.16123001' ],\n                [ '3291.99000000', '0.22000000' ],\n                [ '3292.00000000', '49.94312963' ],\n                .....\n            ] }\n        */\n    });\n});\n\nbitstampStream.on(\"error\", (e) =\u003e console.error(e));\n\nbitstampStream.close();\n\n/* REST-API */\n// @ https://www.bitstamp.net/api/\n\n// @ https://www.bitstamp.net/account/login/\n// To get an API key, go to \"Account\", \"Security\" and then \"API Access\". \n// Set permissions and click \"Generate key\"\n// Dont forget to active the key and confirm the email.\nconst key = \"abc3def4ghi5jkl6mno7\";\nconst secret = \"abcdefghijklmno\";\nconst clientId = \"123123\";\n\nconst bitstamp = new Bitstamp({\n    key,\n    secret,\n    clientId,\n    timeout: 5000,\n    rateLimit: true //turned on by default\n});\n\nconst run = async () =\u003e {\n\n    /*\n        Every api function returns a bluebird promise.\n        The promise only rejects on network errors or timeouts.\n        A successfull promise always resolves in an object containing status, headers and body.\n        status is the http status code as number, headers is an object of http response headers\n        and body is the parsed JSON response body of the api, you dont need to parse the results\n        yourself you can simply continue by accessing the object.\n    */\n\n    /* PUBLIC */\n    const ticker = await bitstamp.ticker(CURRENCY.ETH_BTC).then(({status, headers, body}) =\u003e console.log(body));\n    await bitstamp.tickerHour(CURRENCY.ETH_BTC);\n    await bitstamp.orderBook(CURRENCY.ETH_BTC);\n    await bitstamp.transactions(CURRENCY.ETH_BTC, \"hour\");\n    await bitstamp.conversionRate();\n\n    /* PRIVATE */\n    const balance = await bitstamp.balance().then(({body:data}) =\u003e data);\n    await bitstamp.userTransaction(CURRENCY.ETH_BTC, {offset, limit, sort});\n\n    await bitstamp.openOrders(CURRENCY.ETH_BTC);\n    await bitstamp.openOrdersAll();\n    await bitstamp.orderStatus(id);\n    await bitstamp.cancelOrder(id);\n    await bitstamp.cancelOrdersAll();\n\n    await bitstamp.buyLimitOrder(amount, price, currency, limit_price, daily_order);\n    await bitstamp.sellLimitOrder(amount, price, currency, limit_price, daily_order);\n    await bitstamp.buyMarketOrder(amount, currency);\n    await bitstamp.sellMarketOrder(amount, currency);\n\n    await bitstamp.withDrawalRequests(timedelta);\n    await bitstamp.bitcoinWithdrawal(amount, address, instant);\n    await bitstamp.bchWithdrawal(amount, address);\n    await bitstamp.litecoinWithdrawal(amount, address);\n    await bitstamp.ethereumWithdrawal(amount, address);\n    await bitstamp.rippleWithdrawal(amount, address, currency);\n    await bitstamp.xrpWithdrawal(amount, address, destination_tag);\n\n    await bitstamp.bitcoinDepositAdress().then(({body}) =\u003e console.log(body));\n    await bitstamp.bchDepositAdress().then(({body}) =\u003e console.log(body));\n    await bitstamp.litecoinDepositAdress().then(({body}) =\u003e console.log(body));\n    await bitstamp.ethereumDepositAdress().then(({body}) =\u003e console.log(body));\n    await bitstamp.rippleDepositAdress().then(({body}) =\u003e console.log(body));\n    await bitstamp.xrpDepositAdress().then(({body}) =\u003e console.log(body));\n\n    await bitstamp.unconfirmedBitcoinDeposits();\n    await bitstamp.transferSubToMain(amount, currency, subAccount);\n    await bitstamp.transferMainToSub(amount, currency, subAccount);\n\n    await bitstamp.openBankWithdrawal(/* {..} */);\n    await bitstamp.bankWithdrawalStatus(id);\n    await bitstamp.cancelBankWithdrawal(id);\n\n    await bitstamp.newLiquidationAddress(currency);\n    await bitstamp.liquidationAddressInfo(address);\n};\n\nrun().then(() =\u003e {\n    console.log(bitstamp.getStats());\n    bitstamp.close();\n});\n```\n\n## Debug Info\n\n`DEBUG=node-bitstamp:* npm start`\n\n## A word on parallel requests\n\n* The client will never generate the same nonce for two requests.\n* But a new request must always contain a higher nonce, than the last request before.\n* When you make multiple calls in parallel (pretty easy in node..) there is a chance\n    that the later calls reach the bitstamp api earlier than the first, causing the first\n    requests to fail with an `invalid nonce` error.\n* To prevent this you should make these calls sequentially.\n* Besides chaining promises, this is another way to do it:\n\n```javascript\nconst async = require(\"async\"); // npm i async or yarn add async\n\nasync.series([\n    cb =\u003e bitstamp.bitcoinDepositAdress()\n        .then(r =\u003e cb(null, \"BTC: \" + r.body)).catch(e =\u003e cb(e)),\n    cb =\u003e bitstamp.ethereumDepositAdress()\n        .then(r =\u003e cb(null, \"ETH: \" + r.body.address)).catch(e =\u003e cb(e)),\n    cb =\u003e bitstamp.litecoinDepositAdress()\n        .then(r =\u003e cb(null, \"LTC: \" + r.body.address)).catch(e =\u003e cb(e))\n], (error, data) =\u003e {\n\n    if(error){\n        return console.error(error);\n    }\n\n    console.log(data); // [ \"BTC: ..\", \"ETH: ..\", \"LTC: ..\" ]\n});\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrystianity%2Fnode-bitstamp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkrystianity%2Fnode-bitstamp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrystianity%2Fnode-bitstamp/lists"}