node-ib icon indicating copy to clipboard operation
node-ib copied to clipboard

How to handle multiple clients?

Open closelate opened this issue 8 years ago • 6 comments

Hi, How does server handle multiple clients? Do I have to install multiple IB gateways in server? If I have thousands of clients, each client have their own account. How do I handel this case with node-ib? Is node-ib running without IB gateway? Thanks

closelate avatar May 23 '16 15:05 closelate

As far as I know, this module is only connecting to IB TWS or IB Gateway which is authorized against IB servers .. so when you want multiuser support you will need multiple IB TWS or IB Gateway running authorized against IB and than connect to them with this node-ib module.. This will be bad solution for your use case..

junajan avatar Jun 04 '16 18:06 junajan

Configure your client IB gateway listen on different port for each client, on a Linux machine you can run one instance of IB gateway for around 700mb memory, so in theory you should able to run at least 1 client/G of memory and I've tried with 4 without any issue on a 3g notebook running Ubuntu 14. And then you have a lookup table on your Nodejs server (in Mongodb or even a simple array in js) of each client account number with their IP and Port number so that you able to run your trading program and route the message accordingly.

codeplexer avatar Jun 08 '16 05:06 codeplexer

Thank you guys for the reply, Codeplexer, let me understand what your solution, 1. We have to install IB gateway on each client side. 2. Install an IB gateway on the server side also, Is that correct? If this is the case, there is a question, Can one server IB gateway run multiple ip and port? If I have thousands of client, I need create thousand of object like the following

var ib[i] = new (require('..'))({ clientId: $('#clientId').val(), host : $('#host').val(), port : $('#port').val() });

where i is the index of the array or mongodb like you said.

Do I understand your reply correctly? Thanks

On Tue, Jun 7, 2016 at 10:19 PM, codeplexer [email protected] wrote:

Configure your client IB gateway listen on different port for each client, on a Linux machine you can run one instance of IB gateway for around 700mb memory, so in theory you should able to run at least 1 client/G of memory and I've tried with 4 without any issue on a 3g notebook running Ubuntu 14. And then you have a lookup table on your Nodejs server (in Mongodb or even a simple array in js) of each client account number with their IP and Port number so that you able to run your trading program and route the message accordingly.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/pilwon/node-ib/issues/42#issuecomment-224490257, or mute the thread https://github.com/notifications/unsubscribe/ASm3Bda9UrI6Wdb2VbX2Ie0r_7ILZzFyks5qJlDQgaJpZM4IknJD .

closelate avatar Jun 08 '16 07:06 closelate

Codeplexer, Are you talking about master account with sub account?

closelate avatar Jun 08 '16 08:06 closelate

Hi closelate, sorry for the late response, swarmed by lots of stuff. For your questions,

  1. We have to install IB gateway on each client side. Yes. You have to install IB gateway for each client, one instance of IB gateway can listen to only one port number. You able to configure it after it's started. So, say you have client1, client2, client3 on server 192.168.1.100 and client4, client5 on 192.168.1.101 var aryClientList = [ {Account:"client1", ipaddr:"192.168.1.100", port: 4003}, {Account:"client2", ipaddr:"192.168.1.100", port: 4004}, {Account:"client3", ipaddr:"192.168.1.100", port: 4005}, {Account:"client4", ipaddr:"192.168.1.101", port: 4003}, {Account:"client5", ipaddr:"192.168.1.101", port: 4004}, ];
  2. Install an IB gateway on the server side also, Is that correct?

Not really. Step 1. is your IB gateway server. Whenever you try to place an order, your code will need to know which IP address and port number to connect to base on the client.

In theory, if you have thousands of clients (Good for you), you should use IB Advisor accounts like a Hedge Fund account and all your client accounts are managed under one account which is much simpler than the above setup, and you need only one instance on IB gateway, the buy/sell order that you send to the gateway will need to have the account information. and the IB gateway will know which account the order belongs to.

codeplexer avatar Jun 20 '16 17:06 codeplexer

Thanks codeplexer,I moved everything to client side, client have to install IB gate way anyway.

On Mon, Jun 20, 2016 at 10:15 AM, codeplexer [email protected] wrote:

Hi closelate, sorry for the late response, swarmed by lots of stuff. For your questions,

  1. We have to install IB gateway on each client side. Yes. You have to install IB gateway for each client, one instance of IB gateway can listen to only one port number. You able to configure it after it's started. So, say you have client1, client2, client3 on server 192.168.1.100 and client4, client5 on 192.168.1.101 var aryClientList = [ {"client1", "192.168.1.100", 4003}, {"client2", "192.168.1.100", 4004}, {"client3", "192.168.1.100", 4005}, {"client4", "192.168.1.101", 4003}, {"client5", "192.168.1.101", 4004}, ];
  2. Install an IB gateway on the server side also, Is that correct? Not really. Step 1. is your IB gateway server. Whenever you try to place order, your code will need to know which IP address and port number to connect to base on the client.

In theory, if you have thousands of clients (Good for you), you should use IB Advisor accounts like a Hedge Fund account and all your client accounts are managed under one account which is much simpler than the above setup, and you need only one instance on IB gateway, the buy/sell order that you send to the gateway will need to have the account information.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/pilwon/node-ib/issues/42#issuecomment-227207569, or mute the thread https://github.com/notifications/unsubscribe/ASm3BczBGX9NYeBf50V2iTyygrV7ASsFks5qNsqsgaJpZM4IknJD .

closelate avatar Jun 21 '16 01:06 closelate