Open kervinucf opened 7 years ago
This has to do with any of the endpoints that require authentication, I have ensured that the key/secret are correct and have already created a number of them to see if allowing permissions at different times would change the output, but nothing so far.
the issue is with the api, I found that I just needed to update the keys (with a fresh 2fa code) and then logout, and after logging out it worked
Same issue as @kervinucf ...
Look at this function it is working fine for me and tested.
function calculateSign(url){ var sign=crypto.createHmac('sha512',constants.bittrexCredentials.SECRET);
sign = sign.update(url,'ascii');
sign = sign.digest('hex');
return sign;
} Full Implementation repo : https://github.com/tarun1475/Nodejs-Bittrex-Client
I am also running into this problem. I think it has to do with the api keys even though I'm inputting them correctly. I tried creating a new key with the new 2fa, logged out, and tried again, yet still same response. Has anyone been able to solve this?
same problem...anyone have any luck?I tried with python and javascript (node - using examples straight from docs) with no luck. Here is my javascript file incase someone spots something i overlooked:
var CryptoJS = require("crypto-js");
const fetch = require('node-fetch');
const url = 'https://api.bittrex.com/v3/orders/closed';
const data = {'marketSymbol':'BTC-LOOM','pageSize': 200,'startDate': '2019-09-25T01:10:27.000','endDate': '2019-09-25T01:29:27.000'};
var content_hash = CryptoJS.SHA512('').toString(CryptoJS.enc.Hex);
var api_timestamp = new Date().getTime();
var pre_sign_string = api_timestamp+url+'GET'+content_hash;
var signature = CryptoJS.HmacSHA512(pre_sign_string, 'yyyyyyyyyyy').toString(CryptoJS.enc.Hex);
const headers = {'Api-Key': 'xxxxxxxxxx', 'Api-Timestamp': api_timestamp, 'Api-Content-Hash': content_hash, 'Api-Signature': signature, 'Content-Type': 'application/json'};
function obj_to_query(obj, base_url) {
var parts = [];
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
parts.push(encodeURIComponent(key) + '=' + encodeURIComponent(obj[key]));
}
}
return base_url+"?" + parts.join('&');
}
async function getOrders(url = '', headers = {}) {
return fetch(url, {
method: 'get',
headers: headers,
})
.then(res => res.json())
.then(json => {
console.log(json)
return json
});
}
var r = getOrders(query_string, headers);
console.log(r);
finally got it working not sure why but it seems to be broken..it always spits back the same data no matter what marketSymbol
I use, and only a few trades come back...this is the output i get for /orders/closed everytime regardless:
[ { id: '62b7764c-2c35-4588-b01b-15fbc2e6fc16',
marketSymbol: 'BTC-USD',
direction: 'SELL',
type: 'LIMIT',
quantity: '0.00733630',
limit: '8315.81600000',
timeInForce: 'GOOD_TIL_CANCELLED',
fillQuantity: '0.00733630',
commission: '0.15251830',
proceeds: '61.00732139',
status: 'CLOSED',
createdAt: '2019-09-25T16:03:53.09Z',
updatedAt: '2019-09-25T16:03:53.09Z',
closedAt: '2019-09-25T16:03:53.09Z' },
{ id: '21ca06f8-8e00-4d71-993c-3a7d53f57f1c',
marketSymbol: 'BTC-USD',
direction: 'BUY',
type: 'LIMIT',
quantity: '0.00733630',
limit: '8334.93200000',
timeInForce: 'GOOD_TIL_CANCELLED',
fillQuantity: '0.00733630',
commission: '0.15286890',
proceeds: '61.14756163',
status: 'CLOSED',
createdAt: '2019-09-25T15:56:55.57Z',
updatedAt: '2019-09-25T15:57:02.92Z',
closedAt: '2019-09-25T15:57:02.92Z' },
{ id: '59f2d104-1213-4634-bbd9-6dc8e7d6b91f',
marketSymbol: 'BTC-USD',
direction: 'SELL',
type: 'LIMIT',
quantity: '0.00744902',
limit: '8250.00000000',
timeInForce: 'GOOD_TIL_CANCELLED',
fillQuantity: '0.00744902',
commission: '0.15363603',
proceeds: '61.45441500',
status: 'CLOSED',
createdAt: '2019-09-24T19:43:20.76Z',
updatedAt: '2019-09-24T19:43:21.09Z',
closedAt: '2019-09-24T19:43:21.09Z' },
{ id: 'e39d4a85-c144-493b-98e1-99c91db5bdad',
marketSymbol: 'BTC-USDT',
direction: 'BUY',
type: 'LIMIT',
quantity: '0.00939489',
limit: '10001.59789805',
timeInForce: 'GOOD_TIL_CANCELLED',
fillQuantity: '0.00939489',
commission: '0.23468751',
proceeds: '93.87500532',
status: 'CLOSED',
createdAt: '2019-09-22T16:37:46.92Z',
updatedAt: '2019-09-22T16:37:46.92Z',
closedAt: '2019-09-22T16:37:46.92Z' },
{ id: '5dcc5a06-1eab-460f-b353-78263e9dac0b',
marketSymbol: 'BTC-USDT',
direction: 'SELL',
type: 'LIMIT',
quantity: '0.00953213',
limit: '9907.07077638',
timeInForce: 'GOOD_TIL_CANCELLED',
fillQuantity: '0.00953213',
commission: '0.23608870',
proceeds: '94.43548654',
status: 'CLOSED',
createdAt: '2019-09-22T03:21:51.15Z',
updatedAt: '2019-09-22T03:29:40.98Z',
closedAt: '2019-09-22T03:29:40.98Z' },
{ id: 'bdc95671-fee0-46fb-bb48-4fdf2cee7cae',
marketSymbol: 'GRS-BTC',
direction: 'SELL',
type: 'LIMIT',
quantity: '22.56987578',
limit: '0.00002226',
timeInForce: 'GOOD_TIL_CANCELLED',
fillQuantity: '22.56987578',
commission: '0.00000125',
proceeds: '0.00050263',
status: 'CLOSED',
createdAt: '2019-09-22T03:15:19.59Z',
updatedAt: '2019-09-22T03:15:19.59Z',
closedAt: '2019-09-22T03:15:19.59Z' },
{ id: '3528c223-d40d-41bc-866c-6c92f0a38195',
marketSymbol: 'GRS-BTC',
direction: 'BUY',
type: 'LIMIT',
quantity: '22.56987578',
limit: '0.00002254',
timeInForce: 'GOOD_TIL_CANCELLED',
fillQuantity: '22.56987578',
commission: '0.00000126',
proceeds: '0.00050871',
status: 'CLOSED',
createdAt: '2019-09-22T02:55:56.84Z',
updatedAt: '2019-09-22T03:07:04.18Z',
closedAt: '2019-09-22T03:07:04.18Z' } ]
Here is my javascript code (because I ended up using javascript instead of python to see if it would work - and at least it got passed auth):
var CryptoJS = require("crypto-js");
const fetch = require('node-fetch');
const url = 'https://api.bittrex.com/v3/orders/closed';
const data = {'marketSymbol':'XRP-BTC','pageSize': 5,'startDate':'2019-09-25T01:10:27.000Z','endDate':'2019-09-25T01:29:27.000Z'};
const method = 'GET'
var apiSecret = 'xxx'
var apiKey = 'yyy'
var contentHash = CryptoJS.SHA512('').toString(CryptoJS.enc.Hex);
var timestamp = new Date().getTime();
const subaccountId = ''
//var pre_sign_string = api_timestamp+url+'GET'+content_hash;
var uri = 'https://api.bittrex.com/v3/orders/closed';
var preSign = [timestamp, uri, method, contentHash, subaccountId].join('');
var signature = CryptoJS.HmacSHA512(preSign, apiSecret).toString(CryptoJS.enc.Hex);
console.log(signature)
//var signature = CryptoJS.HmacSHA512(pre_sign_string, '').toString(CryptoJS.enc.Hex);
const headers = {'Api-Key': apiKey, 'Api-Timestamp': timestamp, 'Api-Content-Hash': contentHash, 'Api-Signature': signature};
function stringToBytes(str) {
var ch, st, re = [];
for (var i = 0; i < str.length; i++ ) {
ch = str.charCodeAt(i); // get char
st = []; // set up "stack"
do {
st.push( ch & 0xFF ); // push byte to stack
ch = ch >> 8; // shift value down by 1 byte
}
while ( ch );
// add stack contents to result
// done because chars have "wrong" endianness
re = re.concat( st.reverse() );
}
// return an array of bytes
return re;
}
function obj_to_query(obj) {
var parts = [];
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
parts.push(encodeURIComponent(key) + '=' + encodeURIComponent(obj[key]));
}
}
return 'https://api.bittrex.com/v3/orders/closed' +"?" + parts.join('&');
}
async function getOrders(url = '', data = {}, headers = {}) {
return fetch(url, {
method: 'GET',
headers: headers,
})
.then(res => res.json())
.then(json => {
console.log(json)
return json
});
}
var query_string = obj_to_query(data)
var r = getOrders(url, data, headers);
console.log(r);
I'm not sure why I seem to be having this issue. But I followed the code and instructions on bittrex and have been receiving this message for the past week: {'result': None, 'message': 'INVALID_SIGNATURE', 'success': False} Any ideas why?