Skip to content

Commit

Permalink
Merge pull request #1438 from tgibson11/gas_us_weekly_contracts
Browse files Browse the repository at this point in the history
Ignore GAS_US weekly contracts
  • Loading branch information
bug-or-feature authored Oct 29, 2024
2 parents 4983254 + d986ca8 commit 8734912
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sysbrokers/IB/config/ib_config_futures.csv
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ FTSETAIWAN,TWN,SGX,USD,40,1,FALSE
FTSEVIET,FIVNM30,SGX,USD,5,1,FALSE
GAS_NL,TFM,ENDEX,EUR,1,1,FALSE
GAS_UK,NGF,IPE,GBP,31000,1,FALSE
GAS_US,NG,NYMEX,NA,10000,1,FALSE
GAS_US,NG,NYMEX,NA,10000,1,TRUE
GAS_US_mini,QG,NYMEX,USD,2500,1,FALSE
GAS-LAST,HH,NYMEX,USD,10000,1,FALSE
GAS-PEN,HP,NYMEX,USD,10000,1,FALSE
Expand Down
23 changes: 23 additions & 0 deletions sysbrokers/IB/ib_contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
EARLIEST_THIRD_WEDNESDAY = 15
LATEST_THIRD_WEDNESDAY = 21

GAS_US_CODE = "GAS_US"


def resolve_multiple_expiries(
ibcontract_list: list,
Expand All @@ -57,6 +59,8 @@ def resolve_multiple_expiries(
resolved_contract = resolve_multiple_expiries_for_EUREX(ibcontract_list)
elif code in LME_CODES:
resolved_contract = resolve_multiple_expiries_for_LME(ibcontract_list)
elif code == GAS_US_CODE:
resolved_contract = resolve_multiple_expiries_for_GAS_US(ibcontract_list)
else:
raise Exception(
"You have specified weekly expiries, but I don't have logic for %s" % code
Expand All @@ -81,6 +85,14 @@ def resolve_multiple_expiries_for_LME(ibcontract_list: list) -> ibContract:
return resolved_contract


def resolve_multiple_expiries_for_GAS_US(ibcontract_list: list) -> ibContract:
resolved_contract = resolve_multiple_expiries_for_generic_futures(
ibcontract_list=ibcontract_list, is_monthly_function=_is_gas_us_symbol_monthly
)

return resolved_contract


def resolve_multiple_expiries_for_VIX(ibcontract_list: list) -> ibContract:
# Get the symbols
resolved_contract = resolve_multiple_expiries_for_generic_futures(
Expand Down Expand Up @@ -139,6 +151,17 @@ def _is_lme_symbol_monthly(symbol: str):
return EARLIEST_THIRD_WEDNESDAY <= day <= LATEST_THIRD_WEDNESDAY


def _is_gas_us_symbol_monthly(symbol: str):
if re.match("HHW[A-Z][0-9][0-9][0-9]", symbol):
# weekly
return False
elif re.match("NG[A-Z][0-9]", symbol):
# monthly
return True
else:
raise Exception("IB Local Symbol %s not recognised" % symbol)


def _is_eurex_symbol_daily(symbol: str):
return symbol[-1] == EUREX_DAY_FLAG

Expand Down

0 comments on commit 8734912

Please sign in to comment.