Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
lovetrading10 opened this issue May 4, 2020 · 5 comments
Open

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

lovetrading10 opened this issue May 4, 2020 · 5 comments

Comments

@lovetrading10
Copy link

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.

@twopirllc
Copy link

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.

def set_historical_data(self, contract):
symbol = self.get_symbol(contract)
bars = self.ib.reqHistoricalData(
contract,
endDateTime=time.strftime('%Y%m%d %H:%M:%S'),
durationStr='3600 S',
barSizeSetting='5 secs',
whatToShow='MIDPOINT',
useRTH=True,
formatDate=1
)
for bar in bars:
dt_obj = dt_util.convert_local_datetime(bar.date)
self.df_hist.loc[dt_obj, symbol] = bar.close

Hope this helps,
KJ

@lovetrading10
Copy link
Author

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.

@twopirllc
Copy link

@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

@lovetrading10
Copy link
Author

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.

@twopirllc
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants