User Channel Not Authenticating
Hi Everyone,
I'm attempting get my account data (orders, transfers, etc) via the User Channel + Websocket.
I'm able to subscribe to the User channel but it just shows the Heartbeat channel data. I place multiple buy and sell orders while it's running and it only populates the Heartbeat data. Is this correct in thinking this?
Or am I wrong in thinking that the User Channel can provide me my account data via the websocket?
Thank you for your help! MM
@MattMav It would be easier to say what's wrong if you provided some code. Something like this should work:
const { WebsocketClient, AuthenticatedClient } = require('coinbase-pro');
const key = 'yourKey';
const secret = 'yourSecret';
const passphrase = 'yourPassphrase';
const ws_url = 'wss://ws-feed.pro.coinbase.com';
const rest_url = 'https://api.pro.coinbase.com';
const auth = { key, secret, passphrase };
const product_id = 'BTC-USD';
const price = 1;
const size = 0.001;
const channels = ['user'];
const client = new AuthenticatedClient(key, secret, passphrase, rest_url);
const websocket = new WebsocketClient([product_id], ws_url, auth, { channels });
websocket.on('message', message => {
console.log(message);
});
websocket.once('open', () => {
client.buy({ price, size, product_id }, (error, response, data) => {
if (error) {
console.error(error);
} else {
console.log(data);
}
});
});
Sergey,
Thank you so much for your response! And the code. I see from your code what my error was. I didn’t have AuthenticatedClient as a const.
I replaced all of my code with the code you provided and put in my key, secret and passphrase and I received the following error response:
events.js:173
throw err; // Unhandled 'error' event
^
Error [ERR_UNHANDLED_ERROR]: Unhandled error. ([object Object])
at WebsocketClient.emit (events.js:171:17)
at WebsocketClient.onError (C:\Users\MM\Desktop\coinbase_client\node_modules\coinbase-pro\lib\clients\websocket.js:109:10)
at WebsocketClient.onMessage (C:\Users\MM\Desktop\coinbase_client\node_modules\coinbase-pro\lib\clients\websocket.js:92:12)
at WebSocket.emit (events.js:182:13)
at Receiver._receiver.onmessage (C:\Users\MM\Desktop\coinbase_client\node_modules\ws\lib\websocket.js:137:47)
at Receiver.dataMessage (C:\Users\MM\Desktop\coinbase_client\node_modules\ws\lib\receiver.js:409:14)
at Receiver.getData (C:\Users\MM\Desktop\coinbase_client\node_modules\ws\lib\receiver.js:347:12)
at Receiver.startLoop (C:\Users\MM\Desktop\coinbase_client\node_modules\ws\lib\receiver.js:143:16)
at Receiver.add (C:\Users\MM\Desktop\coinbase_client\node_modules\ws\lib\receiver.js:117:10)
at TLSSocket.emit (events.js:182:13)
I spent a couple of hours Googling and troubleshooting. I restarted, shutdown my PC and updated and reinstalled NPM. Those were the three suggestions that I came across.
Do you have any other suggestions for a fix?
Thank you again!
From: Sergey Bakulin [email protected] Sent: Monday, July 22, 2019 1:05 PM To: coinbase/coinbase-pro-node [email protected] Cc: Subscribed [email protected] Subject: Re: [coinbase/coinbase-pro-node] User Channel Not Authenticating (#374)
@MattMav https://github.com/MattMav It would be easier to say what's wrong if you provided some code. Something like this should work:
const { WebsocketClient, AuthenticatedClient } = require('coinbase-pro'); const key = 'yourKey'; const secret = 'yourSecret'; const passphrase = 'yourPassphrase'; const ws_url = 'wss://ws-feed.pro.coinbase.com'; const rest_url = 'https://api.pro.coinbase.com'; const auth = { key, secret, passphrase }; const product_id = 'BTC-USD'; const price = 1; const size = 0.001; const channels = ['user']; const client = new AuthenticatedClient(key, secret, passphrase, rest_url); const websocket = new WebsocketClient([product_id], ws_url, auth, { channels }); websocket.on('message', message => { console.log(message); }); websocket.once('open', () => { client.buy({ price, size, product_id }, (error, response, data) => { if (error) { console.error(error); } else { console.log(data); } }); });
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/coinbase/coinbase-pro-node/issues/374?email_source=notifications&email_token=ALPOVQQVM7SJCO2QRA2E2EDQAXSCVA5CNFSM4IFBQV2KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD2QQNEI#issuecomment-513869457 , or mute the thread https://github.com/notifications/unsubscribe-auth/ALPOVQWOAS4U2A5LTNMRLGLQAXSCVANCNFSM4IFBQV2A .
@MattMav Could you also add a listener to the error event:
websocket.on('error', error => {
console.error('Error: ', error);
});
and provide more information about the error you receive.
Okay, yes. I added that and it came back with an error saying Invalid API Key. I confirmed that the key was correct but I read the error message more intently and I realized that I should've been using the Sandbox URL.. Rookie mistake...
Thank you again Vansergen!! I spent several hours trying to figure that out prior to my post, You're a great help!