{"_id":"@0xcmp/gdax","_rev":"2-708a0c4491a66026ba1a9efd01fbb3c1","name":"@0xcmp/gdax","description":"Client for the GDAX API","dist-tags":{"latest":"0.5.1"},"versions":{"0.5.1":{"name":"@0xcmp/gdax","version":"0.5.1","author":{"name":"Coinbase"},"bugs":{"url":"https://github.com/coinbase/gdax-node/issues"},"contributors":[{"name":"Peter Downs","email":"peterldowns@gmail.com","url":"http://peterdowns.com"},{"name":"Maksim Stepanenko","email":"maksimus16@gmail.com","url":"http://maksim.ms"},{"name":"Miha Rebernik","email":"miha@rebernik.info","url":"http://miha.rebernik.info"}],"dependencies":{"bignumber.js":"^5.0.0","bintrees":"^1.0.1","request":"^2.81.0","ws":"^4.0.0","crypto-js":"^3.1.9-1"},"description":"Client for the GDAX API","devDependencies":{"eslint":"^4.0.0","husky":"^0.13.4","lint-staged":"^3.6.1","mocha":"^5.0.0","nock":"^9.0.13","prettier":"^1.9.2"},"directories":{"lib":"./lib"},"engines":{"node":">=6.0.0"},"homepage":"https://github.com/coinbase/gdax-node","keywords":["API","bitcoin","coinbase","exchange","real-time","trading","websockets","gdax","ethereum"],"license":"MIT","main":"index.js","types":"index.d.ts","repository":{"type":"git","url":"git://github.com/coinbase/gdax-node.git"},"scripts":{"test":"mocha --full-trace --ui tdd --bail --reporter spec tests/*.js","precommit":"lint-staged"},"lint-staged":{"*.{js}":["eslint --fix","prettier --write","git add"],"*.{json,md}":["prettier --write","git add"]},"gitHead":"36e4a2e6a763d2bd1df498d3f3b59c2352d3061a","_id":"@0xcmp/gdax@0.5.1","_shasum":"25b775fcfc824b44371b3bfad675b124bd142891","_from":".","_npmVersion":"3.10.10","_nodeVersion":"6.10.3","_npmUser":{"name":"0xcmp","email":"me+npm@cmp.is"},"dist":{"shasum":"25b775fcfc824b44371b3bfad675b124bd142891","tarball":"https://registry.npmjs.org/@0xcmp/gdax/-/gdax-0.5.1.tgz","integrity":"sha512-laBiOR4gd7pZeNSwcuzeReV7P9krhSB43k/IhgpeF3z/v3C2kut2aJpPEQ0PzUv4Iyv6cPw5DY6UqCL4FlsGzQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCI3bNdjlIW7u5jigHOrK4JcEKNsfL3lswnc2F84dUK5QIgXoszptV2yUAqWZJIwlh/2GMNtH9QrHKWGwLqpDjnvX8="}]},"maintainers":[{"name":"0xcmp","email":"me+npm@cmp.is"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/gdax-0.5.1.tgz_1517188212489_0.44675499689765275"}}},"readme":"# GDAX [![CircleCI](https://circleci.com/gh/coinbase/gdax-node.svg?style=svg)](https://circleci.com/gh/coinbase/gdax-node) [![npm version](https://badge.fury.io/js/gdax.svg)](https://badge.fury.io/js/gdax)\n\nThe official Node.js library for Coinbase's [GDAX API](https://docs.gdax.com/).\n\n## Features\n\n* Easy functionality to use in programmatic trading\n* A customizable, websocket-synced Order Book implementation\n* API clients with convenient methods for every API endpoint\n* Abstracted interfaces – don't worry about HMAC signing or JSON formatting; the\n  library does it for you\n\n## Installation\n\n```bash\nnpm install gdax\n```\n\nYou can learn about the API responses of each endpoint [by reading our\ndocumentation](https://docs.gdax.com/#market-data).\n\n## Quick Start\n\nThe GDAX API has both public and private endpoints. If you're only interested in\nthe public endpoints, you should use a `PublicClient`.\n\n```js\nconst Gdax = require('gdax');\nconst publicClient = new Gdax.PublicClient();\n```\n\nAll methods, unless otherwise specified, can be used with either a promise or\ncallback API.\n\n### Using Promises\n\n```js\npublicClient\n  .getProducts()\n  .then(data => {\n    // work with data\n  })\n  .catch(error => {\n    // handle the error\n  });\n```\n\nThe promise API can be used as expected in `async` functions in ES2017+\nenvironments:\n\n```js\nasync function yourFunction() {\n  try {\n    const products = await publicClient.getProducts();\n  } catch (error) {\n    /* ... */\n  }\n}\n```\n\n### Using Callbacks\n\nYour callback should accept two arguments:\n\n* `error`: contains an error message (`string`), or `null` if no was error\n  encountered\n* `response`: a generic HTTP response abstraction created by the [`request`\n  library](https://github.com/request/request)\n* `data`: contains data returned by the GDAX API, or `undefined` if an error was\n  encountered\n\n```js\npublicClient.getProducts((error, response, data) => {\n  if (error) {\n    // handle the error\n  } else {\n    // work with data\n  }\n});\n```\n\n**NOTE:** if you supply a callback, no promise will be returned. This is to\nprevent potential `UnhandledPromiseRejectionWarning`s, which will cause future\nversions of Node to terminate.\n\n```js\nconst myCallback = (err, response, data) => {\n  /* ... */\n};\n\nconst result = publicClient.getProducts(myCallback);\n\nresult.then(() => {\n  /* ... */\n}); // TypeError: Cannot read property 'then' of undefined\n```\n\n### Optional Parameters\n\nSome methods accept optional parameters, e.g.\n\n```js\npublicClient.getProductOrderBook('BTC-USD', { level: 3 }).then(book => {\n  /* ... */\n});\n```\n\nTo use optional parameters with callbacks, supply the options as the first\nparameter(s) and the callback as the last parameter:\n\n```js\npublicClient.getProductOrderBook(\n  'ETH-USD',\n  { level: 3 },\n  (error, response, book) => {\n    /* ... */\n  }\n);\n```\n\n### The Public API Client\n\n```js\nconst publicClient = new Gdax.PublicClient(endpoint);\n```\n\n* `productID` _optional_ - defaults to 'BTC-USD' if not specified.\n* `endpoint` _optional_ - defaults to 'https://api.gdax.com' if not specified.\n\n#### Public API Methods\n\n* [`getProducts`](https://docs.gdax.com/#get-products)\n\n```js\npublicClient.getProducts(callback);\n```\n\n* [`getProductOrderBook`](https://docs.gdax.com/#get-product-order-book)\n\n```js\n// Get the order book at the default level of detail.\npublicClient.getProductOrderBook('BTC-USD', callback);\n\n// Get the order book at a specific level of detail.\npublicClient.getProductOrderBook('LTC-USD', { level: 3 }, callback);\n```\n\n* [`getProductTicker`](https://docs.gdax.com/#get-product-ticker)\n\n```js\npublicClient.getProductTicker('ETH-USD', callback);\n```\n\n* [`getProductTrades`](https://docs.gdax.com/#get-trades)\n\n```js\npublicClient.getProductTrades('BTC-USD', callback);\n\n// To make paginated requests, include page parameters\npublicClient.getProductTrades('BTC-USD', { after: 1000 }, callback);\n```\n\n* [`getProductTradeStream`](https://docs.gdax.com/#get-trades)\n\nWraps around `getProductTrades`, fetches all trades with IDs `>= tradesFrom` and\n`<= tradesTo`. Handles pagination and rate limits.\n\n```js\nconst trades = publicClient.getProductTradeStream('BTC-USD', 8408000, 8409000);\n\n// tradesTo can also be a function\nconst trades = publicClient.getProductTradeStream(\n  'BTC-USD',\n  8408000,\n  trade => Date.parse(trade.time) >= 1463068e6\n);\n```\n\n* [`getProductHistoricRates`](https://docs.gdax.com/#get-historic-rates)\n\n```js\npublicClient.getProductHistoricRates('BTC-USD', callback);\n\n// To include extra parameters:\npublicClient.getProductHistoricRates(\n  'BTC-USD',\n  { granularity: 3600 },\n  callback\n);\n```\n\n* [`getProduct24HrStats`](https://docs.gdax.com/#get-24hr-stats)\n\n```js\npublicClient.getProduct24HrStats('BTC-USD', callback);\n```\n\n* [`getCurrencies`](https://docs.gdax.com/#get-currencies)\n\n```js\npublicClient.getCurrencies(callback);\n```\n\n* [`getTime`](https://docs.gdax.com/#time)\n\n```js\npublicClient.getTime(callback);\n```\n\n### The Authenticated API Client\n\nThe [private exchange API endpoints](https://docs.gdax.com/#private) require you\nto authenticate with a GDAX API key. You can create a new API key [in your\nexchange account's settings](https://gdax.com/settings). You can also specify\nthe API URI (defaults to `https://api.gdax.com`).\n\n```js\nconst key = 'your_api_key';\nconst secret = 'your_b64_secret';\nconst passphrase = 'your_passphrase';\n\nconst apiURI = 'https://api.gdax.com';\nconst sandboxURI = 'https://api-public.sandbox.gdax.com';\n\nconst authedClient = new Gdax.AuthenticatedClient(\n  key,\n  secret,\n  passphrase,\n  apiURI\n);\n```\n\nLike `PublicClient`, all API methods can be used with either callbacks or will\nreturn promises.\n\n`AuthenticatedClient` inherits all of the API methods from\n`PublicClient`, so if you're hitting both public and private API endpoints you\nonly need to create a single client.\n\n#### Private API Methods\n\n* [`getCoinbaseAccounts`](https://docs.gdax.com/#coinbase-accounts)\n\n```javascript\nauthedClient.getCoinbaseAccounts(callback);\n```\n\n* [`getPaymentMethods`](https://docs.gdax.com/#payment-methods)\n\n```javascript\nauthedClient.getPaymentMethods(callback);\n```\n\n* [`getAccounts`](https://docs.gdax.com/#list-accounts)\n\n```js\nauthedClient.getAccounts(callback);\n```\n\n* [`getAccount`](https://docs.gdax.com/#get-an-account)\n\n```js\nconst accountID = '7d0f7d8e-dd34-4d9c-a846-06f431c381ba';\nauthedClient.getAccount(accountID, callback);\n```\n\n* [`getAccountHistory`](https://docs.gdax.com/#get-account-history)\n\n```js\nconst accountID = '7d0f7d8e-dd34-4d9c-a846-06f431c381ba';\nauthedClient.getAccountHistory(accountID, callback);\n\n// For pagination, you can include extra page arguments\nauthedClient.getAccountHistory(accountID, { before: 3000 }, callback);\n```\n\n* [`getAccountHolds`](https://docs.gdax.com/#get-holds)\n\n```js\nconst accountID = '7d0f7d8e-dd34-4d9c-a846-06f431c381ba';\nauthedClient.getAccountHolds(accountID, callback);\n\n// For pagination, you can include extra page arguments\nauthedClient.getAccountHolds(accountID, { before: 3000 }, callback);\n```\n\n* [`buy`, `sell`](https://docs.gdax.com/#place-a-new-order)\n\n```js\n// Buy 1 BTC @ 100 USD\nconst buyParams = {\n  price: '100.00', // USD\n  size: '1', // BTC\n  product_id: 'BTC-USD',\n};\nauthedClient.buy(buyParams, callback);\n\n// Sell 1 BTC @ 110 USD\nconst sellParams = {\n  price: '110.00', // USD\n  size: '1', // BTC\n  product_id: 'BTC-USD',\n};\nauthedClient.sell(sellParams, callback);\n```\n\n* [`placeOrder`](https://docs.gdax.com/#place-a-new-order)\n\n```js\n// Buy 1 LTC @ 75 USD\nconst params = {\n  side: 'buy',\n  price: '75.00', // USD\n  size: '1', // LTC\n  product_id: 'LTC-USD',\n};\nauthedClient.placeOrder(params, callback);\n```\n\n* [`cancelOrder`](https://docs.gdax.com/#cancel-an-order)\n\n```js\nconst orderID = 'd50ec984-77a8-460a-b958-66f114b0de9b';\nauthedClient.cancelOrder(orderID, callback);\n```\n\n* [`cancelOrders`](https://docs.gdax.com/#cancel-all)\n\n```js\nauthedClient.cancelOrders(callback);\n```\n\n* [`cancelAllOrders`](https://docs.gdax.com/#cancel-all)\n\n```js\n// `cancelOrders` may require you to make the request multiple times until\n// all of the orders are deleted.\n\n// `cancelAllOrders` will handle making these requests for you asynchronously.\n// Also, you can add a `product_id` param to only delete orders of that product.\n\n// The data will be an array of the order IDs of all orders which were cancelled\nauthedClient.cancelAllOrders({ product_id: 'BTC-USD' }, callback);\n```\n\n* [`getOrders`](https://docs.gdax.com/#list-open-orders)\n\n```js\nauthedClient.getOrders(callback);\n// For pagination, you can include extra page arguments\n// Get all orders of 'open' status\nauthedClient.getOrders({ after: 3000, status: 'open' }, callback);\n```\n\n* [`getOrder`](https://docs.gdax.com/#get-an-order)\n\n```js\nconst orderID = 'd50ec984-77a8-460a-b958-66f114b0de9b';\nauthedClient.getOrder(orderID, callback);\n```\n\n* [`getFills`](https://docs.gdax.com/#list-fills)\n\n```js\nauthedClient.getFills(callback);\n// For pagination, you can include extra page arguments\nauthedClient.getFills({ before: 3000 }, callback);\n```\n\n* [`getFundings`](https://docs.gdax.com/#list-fundings)\n\n```js\nauthedClient.getFundings({}, callback);\n```\n\n* [`repay`](https://docs.gdax.com/#repay)\n\n```js\nconst params = {\n  amount: '2000.00',\n  currency: 'USD',\n};\nauthedClient.repay(params, callback);\n```\n\n* [`marginTransfer`](https://docs.gdax.com/#margin-transfer)\n\n```js\nconst params =\n  'margin_profile_id': '45fa9e3b-00ba-4631-b907-8a98cbdf21be',\n  'type': 'deposit',\n  'currency': 'USD',\n  'amount': 2\n};\nauthedClient.marginTransfer(params, callback);\n```\n\n* [`closePosition`](https://docs.gdax.com/#close)\n\n```js\nconst params = {\n  repay_only: false,\n};\nauthedClient.closePosition(params, callback);\n```\n\n* [`deposit`, `withdraw`](https://docs.gdax.com/#deposits)\n\n```js\n// Deposit to your Exchange USD account from your Coinbase USD account.\nconst depositParamsUSD = {\n  amount: '100.00',\n  currency: 'USD',\n  coinbase_account_id: '60680c98bfe96c2601f27e9c', // USD Coinbase Account ID\n};\nauthedClient.deposit(depositParamsUSD, callback);\n\n// Withdraw from your Exchange USD account to your Coinbase USD account.\nconst withdrawParamsUSD = {\n  amount: '100.00',\n  currency: 'USD',\n  coinbase_account_id: '60680c98bfe96c2601f27e9c', // USD Coinbase Account ID\n};\nauthedClient.withdraw(withdrawParamsUSD, callback);\n\n// Deposit to your Exchange BTC account from your Coinbase BTC account.\nconst depositParamsBTC = {\n  amount: '2.0',\n  currency: 'BTC',\n  coinbase_account_id: '536a541fa9393bb3c7000023', // BTC Coinbase Account ID\n};\nauthedClient.deposit(depositParamsBTC, callback);\n\n// Withdraw from your Exchange BTC account to your Coinbase BTC account.\nconst withdrawParamsBTC = {\n  amount: '2.0',\n  currency: 'BTC',\n  coinbase_account_id: '536a541fa9393bb3c7000023', // BTC Coinbase Account ID\n};\nauthedClient.withdraw(withdrawParamsBTC, callback);\n\n// Withdraw from your Exchange BTC account to another BTC address.\nconst withdrawAddressParams = {\n  amount: 10.0,\n  currency: 'BTC',\n  crypto_address: '15USXR6S4DhSWVHUxXRCuTkD1SA6qAdy',\n};\nauthedClient.withdrawCrypto(withdrawAddressParams, callback);\n```\n\n* [`getTrailingVolume`](https://docs.gdax.com/#user-account)\n\n```js\n// Get your 30 day trailing volumes\nauthedClient.getTrailingVolume(callback);\n```\n\n### Websocket Client\n\nThe `WebsocketClient` allows you to connect and listen to the [exchange\nwebsocket messages](https://docs.gdax.com/#messages).\n\n```js\nconst websocket = new Gdax.WebsocketClient(['BTC-USD', 'ETH-USD']);\n\nwebsocket.on('message', data => {\n  /* work with data */\n});\nwebsocket.on('error', err => {\n  /* handle error */\n});\nwebsocket.on('close', () => {\n  /* ... */\n});\n```\n\nThe client will automatically subscribe to the `heartbeat` channel. By\ndefault, the `full` channel will be subscribed to unless other channels are\nrequested.\n\n```javascript\nconst websocket = new Gdax.WebsocketClient(\n  ['BTC-USD', 'ETH-USD'],\n  'https://api-public.sandbox.gdax.com',\n  {\n    key: 'suchkey',\n    secret: 'suchsecret',\n    passphrase: 'muchpassphrase',\n  },\n  { channels: ['full', 'level2'] }\n);\n\n```\n\nOptionally, [change subscriptions at runtime](https://docs.gdax.com/#subscribe):\n\n```javascript\nwebsocket.unsubscribe({ channels: ['full'] });\n\nwebsocket.subscribe({ product_ids: ['LTC-USD'], channels: ['ticker', 'user'] });\n\nwebsocket.subscribe({\n  channels: [{\n    name: 'user',\n    product_ids: ['ETH-USD']\n  }]\n});\n\nwebsocket.unsubscribe({\n  channels: [{\n    name: 'user',\n    product_ids: ['LTC-USD']\n  }, {\n    name: 'user',\n    product_ids: ['ETH-USD']\n  }]\n});\n```\n\nThe following events can be emitted from the `WebsocketClient`:\n\n* `open`\n* `message`\n* `close`\n* `error`\n\n### Orderbook\n\n`Orderbook` is a data structure that can be used to store a local copy of the\norderbook.\n\n```js\nconst orderbook = new Gdax.Orderbook();\n```\n\nThe orderbook has the following methods:\n\n* `state(book)`\n* `get(orderId)`\n* `add(order)`\n* `remove(orderId)`\n* `match(match)`\n* `change(change)`\n\n### Orderbook Sync\n\n`OrderbookSync` creates a local mirror of the orderbook on GDAX using\n`Orderbook` and `WebsocketClient` as described\n[here](https://docs.gdax.com/#real-time-order-book).\n\n```js\nconst orderbookSync = new Gdax.OrderbookSync(['BTC-USD', 'ETH-USD']);\nconsole.log(orderbookSync.books['ETH-USD'].state());\n```\n\n## Testing\n\n```bash\nnpm test\n\n# test for known vulnerabilities in packages\nnpm install -g nsp\nnsp check --output summary\n```\n","maintainers":[{"name":"0xcmp","email":"me+npm@cmp.is"}],"time":{"modified":"2022-06-12T14:09:18.599Z","created":"2018-01-29T01:10:13.707Z","0.5.1":"2018-01-29T01:10:13.707Z"},"homepage":"https://github.com/coinbase/gdax-node","keywords":["API","bitcoin","coinbase","exchange","real-time","trading","websockets","gdax","ethereum"],"repository":{"type":"git","url":"git://github.com/coinbase/gdax-node.git"},"contributors":[{"name":"Peter Downs","email":"peterldowns@gmail.com","url":"http://peterdowns.com"},{"name":"Maksim Stepanenko","email":"maksimus16@gmail.com","url":"http://maksim.ms"},{"name":"Miha Rebernik","email":"miha@rebernik.info","url":"http://miha.rebernik.info"}],"author":{"name":"Coinbase"},"bugs":{"url":"https://github.com/coinbase/gdax-node/issues"},"license":"MIT","readmeFilename":"README.md"}