High-Frequency-Trading-Model-with-IB icon indicating copy to clipboard operation
High-Frequency-Trading-Model-with-IB copied to clipboard

How to get pre-market-price from tws by using IB.

Open lovetrading10 opened this issue 4 years ago • 5 comments

I would like to get the pre-market-price -> the price between 8 -9.30. By the way, I don't know how to get the price. Would you please inform me about it? I will wait for your favorable reply. Thanks.

lovetrading10 avatar May 04 '20 15:05 lovetrading10

Hi @SunHxiao,

You will need to disable RTH (Regular Trading Hours) in the script and possibly change in your IB Gateway settings. How can I trade stocks during the pre-market or post market?

But first, I would try and set useRTH=False (line #249) in hft_model_1.py and see if that works. If you are not doing HFT, then also adjust durationStr and barSizeSetting.

https://github.com/jamesmawm/High-Frequency-Trading-Model-with-IB/blob/a19d2a62c2c73ad9e5053bf305a9c89306fbf193/models/hft_model_1.py#L240-L254

Hope this helps, KJ

twopirllc avatar May 04 '20 18:05 twopirllc

Hi, there. I appreciate your help. I would like to run your script(HFT). By the way, I can't run it. Would you please inform me how to run it? After downloading your script, how to install the environment, and how to run it. Thank you very much.

lovetrading10 avatar May 04 '20 23:05 lovetrading10

@SunHxiao,

My script? Or the owner's, Jame's, HFT script?

To run it, you need to make sure you have IB Gateway installed and Paper Trade Account setup because you certainly do not want to run it on a funded Live Account without fulling understanding what the algorithm does. In fact, make sure any Algo is ran on a Paper Trading Account and does as expected for some time before running it on a Live Account.

As for installation, there is a green 'Clone or Download' button at the Repository main page. I also recommend installing a Python 3 Virtual Environment or use Anaconda to setup the environment. I would look for videos on how to set up the Python environment if you are not familiar doing it.

Hope this helps. Good luck. KJ

twopirllc avatar May 05 '20 03:05 twopirllc

Hi @twopirllc. Thanks for your quick reply. I have following issue. "Only 50 simultaneous API historical data requests allowed." For fixing this error, I have used ib.cancelHistoricalData function. So I fixed the error. But I am getting this message. image I don't want to get this message. Can you help me? Thanks for your kind.

lovetrading10 avatar May 05 '20 07:05 lovetrading10

Hey @SunHxiao,

If you are limited to 50 simultaneous API historical data requests, then you need to throttle or stagger your requests to stay under 50. Here are the IB API Message Codes. Unfortunately Error 162 has no Additional Notes about it.

Play around with your code some more and you'll figure it out.

Good luck, KJ

twopirllc avatar May 05 '20 16:05 twopirllc