robcarver17 / pysystemtrade

Systematic Trading in python
GNU General Public License v3.0
2.49k stars 798 forks source link

contract data not pulling from mongodb, but now appears to reside in parquet #1334

Closed t3chap closed 4 months ago

t3chap commented 5 months ago

I'm running a PST that currently doesn't have access to IB. (I have another system running on IB and it can't support ibnsnyc along with what I currently have running, and I don't know if I can open another account, etc.) So what I've found might not be a problem if PST can interact with IB, I don't know.

Bottom line, lots of things don't work because PST can't get contract data. However, all of the data does exist in parquet and can be accessed by PST. I'm able to run backtests, generate orders, etc.

from sysdata.data_blob import dataBlob
from sysproduction.data.contracts import dataContracts
with dataBlob(log_name="Interactive-Diagnostics") as data:
    diag_contracts = dataContracts(data)
diag_contracts.db_contract_data.get_all_contract_objects_for_instrument_code('MXP')
[]
diag_contracts.db_contract_data.get_list_of_all_instruments_with_contracts()
[]
diag_contracts.get_labelled_dict_of_current_contracts('MXP')
{'contracts': ['20240600', '20240300', '20240600'],
 'labels': ['20240600c', '20240300p', '20240600f']}

data.db_futures_contract_price.contracts_with_merged_price_data_for_instrument_code('MXP')
[MXP/20050900,
 MXP/20240600,
 MXP/20200600,
 MXP/20220900,
 MXP/20080600,
 MXP/20020900,
 MXP/20100300,
 MXP/20120600,
 MXP/20051200,
 MXP/20110600,
 MXP/20170300,
 MXP/20180300,
 MXP/19990300,
 MXP/20090900,
 MXP/20061200,
 MXP/20000300,
 MXP/20001200,
 MXP/20110900,
 MXP/20211200,
 MXP/20170900,
 MXP/20110300,
 MXP/20030600,
 MXP/19991200,
 MXP/20091200,
 MXP/20030300,
 MXP/19970900,
 MXP/19970600,
 MXP/20070600,
 MXP/20070900,
 MXP/20011200,
 MXP/20000900,
 MXP/20160300,
 MXP/20250300,
 MXP/20150900,
 MXP/20220600,
 MXP/20160900,
 MXP/20080900,
 MXP/20190900,
 MXP/20181200,
 MXP/20060600,
 MXP/20010300,
 MXP/20040900,
 MXP/20240300,
 MXP/20210900,
 MXP/20250600,
 MXP/19980600,
 MXP/20060300,
 MXP/19980300,
 MXP/20180600,
 MXP/20120300,
 MXP/20010600,
 MXP/20190600,
 MXP/20101200,
 MXP/20121200,
 MXP/20131200,
 MXP/20201200,
 MXP/20040300,
 MXP/20200300,
 MXP/19960300,
 MXP/19970300,
 MXP/20230900,
 MXP/20120900,
 MXP/19981200,
 MXP/19980900,
 MXP/19971200,
 MXP/20100900,
 MXP/19950900,
 MXP/20171200,
 MXP/20161200,
 MXP/20140600,
 MXP/20191200,
 MXP/19990900,
 MXP/20130300,
 MXP/20150300,
 MXP/20231200,
 MXP/20041200,
 MXP/20221200,
 MXP/20190300,
 MXP/20160600,
 MXP/20230300,
 MXP/20210600,
 MXP/19960600,
 MXP/20241200,
 MXP/20170600,
 MXP/20141200,
 MXP/20030900,
 MXP/20130900,
 MXP/20151200,
 MXP/20180900,
 MXP/20210300,
 MXP/20230600,
 MXP/20090300,
 MXP/19960900,
 MXP/20130600,
 MXP/20021200,
 MXP/20020600,
 MXP/20060900,
 MXP/20071200,
 MXP/20220300,
 MXP/20050300,
 MXP/20140300,
 MXP/20050600,
 MXP/20020300,
 MXP/20010900,
 MXP/19950600,
 MXP/19961200,
 MXP/19951200,
 MXP/20070300,
 MXP/19990600,
 MXP/20000600,
 MXP/20090600,
 MXP/20111200,
 MXP/20031200,
 MXP/20140900,
 MXP/20040600,
 MXP/20240900,
 MXP/20150600,
 MXP/20200900,
 MXP/20100600,
 MXP/20080300,
 MXP/20081200]

Digging through the code, it appears that sysdata/mongodb/mongo_futures_contracts.py might be the problem, as the functions that don't return data appear to live in this code. I'm importing the data from barchart to csv using my own code, and importing it using the code in /sysinit/futures/contract_prices_from_csv_to_arctic.py to go from csv to PST data.

The functions that do return data appear to me to be referencing the parquet data. As far as I can tell in mongodb the contract data doesn't exist, and the contract_prices_from_csv_to_arctic.py doesn't appear to do anything to add them to mongodb.

I'm not the worlds best coder and tend to get lost when code inherits methods or functions for prior modules so it is entirely possible I'm missing something but this is my analysis.

This problem causes problems with the interactive_order_stack, reports (roll report of particular note and importance), and interactive_diagnostics. For example, in a position I hold I need to add a position but because of the volume/oi, I wanted to add a different contract month. I can't do this as the interactive_order_stack won't allow a manual entry when it can't find the contract object for the symbol I'm trying to use.

Also, this problem occurs for all of my instruments, not just MXP. I might be able to craft a work-around but I suspect I'll probably break more stuff than I'll fix. Please let me know if you need more information and I appreciate any help. Thanks.

robcarver17 commented 4 months ago

There is no 'problem' you need contract dates to run the production system and at the moment they can only come from IB. You can run backtetsts and do other things because you have price data and that is all they need.

It should be possible to write a piece of code that allows you to manually type in the contract expiry dates rather than getting them from IB, but there are probably quite a few touch points where you need to get data from IB so there is no guarantee you won't get other problems.