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

LME Contracts Issue? #1403

Closed
craigmediaservices opened this issue Sep 10, 2024 · 9 comments
Closed

LME Contracts Issue? #1403

craigmediaservices opened this issue Sep 10, 2024 · 9 comments

Comments

@craigmediaservices
Copy link

Recently I've been getting errors for a failure to find various LME contracts:

{'component': 'ibFuturesContractData', 'instrument_code': 'NICKEL_LME', 'contract_date': '20241100'} Error! Cannot find active contract! Expired? interactive_update_roll_status.py not executed?

I noticed this output in run_stack_handler:

2024-09-10 13:10:19 WARNING stack_handler {'component': 'ibFuturesContractData'} futuresInstrumentWithIBConfigData(instrument=NICKEL_LME, ib_data=symbol='NI', exchange='LMEOTC', currency='USD', ibMultiplier='6.0', priceMagnifier='1.00', ignoreWeekly='False', effective_multiplier='6.00') could not resolve contracts: NICKEL_LME has multiple plausible contracts but is not set to ignoreWeekly in IB config file
2024-09-10 13:10:19 WARNING stack_handler {'component': 'ibFuturesContractData', 'instrument_code': 'NICKEL_LME', 'contract_date': '20241100'} Contract is missing can't get expiry
2024-09-10 13:10:19 DEBUG stack_handler {'component': 'ibFuturesContractData', 'instrument_code': 'NICKEL_LME', 'contract_date': '20241100'} Can't resolve contract
2024-09-10 13:10:19 CRITICAL stack_handler {'component': 'ibFuturesContractData', 'instrument_code': 'NICKEL_LME', 'contract_date': '20241100'} Error! Cannot find active contract! Expired? interactive_update_roll_status.py not executed?

The error suggests that ignoreWeekly may resolve the issue, but I had not seen this before. Barchart and the LME website do not list multiple November LME contracts.

Thank you for any help.

@craigmediaservices
Copy link
Author

I also verified I have correct price data until a few days ago

2024-08-30 23:00:00 17035.0 17035.0 16750.0 16750.0 1.0
2024-09-02 08:00:00 16605.0 16605.0 16595.0 16595.0 2.0
2024-09-02 10:00:00 16605.0 16620.0 16605.0 16620.0 5.0
2024-09-02 11:00:00 16615.0 16615.0 16575.0 16615.0 13.0
2024-09-02 23:00:00 16605.0 16620.0 16575.0 16600.0 20.0
2024-09-03 04:00:00 16580.0 16610.0 16575.0 16600.0 20.0
2024-09-03 07:00:00 16435.0 16435.0 16435.0 16435.0 2.0
2024-09-03 08:00:00 16495.0 16495.0 16495.0 16495.0 1.0
2024-09-03 10:00:00 16350.0 16350.0 16350.0 16350.0 1.0
2024-09-03 12:00:00 16450.0 16450.0 16450.0 16450.0 1.0
2024-09-03 23:00:00 16580.0 16610.0 16350.0 16430.0 25.0
2024-09-04 03:00:00 16230.0 16245.0 16230.0 16245.0 10.0
2024-09-04 04:00:00 16250.0 16250.0 16200.0 16205.0 17.0
2024-09-04 08:00:00 16235.0 16235.0 16235.0 16235.0 2.0
2024-09-04 09:00:00 16225.0 16225.0 16200.0 16200.0 2.0
2024-09-04 11:00:00 16200.0 16200.0 16080.0 16080.0 7.0
2024-09-04 12:00:00 16075.0 16075.0 16075.0 16075.0 1.0
2024-09-04 13:00:00 16130.0 16130.0 16130.0 16130.0 1.0
2024-09-04 23:00:00 16230.0 16250.0 16075.0 16175.0 41.0
2024-09-05 03:00:00 16070.0 16090.0 15995.0 16000.0 23.0
2024-09-05 04:00:00 16005.0 16060.0 15975.0 15975.0 45.0
2024-09-05 06:00:00 15920.0 15920.0 15915.0 15915.0 32.0
2024-09-05 23:00:00 16070.0 16090.0 15915.0 16035.0 100.0
2024-09-06 04:00:00 15905.0 15920.0 15900.0 15900.0 23.0
2024-09-06 05:00:00 15900.0 15905.0 15875.0 15905.0 43.0
2024-09-06 06:00:00 15900.0 15900.0 15890.0 15890.0 13.0

@oldlore
Copy link

oldlore commented Sep 10, 2024

I don't have an explanation but I can verify that I have seen the same issue, although I only noticed it just now in the Status report.

                      last_update
TWD           2024-09-02 23:00:00
SGX           2024-09-02 23:00:00
TIN_LME       2024-09-04 23:00:00
LEAD_LME      2024-09-05 03:00:00
NICKEL_LME    2024-09-05 06:00:00
COPPER_LME    2024-09-05 12:00:00
ZINC_LME      2024-09-05 12:00:00
CNH-onshore   2024-09-05 23:00:00
ALUMINIUM_LME 2024-09-06 12:00:00

@tgibson11
Copy link
Contributor

tgibson11 commented Sep 10, 2024

I also see this issue.

Per IB UK website: residents of the US, Canada, Hong Kong, and Israel are not permitted to trade LME futures. (I also saw Singapore mentioned elsewhere.)

That doesn't necessarily mean we aren't allowed to get price data from LME, but maybe this has something to do with it. Someone would probably have to contact IB support for a definitive answer.

In any case, this almost certainly isn't a pysystemtrade issue. A discussion would be more appropriate.

@tgibson11
Copy link
Contributor

In TWS, I do indeed see multiple expiries in a given month, so maybe that is the only issue.

@tgibson11
Copy link
Contributor

In TWS, I do indeed see multiple expiries in a given month, so maybe that is the only issue.

All contracts look basically the same though. I can't see how you would identify one of them as monthly. Per the website I linked above, the contracts expiring on the 3rd Wednesday of the month are the most liquid. Code would need to be added here to identify the "monthly" contracts.

@tgibson11
Copy link
Contributor

I've added code to my repo that fixes this. After updating contracts, contract prices, multiple & adjusted prices, all my LME contracts are now up-to-date.

If anyone wants to make the change themselves, see this commit and this one.

The "is this the third Wednesday?" logic is a bit of a hack. It's really just checking if the contract expires on the third Monday, Tuesday, Wednesday, Thursday, or Friday. It seems to be working fine for now, but could be made more precise if necessary or desired.

I can create a PR if @robcarver17 is willing to merge it.

@craigmediaservices
Copy link
Author

craigmediaservices commented Sep 10, 2024

@tgibson11 Thank you for verifying these contracts could not be traded for US investors. I did not see that notification and will add them to trading_restrictions in private_config.yaml

Definitely helpful to know it's not worth paying the $65 data fee!

`

trading_restrictions:
- TIN_LME
- COPPER_LME
- LEAD_LME
- ZINC_LME
- ALUMINIUM_LME
- NICKEL_LME
`

I wonder if we could effectively swap for similar availables?

For example ALUMINUM, COPPER (or _mini, _micro),

@craigmediaservices
Copy link
Author

Thanks again @tgibson11 - I deleted my previous comment.

Confirmed that your code changes resolve the issue and I was able to successfully update_sampled_contracts.

bug-or-feature added a commit that referenced this issue Oct 26, 2024
@bug-or-feature
Copy link
Collaborator

Fixed by #1431

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

4 participants