bitfinexcom / bitfinex-api-node

BITFINEX NodeJS trading API - Bitcoin, Litecoin, and Ether exchange
https://www.bitfinex.com/
MIT License
462 stars 213 forks source link

API Key invalid for submitting orders, but works for viewing wallet #531

Closed BronacusAmmon closed 4 years ago

BronacusAmmon commented 4 years ago

Issue type

Brief description

Im trying to utilize the Bitfinex Authenticated API to create orders, when I use the base code to get wallet balance it works perfects but when I change the options to fit whats described in the docs for submitting an order it returns [ 'error', 10100, 'apikey: invalid' ]

Steps to reproduce

Including my code below

const CryptoJS = require('crypto-js') // Standard JavaScript cryptography library const request = require('request') // "Request" HTTP req library var config = require('./config') const apiPath = 'v2/auth/w/order/submit' const nonce = (Date.now() 1000).toString() // Standard nonce generator. Timestamp 1000 const body = {} // Field you may change depending on endpoint let signature = /api/${apiPath}${nonce}${JSON.stringify(body)} // Consists of the complete url, nonce, and request body

const sig = CryptoJS.HmacSHA384(signature, config.BitfinexSecretKey).toString() // The authentication signature is hashed using the private key

const options = { url: https://api.bitfinex.com/${apiPath}, headers: { 'content-type': 'application/json', 'bfx-nonce': nonce, 'bfx-apikey': config.BitfinexApiKey, 'bfx-signature': sig }, body: { type: 'LIMIT', symbol: 'tETHUSD', price: 5, amount: 5000 }, json: true }

request.post(options, (error, response, body) => { console.log(body); // Logs the response body })

Additional Notes:

I've double checked it has permission to write orders and the body prices and amounts are meant to be ridiculous so in the event it actually gets submitted I don't make a terrible trade accidentally

JacobPlaster commented 4 years ago

Hi @MallyxTheZealous, thanks for opening an issue. This repo is for the Bitfinex nodejs library and not the core API.

Could you please try to submit the order using the nodjs library? Here is an example on how to achieve that: https://github.com/bitfinexcom/bitfinex-api-node/blob/master/examples/rest2/submit_order.js