Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi i am working on an autotrading financial WebApp whereas i am using their WebSocket api, below is the minimal javascript code...

Each client have their specific auth token to execute trade on the broker server on their behalf, and the token is passed through the WebSocket request.

But the problem is!

Let's say i have 100 clients, so each client will have their own js code where i will invoke their api token individually. And finally i will host their code on virtual server individually for each client to keep it alive all 24x7 using a browser on it to execute their code.

So is not there any way where i write one code for all and pass all client's tokens in an array?

Note: Worrying about because execution of code for all clients must be at once in parallel instead of one by one synchronously.

So how to batch it in bunch?

Hoping for some ideas from you guys...

What I have tried:

JavaScript
const _ws = new WebSocket('wss://ws.broker.com/websockets/v3?app_id=123');
    function Connect() {
        return new Promise(function (resolve, reject) {
            _ws.onopen = function () {
                _ws.send(JSON.stringify({ "authorize": 'client api token' }));
                resolve(_ws);
            };
        });
    }

    Connect().then(function () {
        _ws.onmessage = function () {
            _ws.send(JSON.stringify({
                "buy": "1",
                "parameters": {
                    "contract_type": "BUY",
                    "amount": 10,
                    "symbol": 'frxEURUSD'
                }
            }));

            _ws.onmessage = function (msg) {
                var _data = JSON.parse(msg.data);

                console.log('Contract purchased');
                console.log(_data);
            };
        };
    });
Posted
Updated 28-Nov-19 23:29pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900