pilwon / node-ib

Interactive Brokers TWS API client library for Node.js
380 stars 133 forks source link

How to handle multiple clients? #42

Open closelate opened 8 years ago

closelate commented 8 years ago

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

junajan commented 8 years ago

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..

codeplexer commented 8 years ago

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.

closelate commented 8 years ago

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 notifications@github.com 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 commented 8 years ago

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

codeplexer commented 8 years ago

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.

closelate commented 8 years ago

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 notifications@github.com 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 .