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.
npm install coinbase-pro
You can learn about the API responses of each endpoint by reading ourdocumentation.
The Coinbase Pro API has both public and private endpoints. If you're only interested inthe 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 orcallback API.
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) {
/* ... */
}
}
Your callback should accept three arguments:
error
: contains an error message (string
), or null
if no error wasencounteredresponse
: a generic HTTP response abstraction created by the request
librarydata
: contains data returned by the Coinbase Pro API, or undefined
if an error wasencounteredpublicClient.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 toprevent potential UnhandledPromiseRejectionWarning
s, which will cause futureversions of Node to terminate.
const myCallback = (err, response, data) => {
/* ... */
};
const result = publicClient.getProducts(myCallback);
result.then(() => {
/* ... */
}); // TypeError: Cannot read property 'then' of undefined
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 firstparameter(s) and the callback as the last parameter:
publicClient.getProductOrderBook(
'ETH-USD',
{ level: 3 },
(error, response, book) => {
/* ... */
}
);
const publicClient = new CoinbasePro.PublicClient(endpoint);
productID
optional - defaults to 'BTC-USD' if not specified.endpoint
optional - defaults to 'https://api.pro.coinbase.com' if not specified.publicClient.getProducts(callback);
// 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);
publicClient.getProductTicker('ETH-USD', callback);
publicClient.getProductTrades('BTC-USD', callback);
// To make paginated requests, include page parameters
publicClient.getProductTrades('BTC-USD', { after: 1000 }, callback);
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
);
publicClient.getProductHistoricRates('BTC-USD', callback);
// To include extra parameters:
publicClient.getProductHistoricRates(
'BTC-USD',
{ granularity: 3600 },
callback
);
publicClient.getProduct24HrStats('BTC-USD', callback);
publicClient.getCurrencies(callback);
publicClient.getTime(callback);
The private exchange API endpoints require youto authenticate with a Coinbase Pro API key. You can create a new API key in yourexchange account's settings. You can also specifythe 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 willreturn promises.
AuthenticatedClient
inherits all of the API methods fromPublicClient
, so if you're hitting both public and private API endpoints youonly need to create a single client.
authedClient.getCoinbaseAccounts(callback);
authedClient.getPaymentMethods(callback);
authedClient.getAccounts(callback);
const accountID = '7d0f7d8e-dd34-4d9c-a846-06f431c381ba';
authedClient.getAccount(accountID, callback);
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);
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);
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 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);
// Buy 1 LTC @ 75 USD
const params = {
side: 'buy',
price: '75.00', // USD
size: '1', // LTC
product_id: 'LTC-USD',
};
authedClient.placeOrder(params, callback);
const orderID = 'd50ec984-77a8-460a-b958-66f114b0de9b';
authedClient.cancelOrder(orderID, callback);
// Cancels "open" orders
authedClient.cancelOrders(callback);
// `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);
authedClient.getOrders(callback);
// For pagination, you can include extra page arguments
// Get all orders of 'open' status
authedClient.getOrders({ after: 3000, status: 'open' }, callback);
const orderID = 'd50ec984-77a8-460a-b958-66f114b0de9b';
authedClient.getOrder(orderID, callback);
const params = {
product_id: 'LTC-USD',
};
authedClient.getFills(params, callback);
// For pagination, you can include extra page arguments
authedClient.getFills({ before: 3000 }, callback);
authedClient.getFundings({}, callback);
const params = {
amount: '2000.00',
currency: 'USD',
};
authedClient.repay(params, callback);
const params =
'margin_profile_id': '45fa9e3b-00ba-4631-b907-8a98cbdf21be',
'type': 'deposit',
'currency': 'USD',
'amount': 2
};
authedClient.marginTransfer(params, callback);
const params = {
repay_only: false,
};
authedClient.closePosition(params, callback);
const params = {
from: 'USD',
to: 'USDC',
amount: '100',
};
authedClient.convert(params, callback);
// 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);
// 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);
// 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);
// Get your 30 day trailing volumes
authedClient.getTrailingVolume(callback);
The WebsocketClient
allows you to connect and listen to the exchangewebsocket 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. Bydefault, the full
channel will be subscribed to unless other channels arerequested.
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
:
open
message
close
error
Orderbook
is a data structure that can be used to store a local copy of theorderbook.
const orderbook = new CoinbasePro.Orderbook();
The orderbook has the following methods:
state(book)
get(orderId)
add(order)
remove(orderId)
match(match)
change(change)
OrderbookSync
creates a local mirror of the orderbook on Coinbase Pro usingOrderbook
and WebsocketClient
as describedhere.
const orderbookSync = new CoinbasePro.OrderbookSync(['BTC-USD', 'ETH-USD']);
console.log(orderbookSync.books['ETH-USD'].state());
npm test
# test for known vulnerabilities in packages
npm install -g nsp
nsp check --output summary
coinbase交易是块中的第一个交易。它是一种可以由矿工创建的独特类型的比特币交易。矿工使用它来收取他们工作的区块奖励,矿工收取的任何其他交易费也在此交易中发送。 说明 在比特币网络上执行的每个交易组合在一起以形成块。当一个块立即形成时,它将包含在区块链中。这些块对于在比特币网络上进行的所有交易是不可变的和防篡改的。每个块必须包含一个或多个交易,块中的第一个交易称为交易。 矿工总是负责创建一个区
本文向大家介绍什么是Coinbase交易?相关面试题,主要包含被问及什么是Coinbase交易?时的应答技巧和注意事项,需要的朋友参考一下 回答:Coinbase交易是矿工创建的独特类型的比特币交易。这是新区块中的第一笔交易。矿工使用它来收集工作的集体奖励。矿工收取的任何交易费也将在此交易中发送。
Recovery Pro 是一种独特的恢复追踪解决方案,可让您知道您的心肺系统是否已恢复并准备好进行心肺训练。此外,它还根据您的短期及长期训练和恢复之间的平衡情况提供恢复反馈和训练建议。 结合使用 Recovery Pro 和 Training Load Pro,您可全面了解训练课如何对身体不同系统造成疲劳。然后,Recovery Pro 会告诉您身体对于这种疲劳的反应,以及它如何影响您每天进行心
主页: Markdown Pro 平台: OSX 费用: $9.99 介绍 Markdown Pro 提供了 iCloud 支持、文件导出等功能。 截图
phpMyBackupPro是一个易于使用,基于web的MySQL备份系统。它的主要特性如下: 1.可以选择备份一个或几个数据库,并可以选择是只备份表格结构还是包含数据,…。 2.支持三种压缩类型(不压缩,gzip和zip)。 3.按计划自动备份。 4.提供一个备份管理界面(查看,恢复,下载,删除)。 5.可直接备份到FTP服务器上或通过email发送。 6.支持多种语言。
DashO Pro 是Java代码保护的理想选择。其代码保护能力强大易用,方便灵活(商业软件,非开源)。 该Java混淆器是: 独立软件开发商理想选择——保护其重要知识产权; 业界理想选择——防止针对Java代码的内部和外部黑客威胁; Sun的选择——代码防护和混淆。对于企业级应用,作为其Java开发包的一部分,Sun微系统使用DashO Pro来混淆其加密库。 您的选择——超级的代码保护和混淆能