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:
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);
};
};
});