coinbase/coinbase-pro-node
coinbase/coinbase-pro-node hiện có 882 sao trên GitHub, viết chủ yếu bằng JavaScript. DEPRECATED — The official Node.js library for Coinbase Pro
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
Snapshot
Cộng tác viên hàng đầu
Xem cộng tác viên hàng đầu
Coinbase Pro

Note: The gdax package is deprecated and might have to be removed from NPM.
Please migrate to the coinbase-pro package to ensure future compatibility.
The official Node.js library for Coinbase's Pro API.
Features
- Easy functionality to use in programmatic trading
- A customizable, websocket-synced Order Book implementation
- API clients with convenient methods for every API endpoint
- Abstracted interfaces – don't worry about HMAC signing or JSON formatting; the library does it for you
Installation
npm install coinbase-pro
You can learn about the API responses of each endpoint by reading our documentation.
Quick Start
The Coinbase Pro API has both public and private endpoints. If you're only interested in
the public endpoints, you should use a PublicClient.
const CoinbasePro = require('coinbase-pro');
const publicClient = new CoinbasePro.PublicClient();
All methods, unless otherwise specified, can be used with either a promise or callback API.
Using Promises
publicClient
.getProducts()
.then(data => {
// work with data
})
.catch(error => {
// handle the error
});
The promise API can be used as expected in async functions in ES2017+
environments:
async function yourFunction() {
try {
const products = await publicClient.getProducts();
} catch (error) {
/* ... */
}
}
Using Callbacks
Your callback should accept three arguments:
error: contains an error message (string), ornullif no error was encounteredresponse: a generic HTTP response abstraction created by therequestlibrarydata: contains data returned by the Coinbase Pro API, orundefinedif an error was encountered
publicClient.getProducts((error, response, data) => {
if (error) {
// handle the error
} else {
// work with data
}
});
NOTE: if you supply a callback, no promise will be returned. This is to
prevent potential UnhandledPromiseRejectionWarnings, which will cause future
versions of Node to terminate.
const myCallback = (err, response, data) => {
/* ... */
};
const result = publicClient.getProducts(myCallback);
result.then(() => {
/* ... */
}); // TypeError: Cannot read property 'then' of undefined
Optional Parameters
Some methods accept optional parameters, e.g.
publicClient.getProductOrderBook('BTC-USD', { level: 3 }).then(book => {
/* ... */
});
To use optional parameters with callbacks, supply the options as the first parameter(s) and the callback as the last parameter:
publicClient.getProductOrderBook(
'ETH-USD',
{ level: 3 },
(error, response, book) => {
/* ... */
}
);
The Public API Client
const publicClient = new CoinbasePro.PublicClient(endpoint);
productIDoptional - defaults to 'BTC-USD' if not specified.endpointoptional - defaults to 'https://api.pro.coinbase.com' if not specified.
Public API Methods
getProducts
publicClient.getProducts(callback);
getProductOrderBook
// Get the order book at the default level of detail.
publicClient.getProductOrderBook('BTC-USD', callback);
// Get the order book at a specific level of detail.
publicClient.getProductOrderBook('LTC-USD', { level: 3 }, callback);
getProductTicker
publicClient.getProductTicker('ETH-USD', callback);
getProductTrades
publicClient.getProductTrades('BTC-USD', callback);
// To make paginated requests, include page parameters
publicClient.getProductTrades('BTC-USD', { after: 1000 }, callback);
getProductTradeStream
Wraps around getProductTrades, fetches all trades with IDs >= tradesFrom and
<= tradesTo. Handles pagination and rate limits.
const trades = publicClient.getProductTradeStream('BTC-USD', 8408000, 8409000);
// tradesTo can also be a function
const trades = publicClient.getProductTradeStream(
'BTC-USD',
8408000,
trade => Date.parse(trade.time) >= 1463068e6
);
getProductHistoricRates
publicClient.getProductHistoricRates('BTC-USD', callback);
// To include extra parameters:
publicClient.getProductHistoricRates(
'BTC-USD',
{ granularity: 3600 },
callback
);
getProduct24HrStats
publicClient.getProduct24HrStats('BTC-USD', callback);
getCurrencies
publicClient.getCurrencies(callback);
getTime
publicClient.getTime(callback);
The Authenticated API Client
The private exchange API endpoints require you
to authenticate with a Coinbase Pro API key. You can create a new API key in your
exchange account's settings. You can also specify
the API URI (defaults to https://api.pro.coinbase.com).
const key = 'your_api_key';
const secret = 'your_b64_secret';
const passphrase = 'your_passphrase';
const apiURI = 'https://api.pro.coinbase.com';
const sandboxURI = 'https://api-public.sandbox.pro.coinbase.com';
const authedClient = new CoinbasePro.AuthenticatedClient(
key,
secret,
passphrase,
apiURI
);
Like PublicClient, all API methods can be used with either callbacks or will
return promises.
AuthenticatedClient inherits all of the API methods from
PublicClient, so if you're hitting both public and private API endpoints you
only need to create a single client.
Private API Methods
getCoinbaseAccounts
authedClient.getCoinbaseAccounts(callback);
getPaymentMethods
authedClient.getPaymentMethods(callback);
getAccounts
authedClient.getAccounts(callback);
getAccount
const accountID = '7d0f7d8e-dd34-4d9c-a846-06f431c381ba';
authedClient.getAccount(accountID, callback);
getAccountHistory
const accountID = '7d0f7d8e-dd34-4d9c-a846-06f431c381ba';
authedClient.getAccountHistory(accountID, callback);
// For pagination, you can include extra page arguments
authedClient.getAccountHistory(accountID, { before: 3000 }, callback);
getAccountTransfers
const accountID = '7d0f7d8e-dd34-4d9c-a846-06f431c381ba';
authedClient.getAccountTransfers(accountID, callback);
// For pagination, you can include extra page arguments
authedClient.getAccountTransfers(accountID, { before: 3000 }, callback);
getAccountHolds
const accountID = '7d0f7d8e-dd34-4d9c-a846-06f431c381ba';
authedClient.getAccountHolds(accountID, callback);
// For pagination, you can include extra page arguments
authedClient.getAccountHolds(accountID, { before: 3000 }, callback);
buy,sell
// Buy 1 BTC @ 100 USD
const buyParams = {
price: '100.00', // USD
size: '1', // BTC
product_id: 'BTC-USD',
};
authedClient.buy(buyParams, callback);
// Sell 1 BTC @ 110 USD
const sellParams = {
price: '110.00', // USD
size: '1', // BTC
product_id: 'BTC-USD',
};
authedClient.sell(sellParams, callback);
placeOrder
// Buy 1 LTC @ 75 USD
const params = {
side: 'buy',
price: '75.00', // USD
size: '1', // LTC
product_id: 'LTC-USD',
};
authedClient.placeOrder(params, callback);
cancelOrder
const orderID = 'd50ec984-77a8-460a-b958-66f114b0de9b';
authedClient.cancelOrder(orderID, callback);
cancelOrders
// Cancels "open" orders
authedClient.cancelOrders(callback);
cancelAllOrders
// `cancelOrders` may require you to make the request multiple times until
// all of the "open" orders are deleted.
// `cancelAllOrders` will handle making these requests for you asynchronously.
// Also, you can add a `product_id` param to only delete orders of that product.
// The data will be an array of the order IDs of all orders which were cancelled
authedClient.cancelAllOrders({ product_id: 'BTC-USD' }, callback);
getOrders
authedClient.getOrders(callback);
// For pagination, you can include extra page arguments
// Get all orders of 'open' status
authedClient.getOrders({ after: 3000, status: 'open' }, callback);
getOrder
const orderID = 'd50ec984-77a8-460a-b958-66f114b0de9b';
authedClient.getOrder(orderID, callback);
getFills
const params = {
product_id: 'LTC-USD',
};
authedClient.getFills(params, callback);
// For pagination, you can include extra page arguments
authedClient.getFills({ before: 3000 }, callback);
getFundings
authedClient.getFundings({}, callback);
repay
const params = {
amount: '2000.00',
currency: 'USD',
};
authedClient.repay(params, callback);
marginTransfer
const params =
'margin_profile_id': '45fa9e3b-00ba-4631-b907-8a98cbdf21be',
'type': 'deposit',
'currency': 'USD',
'amount': 2
};
authedClient.marginTransfer(params, callback);
closePosition
const params = {
repay_only: false,
};
authedClient.closePosition(params, callback);
convert
const params = {
from: 'USD',
to: 'USDC',
amount: '100',
};
authedClient.convert(params, callback);
deposit,withdraw
// Deposit to your Exchange USD account from your Coinbase USD account.
const depositParamsUSD = {
amount: '100.00',
currency: 'USD',
coinbase_account_id: '60680c98bfe96c2601f27e9c', // USD Coinbase Account ID
};
authedClient.deposit(depositParamsUSD, callback);
// Withdraw from your Exchange USD account to your Coinbase USD account.
const withdrawParamsUSD = {
amount: '100.00',
currency: 'USD',
coinbase_account_id: '60680c98bfe96c2601f27e9c', // USD Coinbase Account ID
};
authedClient.withdraw(withdrawParamsUSD, callback);
// Deposit to your Exchange BTC account from your Coinbase BTC account.
const depositParamsBTC = {
amount: '2.0',
currency: 'BTC',
coinbase_account_id: '536a541fa9393bb3c7000023', // BTC Coinbase Account ID
};
authedClient.deposit(depositParamsBTC, callback);
// Withdraw from your Exchange BTC account to your Coinbase BTC account.
const withdrawParamsBTC = {
amount: '2.0',
currency: 'BTC',
coinbase_account_id: '536a541fa9393bb3c7000023', // BTC Coinbase Account ID
};
authedClient.withdraw(withdrawParamsBTC, callback);
// Fetch a deposit address from your Exchange BTC account.
const depositAddressParams = {
currency: 'BTC',
};
authedClient.depositCrypto(depositAddressParams, callback);
// Withdraw from your Exchange BTC account to another BTC address.
const withdrawAddressParams = {
amount: 10.0,
currency: 'BTC',
crypto_address: '15USXR6S4DhSWVHUxXRCuTkD1SA6qAdy',
};
authedClient.withdrawCrypto(withdrawAddressParams, callback);
depositPayment
// Schedule Deposit to your Exchange USD account from a configured payment method.
const depositPaymentParamsUSD = {
amount: '100.00',
currency: 'USD',
payment_method_id: 'bc6d7162-d984-5ffa-963c-a493b1c1370b', // ach_bank_account
};
authedClient.depositPayment(depositPaymentParamsUSD, callback);
withdrawPayment
// Withdraw from your Exchange USD account to a configured payment method.
const withdrawPaymentParamsUSD = {
amount: '100.00',
currency: 'USD',
payment_method_id: 'bc6d7162-d984-5ffa-963c-a493b1c1370b', // ach_bank_account
};
authedClient.withdrawPayment(withdrawPaymentParamsUSD, callback);
getTrailingVolume
// Get your 30 day trailing volumes
authedClient.getTrailingVolume(callback);
Websocket Client
The WebsocketClient allows you to connect and listen to the exchange
websocket messages.
const websocket = new CoinbasePro.WebsocketClient(['BTC-USD', 'ETH-USD']);
websocket.on('message', data => {
/* work with data */
});
websocket.on('error', err => {
/* handle error */
});
websocket.on('close', () => {
/* ... */
});
The client will automatically subscribe to the heartbeat channel. By
default, the full channel will be subscribed to unless other channels are
requested.
const websocket = new CoinbasePro.WebsocketClient(
['BTC-USD', 'ETH-USD'],
'wss://ws-feed-public.sandbox.pro.coinbase.com',
{
key: 'suchkey',
secret: 'suchsecret',
passphrase: 'muchpassphrase',
},
{ channels: ['full', 'level2'] }
);
Optionally, change subscriptions at runtime:
websocket.unsubscribe({ channels: ['full'] });
websocket.subscribe({ product_ids: ['LTC-USD'], channels: ['ticker', 'user'] });
websocket.subscribe({
channels: [
{
name: 'user',
product_ids: ['ETH-USD'],
},
],
});
websocket.unsubscribe({
channels: [
{
name: 'user',
product_ids: ['LTC-USD'],
},
{
name: 'user',
product_ids: ['ETH-USD'],
},
],
});
The following events can be emitted from the WebsocketClient:
openmessagecloseerror
Orderbook
Orderbook is a data structure that can be used to store a local copy of the
orderbook.
const orderbook = new CoinbasePro.Orderbook();
The orderbook has the following methods:
state(book)get(orderId)add(order)remove(orderId)match(match)change(change)
Orderbook Sync
OrderbookSync creates a local mirror of the orderbook on Coinbase Pro using
Orderbook and WebsocketClient as described
here.
const orderbookSync = new CoinbasePro.OrderbookSync(['BTC-USD', 'ETH-USD']);
console.log(orderbookSync.books['ETH-USD'].state());
Testing
npm test
# test for known vulnerabilities in packages
npm install -g nsp
nsp check --output summary
Repo liên quan
Master programming by recreating your favorite technologies from scratch.
A curated meta-list of curated lists organized by technology domain. The repository acts as a directory pointing to hundreds of specialized awesome lists covering programming languages, platforms, frameworks, and tooling. All content is community-contributed under the CC0 public domain dedication.
Public APIs is a community-curated GitHub repository listing free, publicly accessible APIs across a wide range of categories, with auth type, HTTPS, and CORS noted for each entry. It's a browsable reference, not a library to install.
freeCodeCamp is a free, self-paced curriculum for learning to code, published as open source at freeCodeCamp/freeCodeCamp. It's a 501(c)(3) nonprofit funded by donor support, structured around six certifications in its Full-Stack Developer Curriculum, each gated by required projects instead of open-book quizzes. The repository also carries beta language certifications for developers, interview-prep resources, and the code that runs the live freecodecamp.org platform.
Trả lời nhanh
coinbase/coinbase-pro-node có phải mã nguồn mở không?
Có — coinbase/coinbase-pro-node phát hành theo license Apache-2.0, nghĩa là mã nguồn mở để đọc, fork và (tùy license) tái sử dụng. Mã: github.com/coinbase/coinbase-pro-node.
coinbase/coinbase-pro-node có website riêng không?
TopGit chưa ghi nhận URL trang chủ cho coinbase/coinbase-pro-node. Phần README ở tab phía trên thường có link demo, hoặc xem mô tả GitHub của repo.
coinbase/coinbase-pro-node dùng license gì?
coinbase/coinbase-pro-node phát hành theo license Apache-2.0. Nên mở file LICENSE trên GitHub để xác nhận — license metadata đôi khi lệch với thực tế dự án.
coinbase/coinbase-pro-node là gì?
coinbase/coinbase-pro-node (coinbase/coinbase-pro-node) là dự án JavaScript trên GitHub. Theo mô tả gốc: DEPRECATED — The official Node.js library for Coinbase Pro
Đọc thêm về coinbase/coinbase-pro-node ở đâu?
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/coinbase/coinbase-pro-node là nguồn chính thức.
Đọc đầy đủ README ở tab phía trên.
coinbase-pro-node có đáng để bạn bỏ thời gian?
ChatGPT, Claude và Perplexity đều đọc được trang này. Hỏi thử xem họ nghĩ gì về coinbase-pro-node.