如何使用 NodeJS coinbase pro api 从正文密钥中获取价格
How do I get the price from the body key using NodeJS coinbase pro api
如何使用 NodeJS coinbase pro api 从正文密钥中获取价格?
我正在尝试使用 api 命令
从 body 键获取价格
getProductTicker
以下是我到目前为止的内容,但我不知道如何解析
主体键的价格。
const CoinbasePro = require('coinbase-pro');
const publicClient = new CoinbasePro.PublicClient();
publicClient.getProductTicker('ETH-USD', function(err, obj) {
console.log('ETH-USD it worked');
console.log('Start of Entries\n');
console.log(Object.entries(obj));
console.log('End of Entries \n');
console.log('Start of keys\n');
console.log(Object.keys(obj));
console.log('End of keys \n');
});
下面是输出。我正在尝试从正文密钥中获取价格。
_ended: true,
_callbackCalled: true
}
],
[ 'toJSON', [Function: responseToJSON] ],
[ 'caseless', Caseless { dict: [Object] } ],
[
'body',
'{"trade_id":53067029,"price":"125.24","size":"0.07555643","time":"2019-12-
27T17:04:37.429725Z","bid":"125.23","ask":"125.24","volume":"55843.38198278"}'
]
]
条目结束
按键开始
[
'_readableState', 'readable',
'_events', '_eventsCount',
'_maxListeners', 'socket',
'connection', 'httpVersionMajor',
'httpVersionMinor', 'httpVersion',
'complete', 'headers',
'rawHeaders', 'trailers',
'rawTrailers', 'aborted',
'upgrade', 'url',
'method', 'statusCode',
'statusMessage', 'client',
'_consuming', '_dumped',
'req', 'request',
'toJSON', 'caseless',
'body'
]
按键结束
您需要解析以字符串形式出现的正文。我不确定是否也可以使用 toJson
方法,但值得一试。试试这个。
const CoinbasePro = require("coinbase-pro");
const publicClient = new CoinbasePro.PublicClient();
publicClient.getProductTicker("ETH-USD", function(err, obj) {
const parsedBody = JSON.parse(obj.body);
const price = parsedBody.price;
});
如何使用 NodeJS coinbase pro api 从正文密钥中获取价格? 我正在尝试使用 api 命令
从 body 键获取价格getProductTicker
以下是我到目前为止的内容,但我不知道如何解析 主体键的价格。
const CoinbasePro = require('coinbase-pro');
const publicClient = new CoinbasePro.PublicClient();
publicClient.getProductTicker('ETH-USD', function(err, obj) {
console.log('ETH-USD it worked');
console.log('Start of Entries\n');
console.log(Object.entries(obj));
console.log('End of Entries \n');
console.log('Start of keys\n');
console.log(Object.keys(obj));
console.log('End of keys \n');
});
下面是输出。我正在尝试从正文密钥中获取价格。
_ended: true,
_callbackCalled: true
}
],
[ 'toJSON', [Function: responseToJSON] ],
[ 'caseless', Caseless { dict: [Object] } ],
[
'body',
'{"trade_id":53067029,"price":"125.24","size":"0.07555643","time":"2019-12-
27T17:04:37.429725Z","bid":"125.23","ask":"125.24","volume":"55843.38198278"}'
]
]
条目结束
按键开始
[
'_readableState', 'readable',
'_events', '_eventsCount',
'_maxListeners', 'socket',
'connection', 'httpVersionMajor',
'httpVersionMinor', 'httpVersion',
'complete', 'headers',
'rawHeaders', 'trailers',
'rawTrailers', 'aborted',
'upgrade', 'url',
'method', 'statusCode',
'statusMessage', 'client',
'_consuming', '_dumped',
'req', 'request',
'toJSON', 'caseless',
'body'
]
按键结束
您需要解析以字符串形式出现的正文。我不确定是否也可以使用 toJson
方法,但值得一试。试试这个。
const CoinbasePro = require("coinbase-pro");
const publicClient = new CoinbasePro.PublicClient();
publicClient.getProductTicker("ETH-USD", function(err, obj) {
const parsedBody = JSON.parse(obj.body);
const price = parsedBody.price;
});