Skip to content

Commit 1d6a547

Browse files
authored
Updates Python Example get_value to get (#8806)
`get` is the Pythonist way to access a dictionary. Also, `not x` replaces `is None`, since the former translates into is None or empty.
1 parent c9c8925 commit 1d6a547

8 files changed

Lines changed: 15 additions & 15 deletions

Algorithm.Python/Alphas/MeanReversionLunchBreakAlpha.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def update(self, algorithm, data):
7777

7878
for symbol, symbol_data in self._symbol_data_by_symbol.items():
7979
if data.bars.contains_key(symbol):
80-
bar = data.bars.get_value(symbol)
80+
bar = data.bars.get(symbol)
8181
symbol_data.update(bar.end_time, bar.close)
8282

8383
return [] if algorithm.time.hour != 12 else \

Algorithm.Python/BasicTemplateOptionEquityStrategyAlgorithm.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ def on_data(self, slice: Slice) -> None:
4242
if self.portfolio.invested or not self.is_market_open(self._option_symbol):
4343
return
4444

45-
chain = slice.option_chains.get_value(self._option_symbol)
46-
if chain is None:
45+
chain = slice.option_chains.get(self._option_symbol)
46+
if not chain:
4747
return
4848

4949
grouped_by_expiry = dict()

Algorithm.Python/BasicTemplateOptionsAlgorithm.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ def initialize(self):
4646
def on_data(self, slice):
4747
if self.portfolio.invested or not self.is_market_open(self.option_symbol): return
4848

49-
chain = slice.option_chains.get_value(self.option_symbol)
50-
if chain is None:
49+
chain = slice.option_chains.get(self.option_symbol)
50+
if not chain:
5151
return
5252

5353
# we sort the contracts to find at the money (ATM) contract with farthest expiration

Algorithm.Python/BasicTemplateOptionsDailyAlgorithm.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ def initialize(self):
4343
def on_data(self,slice):
4444
if self.portfolio.invested: return
4545

46-
chain = slice.option_chains.get_value(self.option_symbol)
47-
if chain is None:
46+
chain = slice.option_chains.get(self.option_symbol)
47+
if not chain:
4848
return
4949

5050
# Grab us the contract nearest expiry

Algorithm.Python/BasicTemplateOptionsHourlyAlgorithm.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ def initialize(self):
4646
def on_data(self,slice):
4747
if self.portfolio.invested or not self.is_market_open(self.option_symbol): return
4848

49-
chain = slice.option_chains.get_value(self.option_symbol)
50-
if chain is None:
49+
chain = slice.option_chains.get(self.option_symbol)
50+
if not chain:
5151
return
5252

5353
# we sort the contracts to find at the money (ATM) contract with farthest expiration

Algorithm.Python/BasicTemplateSPXWeeklyIndexOptionsAlgorithm.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ def initialize(self):
4242
def on_data(self,slice):
4343
if self.portfolio.invested: return
4444

45-
chain = slice.option_chains.get_value(self.spxw_option)
46-
if chain is None:
45+
chain = slice.option_chains.get(self.spxw_option)
46+
if not chain:
4747
return
4848

4949
# we sort the contracts to find at the money (ATM) contract with closest expiration

Algorithm.Python/ComboOrderTicketDemoAlgorithm.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ def initialize(self) -> None:
3939
def on_data(self, data: Slice) -> None:
4040
if self._order_legs is None:
4141
if self.is_market_open(self._option_symbol):
42-
chain = data.option_chains.get_value(self._option_symbol)
43-
if chain is not None:
42+
chain = data.option_chains.get(self._option_symbol)
43+
if chain:
4444
call_contracts = [contract for contract in chain if contract.right == OptionRight.CALL]
4545
call_contracts_by_expiry = [(key, list(group)) for key, group in itertools.groupby(call_contracts, key=lambda x: x.expiry)]
4646
call_contracts_by_expiry.sort(key=lambda x: x[0])

Algorithm.Python/NullMarginMultipleOrdersRegressionAlgorithm.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ def initialize(self):
3737
def on_data(self, data: Slice):
3838
if not self.portfolio.invested:
3939
if self.is_market_open(self._option_symbol):
40-
chain = data.option_chains.get_value(self._option_symbol)
41-
if chain is not None:
40+
chain = data.option_chains.get(self._option_symbol)
41+
if chain:
4242
call_contracts = [contract for contract in chain if contract.right == OptionRight.CALL]
4343
call_contracts.sort(key=lambda x: (x.expiry, 1/ x.strike), reverse=True)
4444

0 commit comments

Comments
 (0)