{"id":13517969,"url":"https://github.com/coinbase/coinbase-pro-node","last_synced_at":"2025-03-31T09:31:00.627Z","repository":{"id":41497733,"uuid":"63640204","full_name":"coinbase/coinbase-pro-node","owner":"coinbase","description":"DEPRECATED — The official Node.js library for Coinbase Pro","archived":true,"fork":false,"pushed_at":"2020-01-16T05:40:14.000Z","size":402,"stargazers_count":852,"open_issues_count":0,"forks_count":320,"subscribers_count":62,"default_branch":"master","last_synced_at":"2025-02-03T09:52:31.875Z","etag":null,"topics":["bitcoin","coinbase","ethereum","gdax","gdax-api","orderbook","trade","trading","trading-api"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/coinbase.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-07-18T22:02:53.000Z","updated_at":"2025-01-31T02:03:23.000Z","dependencies_parsed_at":"2022-08-22T21:40:09.374Z","dependency_job_id":null,"html_url":"https://github.com/coinbase/coinbase-pro-node","commit_stats":null,"previous_names":["coinbase/gdax-node"],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coinbase%2Fcoinbase-pro-node","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coinbase%2Fcoinbase-pro-node/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coinbase%2Fcoinbase-pro-node/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coinbase%2Fcoinbase-pro-node/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/coinbase","download_url":"https://codeload.github.com/coinbase/coinbase-pro-node/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244409347,"owners_count":20448141,"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":["bitcoin","coinbase","ethereum","gdax","gdax-api","orderbook","trade","trading","trading-api"],"created_at":"2024-08-01T05:01:39.215Z","updated_at":"2025-03-31T09:31:00.285Z","avatar_url":"https://github.com/coinbase.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# Coinbase Pro [![CircleCI](https://circleci.com/gh/coinbase/coinbase-pro-node.svg?style=svg)](https://circleci.com/gh/coinbase/coinbase-pro-node) [![npm version](https://badge.fury.io/js/coinbase-pro.svg)](https://badge.fury.io/js/coinbase-pro)\n\n**Note**: The `gdax` package is deprecated and might have to be removed from NPM.\nPlease migrate to the `coinbase-pro` package to ensure future compatibility.\n\nThe official Node.js library for Coinbase's [Pro API](https://docs.pro.coinbase.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 coinbase-pro\n```\n\nYou can learn about the API responses of each endpoint [by reading our\ndocumentation](https://docs.pro.coinbase.com/#market-data).\n\n## Quick Start\n\nThe Coinbase Pro 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 CoinbasePro = require('coinbase-pro');\nconst publicClient = new CoinbasePro.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 =\u003e {\n    // work with data\n  })\n  .catch(error =\u003e {\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 three arguments:\n\n- `error`: contains an error message (`string`), or `null` if no error was\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 Coinbase Pro API, or `undefined` if an error was\n  encountered\n\n```js\npublicClient.getProducts((error, response, data) =\u003e {\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) =\u003e {\n  /* ... */\n};\n\nconst result = publicClient.getProducts(myCallback);\n\nresult.then(() =\u003e {\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 =\u003e {\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) =\u003e {\n    /* ... */\n  }\n);\n```\n\n### The Public API Client\n\n```js\nconst publicClient = new CoinbasePro.PublicClient(endpoint);\n```\n\n- `productID` _optional_ - defaults to 'BTC-USD' if not specified.\n- `endpoint` _optional_ - defaults to 'https://api.pro.coinbase.com' if not specified.\n\n#### Public API Methods\n\n- [`getProducts`](https://docs.pro.coinbase.com/#get-products)\n\n```js\npublicClient.getProducts(callback);\n```\n\n- [`getProductOrderBook`](https://docs.pro.coinbase.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.pro.coinbase.com/#get-product-ticker)\n\n```js\npublicClient.getProductTicker('ETH-USD', callback);\n```\n\n- [`getProductTrades`](https://docs.pro.coinbase.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.pro.coinbase.com/#get-trades)\n\nWraps around `getProductTrades`, fetches all trades with IDs `\u003e= tradesFrom` and\n`\u003c= 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 =\u003e Date.parse(trade.time) \u003e= 1463068e6\n);\n```\n\n- [`getProductHistoricRates`](https://docs.pro.coinbase.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.pro.coinbase.com/#get-24hr-stats)\n\n```js\npublicClient.getProduct24HrStats('BTC-USD', callback);\n```\n\n- [`getCurrencies`](https://docs.pro.coinbase.com/#get-currencies)\n\n```js\npublicClient.getCurrencies(callback);\n```\n\n- [`getTime`](https://docs.pro.coinbase.com/#time)\n\n```js\npublicClient.getTime(callback);\n```\n\n### The Authenticated API Client\n\nThe [private exchange API endpoints](https://docs.pro.coinbase.com/#private) require you\nto authenticate with a Coinbase Pro API key. You can create a new API key [in your\nexchange account's settings](https://pro.coinbase.com/profile/api). You can also specify\nthe API URI (defaults to `https://api.pro.coinbase.com`).\n\n```js\nconst key = 'your_api_key';\nconst secret = 'your_b64_secret';\nconst passphrase = 'your_passphrase';\n\nconst apiURI = 'https://api.pro.coinbase.com';\nconst sandboxURI = 'https://api-public.sandbox.pro.coinbase.com';\n\nconst authedClient = new CoinbasePro.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.pro.coinbase.com/#coinbase-accounts)\n\n```javascript\nauthedClient.getCoinbaseAccounts(callback);\n```\n\n- [`getPaymentMethods`](https://docs.pro.coinbase.com/#payment-methods)\n\n```javascript\nauthedClient.getPaymentMethods(callback);\n```\n\n- [`getAccounts`](https://docs.pro.coinbase.com/#list-accounts)\n\n```js\nauthedClient.getAccounts(callback);\n```\n\n- [`getAccount`](https://docs.pro.coinbase.com/#get-an-account)\n\n```js\nconst accountID = '7d0f7d8e-dd34-4d9c-a846-06f431c381ba';\nauthedClient.getAccount(accountID, callback);\n```\n\n- [`getAccountHistory`](https://docs.pro.coinbase.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- [`getAccountTransfers`](https://docs.pro.coinbase.com/#get-account-transfers)\n\n```js\nconst accountID = '7d0f7d8e-dd34-4d9c-a846-06f431c381ba';\nauthedClient.getAccountTransfers(accountID, callback);\n\n// For pagination, you can include extra page arguments\nauthedClient.getAccountTransfers(accountID, { before: 3000 }, callback);\n```\n\n- [`getAccountHolds`](https://docs.pro.coinbase.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.pro.coinbase.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.pro.coinbase.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.pro.coinbase.com/#cancel-an-order)\n\n```js\nconst orderID = 'd50ec984-77a8-460a-b958-66f114b0de9b';\nauthedClient.cancelOrder(orderID, callback);\n```\n\n- [`cancelOrders`](https://docs.pro.coinbase.com/#cancel-all)\n\n```js\n// Cancels \"open\" orders\nauthedClient.cancelOrders(callback);\n```\n\n- [`cancelAllOrders`](https://docs.pro.coinbase.com/#cancel-all)\n\n```js\n// `cancelOrders` may require you to make the request multiple times until\n// all of the \"open\" 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.pro.coinbase.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.pro.coinbase.com/#get-an-order)\n\n```js\nconst orderID = 'd50ec984-77a8-460a-b958-66f114b0de9b';\nauthedClient.getOrder(orderID, callback);\n```\n\n- [`getFills`](https://docs.pro.coinbase.com/#list-fills)\n\n```js\nconst params = {\n  product_id: 'LTC-USD',\n};\nauthedClient.getFills(params, callback);\n// For pagination, you can include extra page arguments\nauthedClient.getFills({ before: 3000 }, callback);\n```\n\n- [`getFundings`](https://docs.pro.coinbase.com/#list-fundings)\n\n```js\nauthedClient.getFundings({}, callback);\n```\n\n- [`repay`](https://docs.pro.coinbase.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.pro.coinbase.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.pro.coinbase.com/#close)\n\n```js\nconst params = {\n  repay_only: false,\n};\nauthedClient.closePosition(params, callback);\n```\n\n- [`convert`](https://docs.pro.coinbase.com/#create-conversion)\n\n```js\nconst params = {\n  from: 'USD',\n  to: 'USDC',\n  amount: '100',\n};\nauthedClient.convert(params, callback);\n```\n\n- [`deposit`, `withdraw`](https://docs.pro.coinbase.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// Fetch a deposit address from your Exchange BTC account.\nconst depositAddressParams = {\n  currency: 'BTC',\n};\nauthedClient.depositCrypto(depositAddressParams, 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- [`depositPayment`](https://docs.pro.coinbase.com/#payment-method)\n\n```js\n// Schedule Deposit to your Exchange USD account from a configured payment method.\nconst depositPaymentParamsUSD = {\n  amount: '100.00',\n  currency: 'USD',\n  payment_method_id: 'bc6d7162-d984-5ffa-963c-a493b1c1370b', // ach_bank_account\n};\nauthedClient.depositPayment(depositPaymentParamsUSD, callback);\n```\n\n- [`withdrawPayment`](https://docs.pro.coinbase.com/#payment-method47)\n\n```js\n// Withdraw from your Exchange USD account to a configured payment method.\nconst withdrawPaymentParamsUSD = {\n  amount: '100.00',\n  currency: 'USD',\n  payment_method_id: 'bc6d7162-d984-5ffa-963c-a493b1c1370b', // ach_bank_account\n};\nauthedClient.withdrawPayment(withdrawPaymentParamsUSD, callback);\n```\n\n- [`getTrailingVolume`](https://docs.pro.coinbase.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.pro.coinbase.com/#messages).\n\n```js\nconst websocket = new CoinbasePro.WebsocketClient(['BTC-USD', 'ETH-USD']);\n\nwebsocket.on('message', data =\u003e {\n  /* work with data */\n});\nwebsocket.on('error', err =\u003e {\n  /* handle error */\n});\nwebsocket.on('close', () =\u003e {\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 CoinbasePro.WebsocketClient(\n  ['BTC-USD', 'ETH-USD'],\n  'wss://ws-feed-public.sandbox.pro.coinbase.com',\n  {\n    key: 'suchkey',\n    secret: 'suchsecret',\n    passphrase: 'muchpassphrase',\n  },\n  { channels: ['full', 'level2'] }\n);\n```\n\nOptionally, [change subscriptions at runtime](https://docs.pro.coinbase.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    {\n      name: 'user',\n      product_ids: ['ETH-USD'],\n    },\n  ],\n});\n\nwebsocket.unsubscribe({\n  channels: [\n    {\n      name: 'user',\n      product_ids: ['LTC-USD'],\n    },\n    {\n      name: 'user',\n      product_ids: ['ETH-USD'],\n    },\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 CoinbasePro.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 Coinbase Pro using\n`Orderbook` and `WebsocketClient` as described\n[here](https://docs.pro.coinbase.com/#real-time-order-book).\n\n```js\nconst orderbookSync = new CoinbasePro.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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoinbase%2Fcoinbase-pro-node","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcoinbase%2Fcoinbase-pro-node","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoinbase%2Fcoinbase-pro-node/lists"}