Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Signature for Futures Websocket API #10

Open
sghoul opened this issue Mar 5, 2022 · 2 comments
Open

Add Signature for Futures Websocket API #10

sghoul opened this issue Mar 5, 2022 · 2 comments

Comments

@sghoul
Copy link

sghoul commented Mar 5, 2022

I have tried to make Websocket calls with auth without success so far.

I suggest adding a SIGN for futures Websocket requests.

@ghost
Copy link

ghost commented May 11, 2022

Unfortunately, there are only examples written in python and go on the gate.io page. And again unfortunately some of the go examples are missing.

Anyway, first you need to connect to v4 websocket api.

Then you have to look at the code of which feature you want to use on the web page.

https://www.gate.io/docs/developers/apiv4/ws/en/

Now let's continue with the sample authentication code on the web page.

const crypto = require('crypto');

const WebSocket = require('ws');
const GateApi = require('gate-api');

let wsclient = new WebSocket('wss://api.gateio.ws/ws/v4/');

wsclient["on"]('message', data => {
    const obj = JSON.parse(data);

   // enjoy with data
});

wsclient["on"]('open', () => {
    console.log("Connected to Service");
     subscribe2Orders();
});

function subscribe2Orders() {
    const time = parseInt((new Date().getTime()) / 1000);
    const message = `channel=${"spot.orders"}&event=${"subscribe"}&time=${time}`;

    const hash = crypto.createHmac('sha512', API_SECRET)
        .update(message)
        .digest('hex');

    const request = {
        'id': (time * 1e6),
        'time': time,
        'channel': 'spot.orders',
        'event': 'subscribe',
        'payload': ["BTC_USDT"],
        'auth': { 'method': 'api_key', 'KEY': API_KEY, 'SIGN': hash }
    }
    
    wsclient.send(JSON.stringify(request));
}

Attention!
1 - npm i ws
2 - npm i gate-api
don't forget to install

3 - Please do the necessary warnings and precautions for ApiKey and ApiSecret by following and checking the gate.io documentation link I gave above!

@sghoul
Copy link
Author

sghoul commented May 24, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant