Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

209
Views
La API de Coinbase devuelve "producto no encontrado" para una identificación de producto válida

Estoy usando la API de sandbox en este momento y puedo consultar los productos, incluso de forma individual, pero si intento hacer un pedido de compra, la respuesta que obtengo es { message: 'Product not found' } .

Aquí está mi código:

 async function cb_request( method, path, headers = {}, body = ''){ var apiKey = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx', apiSecret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx', apiPass = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx'; //get unix time in seconds var timestamp = Math.floor(Date.now() / 1000); // set the request message var message = timestamp + method + path + body; //create a hexedecimal encoded SHA256 signature of the message var key = Buffer.from(apiSecret, 'base64'); var signature = crypto.createHmac('sha256', key).update(message).digest('base64'); //create the request options object var baseUrl = 'https://api-public.sandbox.pro.coinbase.com'; headers = Object.assign({},headers,{ 'CB-ACCESS-SIGN': signature, 'CB-ACCESS-TIMESTAMP': timestamp, 'CB-ACCESS-KEY': apiKey, 'CB-ACCESS-PASSPHRASE': apiPass, 'USER-AGENT': 'request' }); // Logging the headers here to ensure they're sent properly console.log(headers); var options = { baseUrl: baseUrl, url: path, method: method, headers: headers }; return new Promise((resolve,reject)=>{ request( options, function(err, response, body){ if (err) reject(err); resolve(JSON.parse(response.body)); }); }); } async function main() { // This queries a product by id (successfully) try { console.log( await cb_request('GET','/products/BTC-USD') ); } catch(e) { console.log(e); } // Trying to place a buy order here (using the same id as above) returns { message: 'Product not found' } var buyParams = { 'type': 'market', 'side': 'buy', 'funds': '100', 'product_id': 'BTC-USD' }; try { var buy = await cb_request('POST','/orders',buyParams); console.log(buy); } catch(e) { console.log(e); } } main();

Intenté enviar los parámetros en el cuerpo, que responde con una invalid signature , incluso cuando está en cadena. También intenté usar los parámetros que se muestran en los documentos de la API , pero eso también responde con product not found .

¿Algunas ideas? AIT

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Como mencionó j-petty, debe enviar datos como cuerpo de solicitud para la operación POST como se describe en la documentación de la API, por lo que obtiene "producto no encontrado".

Aquí está el código de trabajo basado en lo que compartió:

 var crypto = require('crypto'); var request = require('request'); async function cb_request( method, path, headers = {}, body = ''){ var apiKey = 'xxxxxx', apiSecret = 'xxxxxxx', apiPass = 'xxxxxxx'; //get unix time in seconds var timestamp = Math.floor(Date.now() / 1000); // set the request message var message = timestamp + method + path + body; console.log('######## message=' + message); //create a hexedecimal encoded SHA256 signature of the message var key = Buffer.from(apiSecret, 'base64'); var signature = crypto.createHmac('sha256', key).update(message).digest('base64'); //create the request options object var baseUrl = 'https://api-public.sandbox.pro.coinbase.com'; headers = Object.assign({},headers,{ 'content-type': 'application/json; charset=UTF-8', 'CB-ACCESS-SIGN': signature, 'CB-ACCESS-TIMESTAMP': timestamp, 'CB-ACCESS-KEY': apiKey, 'CB-ACCESS-PASSPHRASE': apiPass, 'USER-AGENT': 'request' }); // Logging the headers here to ensure they're sent properly console.log(headers); var options = { 'baseUrl': baseUrl, 'url': path, 'method': method, 'headers': headers, 'body': body }; return new Promise((resolve,reject)=>{ request( options, function(err, response, body){ console.log(response.statusCode + " " + response.statusMessage); if (err) reject(err); resolve(JSON.parse(response.body)); }); }); } async function main() { // This queries a product by id (successfully) try { console.log('try to call product------->'); console.log( await cb_request('GET','/products/BTC-USD') ); console.log('product------------------->done'); } catch(e) { console.log(e); } var buyParams = JSON.stringify({ 'type': 'market', 'side': 'buy', 'funds': '10', 'product_id': 'BTC-USD' }); try { console.log('try to call orders------->'); var buy = await cb_request('POST','/orders', {}, buyParams); console.log(buy); console.log('orders----------------------->done'); } catch(e) { console.log(e); } } main();

ingrese la descripción de la imagen aquí

over 4 years ago · Santiago Trujillo Report

0

Vale la pena mencionar que la API de sandbox tiene resultados diferentes a la API de producción. Considere los siguientes CURL.

API de espacio aislado:

 ❯ curl --request GET \ --url https://api-public.sandbox.exchange.coinbase.com/products/ETH-USD \ --header 'Accept: application/json' {"message":"NotFound"}%

API de producción:

 ❯ curl --request GET \ --url https://api.exchange.coinbase.com/products/ETH-USD \ --header 'Accept: application/json' {"id":"ETH-USD","base_currency":"ETH","quote_currency":"USD","base_min_size":"0.00029","base_max_size":"2800","quote_increment":"0.01","base_increment":"0.00000001","display_name":"ETH/USD","min_market_funds":"1","max_market_funds":"4000000","margin_enabled":false,"fx_stablecoin":false,"max_slippage_percentage":"0.02000000","post_only":false,"limit_only":false,"cancel_only":false,"trading_disabled":false,"status":"online","status_message":"","auction_mode":false}%

Notarás que las rutas son idénticas pero obtienes resultados diferentes, así que tenlo en cuenta. Para fines de prueba, se puede utilizar BTC-USD.

over 4 years ago · Santiago Trujillo Report

0

Debe enviar una solicitud POST al punto final /orders e incluir el cuerpo en la carga útil de la solicitud.

Hay algunos ejemplos de respuestas en esta pregunta .

 var options = { baseUrl: baseUrl, url: path, method: method, headers: headers json: true, body: body } request.post(options, function(err, response, body){ if (err) reject(err); resolve(JSON.parse(response.body)); });
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!