Skip to content

Commit

Permalink
Black
Browse files Browse the repository at this point in the history
  • Loading branch information
tgibson11 committed Oct 29, 2024
1 parent 4983254 commit e427073
Showing 1 changed file with 23 additions and 0 deletions.
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 e427073

Please sign in to comment.