Skip to content

Commit

Permalink
autoconvert string args to get_instruments to a list
Browse files Browse the repository at this point in the history
  • Loading branch information
alexgolec committed Jun 30, 2024
1 parent 324e58f commit ef9d7b8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions schwab/client/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1119,6 +1119,9 @@ def get_instruments(self, symbols, projection):
- String, or array of strings
- Symbols for which to return fundamentals. Exact match.
'''
if isinstance(symbols, str):
symbols = [symbols]

projection = self.convert_enum(projection, self.Instrument.Projection)

params = {
Expand Down
9 changes: 9 additions & 0 deletions tests/client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2178,6 +2178,15 @@ def test_get_instruments(self):
'projection': 'fundamental'})


def test_get_instruments_string_args(self):
self.client.get_instruments(
'AAPL', self.client_class.Instrument.Projection.FUNDAMENTAL)
self.mock_session.get.assert_called_once_with(
self.make_url('/marketdata/v1/instruments'), params={
'symbol': 'AAPL',
'projection': 'fundamental'})


def test_get_instruments_projection_unchecked(self):
self.client.set_enforce_enums(False)
self.client.get_instruments(
Expand Down

0 comments on commit ef9d7b8

Please sign in to comment.