From 5ac64e79b0f02f860d9b3d49ff7d4f9ad668199f Mon Sep 17 00:00:00 2001 From: Alex Golec Date: Sat, 4 May 2024 09:50:47 -0400 Subject: [PATCH] merge stashed files --- schwab/client/base.py | 10 +- tests/client_test.py | 2209 ++++++++++++++++++++++------------------- 2 files changed, 1168 insertions(+), 1051 deletions(-) diff --git a/schwab/client/base.py b/schwab/client/base.py index 8e219e9..1bd1ff0 100644 --- a/schwab/client/base.py +++ b/schwab/client/base.py @@ -171,16 +171,16 @@ def get_accounts(self, *, fields=None): ########################################################################## # Orders - def cancel_order(self, order_id, account_hash): - '''Cancel a specific order for a specific account''' - path = '/trader/v1/accounts/{}/orders/{}'.format(account_hash, order_id) - return self._delete_request(path) - def get_order(self, order_id, account_hash): '''Get a specific order for a specific account by its order ID''' path = '/trader/v1/accounts/{}/orders/{}'.format(account_hash, order_id) return self._get_request(path, {}) + def cancel_order(self, order_id, account_hash): + '''Cancel a specific order for a specific account''' + path = '/trader/v1/accounts/{}/orders/{}'.format(account_hash, order_id) + return self._delete_request(path) + class Order: class Status(Enum): '''Order statuses passed to :meth:`get_orders_for_account` and diff --git a/tests/client_test.py b/tests/client_test.py index d658583..a4d5985 100644 --- a/tests/client_test.py +++ b/tests/client_test.py @@ -95,164 +95,6 @@ def test_set_timeout(self): self.assertEqual(timeout, self.client.session.timeout) - ''' - # place_order - - - def test_place_order(self): - order_spec = {'order': 'spec'} - self.client.place_order(ACCOUNT_HASH, order_spec) - self.mock_session.post.assert_called_once_with( - self.make_url('/v1/accounts/{accountHash}/orders'), json=order_spec) - - - def test_place_order_order_builder(self): - order_spec = OrderBuilder(enforce_enums=False).set_order_type('LIMIT') - expected_spec = {'orderType': 'LIMIT'} - self.client.place_order(ACCOUNT_HASH, order_spec) - self.mock_session.post.assert_called_once_with( - self.make_url('/v1/accounts/{accountHash}/orders'), - json=expected_spec) - - - def test_place_order_str(self): - order_spec = {'order': 'spec'} - self.client.place_order(str(ACCOUNT_HASH), order_spec) - self.mock_session.post.assert_called_once_with( - self.make_url('/v1/accounts/{accountHash}/orders'), json=order_spec) - - # replace_order - - - def test_replace_order(self): - order_spec = {'order': 'spec'} - self.client.replace_order(ACCOUNT_HASH, ORDER_ID, order_spec) - self.mock_session.put.assert_called_once_with( - self.make_url('/v1/accounts/{accountHash}/orders/{orderId}'), - json=order_spec) - - - def test_replace_order_order_builder(self): - order_spec = OrderBuilder(enforce_enums=False).set_order_type('LIMIT') - expected_spec = {'orderType': 'LIMIT'} - self.client.replace_order(ACCOUNT_HASH, ORDER_ID, order_spec) - self.mock_session.put.assert_called_once_with( - self.make_url('/v1/accounts/{accountHash}/orders/{orderId}'), - json=expected_spec) - - - def test_replace_order_str(self): - order_spec = {'order': 'spec'} - self.client.replace_order(str(ACCOUNT_HASH), str(ORDER_ID), order_spec) - self.mock_session.put.assert_called_once_with( - self.make_url('/v1/accounts/{accountHash}/orders/{orderId}'), - json=order_spec) - - # create_saved_order - - - def test_create_saved_order(self): - order_spec = {'order': 'spec'} - self.client.create_saved_order(ACCOUNT_HASH, order_spec) - self.mock_session.post.assert_called_once_with( - self.make_url('/v1/accounts/{accountHash}/savedorders'), - json=order_spec) - - - def test_create_saved_order_order_builder(self): - order_spec = OrderBuilder(enforce_enums=False).set_order_type('LIMIT') - expected_spec = {'orderType': 'LIMIT'} - self.client.create_saved_order(ACCOUNT_HASH, order_spec) - self.mock_session.post.assert_called_once_with( - self.make_url('/v1/accounts/{accountHash}/savedorders'), - json=expected_spec) - - - def test_create_saved_order_str(self): - order_spec = {'order': 'spec'} - self.client.create_saved_order(str(ACCOUNT_HASH), order_spec) - self.mock_session.post.assert_called_once_with( - self.make_url('/v1/accounts/{accountHash}/savedorders'), - json=order_spec) - - # delete_saved_order - - - def test_delete_saved_order(self): - self.client.delete_saved_order(ACCOUNT_HASH, SAVED_ORDER_ID) - self.mock_session.delete.assert_called_once_with( - self.make_url('/v1/accounts/{accountHash}/savedorders/{savedOrderId}')) - - - def test_delete_saved_order_str(self): - self.client.delete_saved_order(str(ACCOUNT_HASH), str(SAVED_ORDER_ID)) - self.mock_session.delete.assert_called_once_with( - self.make_url('/v1/accounts/{accountHash}/savedorders/{savedOrderId}')) - - # delete_saved_order - - - def test_get_saved_order(self): - self.client.get_saved_order(ACCOUNT_HASH, SAVED_ORDER_ID) - self.mock_session.get.assert_called_once_with( - self.make_url( - '/v1/accounts/{accountHash}/savedorders/{savedOrderId}'), - params={}) - - - def test_get_saved_order_str(self): - self.client.get_saved_order(str(ACCOUNT_HASH), str(SAVED_ORDER_ID)) - self.mock_session.get.assert_called_once_with( - self.make_url( - '/v1/accounts/{accountHash}/savedorders/{savedOrderId}'), - params={}) - - # get_saved_orders_by_path - - - def test_get_saved_orders_by_path(self): - self.client.get_saved_orders_by_path(ACCOUNT_HASH) - self.mock_session.get.assert_called_once_with( - self.make_url('/v1/accounts/{accountHash}/savedorders'), params={}) - - - def test_get_saved_orders_by_path_str(self): - self.client.get_saved_orders_by_path(str(ACCOUNT_HASH)) - self.mock_session.get.assert_called_once_with( - self.make_url('/v1/accounts/{accountHash}/savedorders'), params={}) - - # replace_saved_order - - - def test_replace_saved_order(self): - order_spec = {'order': 'spec'} - self.client.replace_saved_order(ACCOUNT_HASH, SAVED_ORDER_ID, order_spec) - self.mock_session.put.assert_called_once_with( - self.make_url( - '/v1/accounts/{accountHash}/savedorders/{savedOrderId}'), - json=order_spec) - - - def test_replace_saved_order_order_builder(self): - order_spec = OrderBuilder(enforce_enums=False).set_order_type('LIMIT') - expected_spec = {'orderType': 'LIMIT'} - self.client.replace_saved_order(ACCOUNT_HASH, SAVED_ORDER_ID, order_spec) - self.mock_session.put.assert_called_once_with( - self.make_url( - '/v1/accounts/{accountHash}/savedorders/{savedOrderId}'), - json=expected_spec) - - - def test_replace_saved_order_str(self): - order_spec = {'order': 'spec'} - self.client.replace_saved_order( - str(ACCOUNT_HASH), str(SAVED_ORDER_ID), order_spec) - self.mock_session.put.assert_called_once_with( - self.make_url( - '/v1/accounts/{accountHash}/savedorders/{savedOrderId}'), - json=order_spec) - ''' - # get_account @@ -352,7 +194,6 @@ def test_cancel_order_str(self): self.mock_session.delete.assert_called_once_with( self.make_url('/trader/v1/accounts/{accountHash}/orders/{orderId}')) - # get_orders_for_account @patch('schwab.client.base.datetime.datetime', mockdatetime) @@ -562,552 +403,440 @@ def test_get_orders_for_all_linked_accounts_status_unchecked(self): }) - ''' - # search_instruments + # get_price_history - def test_search_instruments(self): - self.client.search_instruments( - ['AAPL', 'MSFT'], self.client_class.Instrument.Projection.FUNDAMENTAL) + def test_get_price_history_vanilla(self): + self.client.get_price_history(SYMBOL) self.mock_session.get.assert_called_once_with( - self.make_url('/v1/instruments'), params={ - 'apikey': API_KEY, - 'symbol': 'AAPL,MSFT', - 'projection': 'fundamental'}) + self.make_url('/marketdata/v1/pricehistory'), params={ + 'symbol': SYMBOL}) - def test_search_instruments_one_instrument(self): - self.client.search_instruments( - 'AAPL', self.client_class.Instrument.Projection.FUNDAMENTAL) + def test_get_price_history_period_type(self): + self.client.get_price_history( + SYMBOL, period_type=self.client_class.PriceHistory.PeriodType.MONTH) self.mock_session.get.assert_called_once_with( - self.make_url('/v1/instruments'), params={ - 'apikey': API_KEY, - 'symbol': 'AAPL', - 'projection': 'fundamental'}) + self.make_url('/marketdata/v1/pricehistory'), params={ + 'symbol': SYMBOL, + 'periodType': 'month'}) - def test_search_instruments_unchecked(self): + def test_get_price_history_period_type_unchecked(self): self.client.set_enforce_enums(False) - self.client.search_instruments(['AAPL', 'MSFT'], 'fundamental') + self.client.get_price_history(SYMBOL, period_type='month') self.mock_session.get.assert_called_once_with( - self.make_url('/v1/instruments'), params={ - 'apikey': API_KEY, - 'symbol': 'AAPL,MSFT', - 'projection': 'fundamental'}) - - # get_instrument + self.make_url('/marketdata/v1/pricehistory'), params={ + 'symbol': SYMBOL, + 'periodType': 'month'}) - def test_get_instrument(self): - self.client.get_instrument(CUSIP) + def test_get_price_history_num_periods(self): + self.client.get_price_history( + SYMBOL, period=self.client_class.PriceHistory.Period.TEN_DAYS) self.mock_session.get.assert_called_once_with( - self.make_url('/v1/instruments/{cusip}'), - params={'apikey': API_KEY}) + self.make_url('/marketdata/v1/pricehistory'), params={ + 'symbol': SYMBOL, + 'period': 10}) - def test_get_instrument_cusip_must_be_string(self): - msg = 'CUSIPs must be passed as strings to preserve leading zeroes' - with self.assertRaises(ValueError, msg=msg): - self.client.get_instrument(123456) - - # get_hours_for_multiple_markets + def test_get_price_history_num_periods_unchecked(self): + self.client.set_enforce_enums(False) + self.client.get_price_history(SYMBOL, period=10) + self.mock_session.get.assert_called_once_with( + self.make_url('/marketdata/v1/pricehistory'), params={ + 'symbol': SYMBOL, + 'period': 10}) - def test_get_hours_for_multiple_markets_datetime(self): - self.client.get_hours_for_multiple_markets([ - self.client_class.Markets.EQUITY, - self.client_class.Markets.BOND], NOW_DATETIME) + def test_get_price_history_frequency_type(self): + self.client.get_price_history( + SYMBOL, + frequency_type=self.client_class.PriceHistory.FrequencyType.DAILY) self.mock_session.get.assert_called_once_with( - self.make_url('/v1/marketdata/hours'), params={ - 'apikey': API_KEY, - 'markets': 'EQUITY,BOND', - 'date': NOW_DATE_ISO}) + self.make_url('/marketdata/v1/pricehistory'), params={ + 'symbol': SYMBOL, + 'frequencyType': 'daily'}) - def test_get_hours_for_multiple_markets_single_market(self): - self.client.get_hours_for_multiple_markets( - self.client_class.Markets.EQUITY, NOW_DATETIME) + def test_get_price_history_frequency_type_unchecked(self): + self.client.set_enforce_enums(False) + self.client.get_price_history(SYMBOL, frequency_type='daily') self.mock_session.get.assert_called_once_with( - self.make_url('/v1/marketdata/hours'), params={ - 'apikey': API_KEY, - 'markets': 'EQUITY', - 'date': NOW_DATE_ISO}) + self.make_url('/marketdata/v1/pricehistory'), params={ + 'symbol': SYMBOL, + 'frequencyType': 'daily'}) - def test_get_hours_for_multiple_markets_date(self): - self.client.get_hours_for_multiple_markets([ - self.client_class.Markets.EQUITY, - self.client_class.Markets.BOND], NOW_DATE) - self.mock_session.get.assert_called_once_with( - self.make_url('/v1/marketdata/hours'), params={ - 'apikey': API_KEY, - 'markets': 'EQUITY,BOND', - 'date': NOW_DATE_ISO}) - - - def test_get_hours_for_multiple_markets_str(self): - with self.assertRaises(ValueError) as cm: - self.client.get_hours_for_multiple_markets([ - self.client_class.Markets.EQUITY, - self.client_class.Markets.BOND], '2020-01-01') - self.assertEqual(str(cm.exception), - "expected type in (datetime.date, datetime.datetime) " - "for date, got 'builtins.str'") - - - def test_get_hours_for_multiple_markets_unchecked(self): - self.client.set_enforce_enums(False) - self.client.get_hours_for_multiple_markets( - ['EQUITY', 'BOND'], NOW_DATETIME) + def test_get_price_history_frequency(self): + self.client.get_price_history( + SYMBOL, + frequency=self.client_class.PriceHistory.Frequency.EVERY_FIVE_MINUTES) self.mock_session.get.assert_called_once_with( - self.make_url('/v1/marketdata/hours'), params={ - 'apikey': API_KEY, - 'markets': 'EQUITY,BOND', - 'date': NOW_DATE_ISO}) + self.make_url('/marketdata/v1/pricehistory'), params={ + 'symbol': SYMBOL, + 'frequency': 5}) - # get_hours_for_single_market - - def test_get_hours_for_single_market_datetime(self): - self.client.get_hours_for_single_market( - self.client_class.Markets.EQUITY, NOW_DATETIME) + def test_get_price_history_frequency_unchecked(self): + self.client.set_enforce_enums(False) + self.client.get_price_history(SYMBOL, frequency=5) self.mock_session.get.assert_called_once_with( - self.make_url('/v1/marketdata/{market}/hours'), params={ - 'apikey': API_KEY, - 'date': NOW_DATE_ISO}) + self.make_url('/marketdata/v1/pricehistory'), params={ + 'symbol': SYMBOL, + 'frequency': 5}) - def test_get_hours_for_single_market_date(self): - self.client.get_hours_for_single_market( - self.client_class.Markets.EQUITY, NOW_DATE) + def test_get_price_history_start_datetime(self): + self.client.get_price_history( + SYMBOL, start_datetime=EARLIER_DATETIME) self.mock_session.get.assert_called_once_with( - self.make_url('/v1/marketdata/{market}/hours'), params={ - 'apikey': API_KEY, - 'date': NOW_DATE_ISO}) + self.make_url('/marketdata/v1/pricehistory'), params={ + 'symbol': SYMBOL, + 'startDate': EARLIER_MILLIS}) - def test_get_hours_for_single_market_str(self): + def test_get_price_history_start_datetime_str(self): with self.assertRaises(ValueError) as cm: - self.client.get_hours_for_single_market( - self.client_class.Markets.EQUITY, '2020-01-01') + self.client.get_price_history(SYMBOL, start_datetime='2020-01-01') self.assertEqual(str(cm.exception), - "expected type in (datetime.date, datetime.datetime) for " + - "date, got 'builtins.str'") + "expected type 'datetime.datetime' for " + + "start_datetime, got 'builtins.str'") - def test_get_hours_for_single_market_unchecked(self): - self.client.set_enforce_enums(False) - self.client.get_hours_for_single_market('EQUITY', NOW_DATETIME) + def test_get_price_history_end_datetime(self): + self.client.get_price_history(SYMBOL, end_datetime=EARLIER_DATETIME) self.mock_session.get.assert_called_once_with( - self.make_url('/v1/marketdata/{market}/hours'), params={ - 'apikey': API_KEY, - 'date': NOW_DATE_ISO}) - - # get_movers + self.make_url('/marketdata/v1/pricehistory'), params={ + 'symbol': SYMBOL, + 'endDate': EARLIER_MILLIS}) - def test_get_movers(self): - self.client.get_movers( - INDEX, self.client_class.Movers.Direction.UP, self.client_class.Movers.Change.PERCENT) - self.mock_session.get.assert_called_once_with( - self.make_url('/v1/marketdata/{index}/movers'), params={ - 'apikey': API_KEY, - 'direction': 'up', - 'change': 'percent'}) + def test_get_price_history_end_datetime_str(self): + with self.assertRaises(ValueError) as cm: + self.client.get_price_history(SYMBOL, end_datetime='2020-01-01') + self.assertEqual(str(cm.exception), + "expected type 'datetime.datetime' for " + + "end_datetime, got 'builtins.str'") - def test_get_movers_unchecked(self): - self.client.set_enforce_enums(False) - self.client.get_movers(INDEX, 'up', 'percent') + def test_get_price_history_need_extended_hours_data(self): + self.client.get_price_history(SYMBOL, need_extended_hours_data=True) self.mock_session.get.assert_called_once_with( - self.make_url('/v1/marketdata/{index}/movers'), params={ - 'apikey': API_KEY, - 'direction': 'up', - 'change': 'percent'}) + self.make_url('/marketdata/v1/pricehistory'), params={ + 'symbol': SYMBOL, + 'needExtendedHoursData': True}) - # get_option_chain - - def test_get_option_chain_vanilla(self): - self.client.get_option_chain('AAPL') + def test_get_price_history_need_previous_close(self): + self.client.get_price_history(SYMBOL, need_previous_close=True) self.mock_session.get.assert_called_once_with( - self.make_url('/v1/marketdata/chains'), params={ - 'apikey': API_KEY, - 'symbol': 'AAPL'}) + self.make_url('/marketdata/v1/pricehistory'), params={ + 'symbol': SYMBOL, + 'needPreviousClose': True}) - - def test_get_option_chain_contract_type(self): - self.client.get_option_chain( - 'AAPL', contract_type=self.client_class.Options.ContractType.PUT) - self.mock_session.get.assert_called_once_with( - self.make_url('/v1/marketdata/chains'), params={ - 'apikey': API_KEY, - 'symbol': 'AAPL', - 'contractType': 'PUT'}) - - def test_get_option_chain_contract_type_unchecked(self): - self.client.set_enforce_enums(False) - self.client.get_option_chain('AAPL', contract_type='PUT') - self.mock_session.get.assert_called_once_with( - self.make_url('/v1/marketdata/chains'), params={ - 'apikey': API_KEY, - 'symbol': 'AAPL', - 'contractType': 'PUT'}) + # get_price_history_every_minute - - def test_get_option_chain_strike_count(self): - self.client.get_option_chain('AAPL', strike_count=100) - self.mock_session.get.assert_called_once_with( - self.make_url('/v1/marketdata/chains'), params={ - 'apikey': API_KEY, - 'symbol': 'AAPL', - 'strikeCount': 100}) - - def test_get_option_chain_include_quotes(self): - self.client.get_option_chain('AAPL', include_quotes=True) - self.mock_session.get.assert_called_once_with( - self.make_url('/v1/marketdata/chains'), params={ - 'apikey': API_KEY, + @patch('schwab.client.base.datetime.datetime', mockdatetime) + def test_get_price_history_every_minute_vanilla(self): + self.client.get_price_history_every_minute('AAPL') + params = { 'symbol': 'AAPL', - 'includeQuotes': True}) - - - def test_get_option_chain_strategy(self): - self.client.get_option_chain( - 'AAPL', strategy=self.client_class.Options.Strategy.STRANGLE) + 'periodType': 'day', + # ONE_DAY + 'period': 1, + 'frequencyType': 'minute', + # EVERY_MINUTE + 'frequency': 1, + 'startDate': MIN_TIMESTAMP_MILLIS, + 'endDate': NOW_DATETIME_PLUS_SEVEN_DAYS_TIMESTAMP_MILLIS, + } self.mock_session.get.assert_called_once_with( - self.make_url('/v1/marketdata/chains'), params={ - 'apikey': API_KEY, - 'symbol': 'AAPL', - 'strategy': 'STRANGLE'}) + self.make_url('/marketdata/v1/pricehistory'), + params=params) - - def test_get_option_chain_strategy_unchecked(self): - self.client.set_enforce_enums(False) - self.client.get_option_chain('AAPL', strategy='STRANGLE') - self.mock_session.get.assert_called_once_with( - self.make_url('/v1/marketdata/chains'), params={ - 'apikey': API_KEY, - 'symbol': 'AAPL', - 'strategy': 'STRANGLE'}) - - def test_get_option_chain_interval(self): - self.client.get_option_chain('AAPL', interval=10.0) + @patch('schwab.client.base.datetime.datetime', mockdatetime) + def test_get_price_history_every_minute_start_datetime(self): + self.client.get_price_history_every_minute( + 'AAPL', start_datetime=EARLIER_DATETIME) + params = { + 'symbol': SYMBOL, + 'periodType': 'day', + # ONE_DAY + 'period': 1, + 'frequencyType': 'minute', + # EVERY_MINUTE + 'frequency': 1, + 'startDate': EARLIER_MILLIS, + 'endDate': NOW_DATETIME_PLUS_SEVEN_DAYS_TIMESTAMP_MILLIS, + } self.mock_session.get.assert_called_once_with( - self.make_url('/v1/marketdata/chains'), params={ - 'apikey': API_KEY, - 'symbol': 'AAPL', - 'interval': 10.0}) + self.make_url('/marketdata/v1/pricehistory'), + params=params) - - def test_get_option_chain_strike(self): - self.client.get_option_chain('AAPL', strike=123) - self.mock_session.get.assert_called_once_with( - self.make_url('/v1/marketdata/chains'), params={ - 'apikey': API_KEY, - 'symbol': 'AAPL', - 'strike': 123}) - - def test_get_option_chain_strike_range(self): - self.client.get_option_chain( - 'AAPL', strike_range=self.client_class.Options.StrikeRange.IN_THE_MONEY) + @patch('schwab.client.base.datetime.datetime', mockdatetime) + def test_get_price_history_every_minute_end_datetime(self): + self.client.get_price_history_every_minute( + 'AAPL', end_datetime=EARLIER_DATETIME) + params = { + 'symbol': SYMBOL, + 'periodType': 'day', + # ONE_DAY + 'period': 1, + 'frequencyType': 'minute', + # EVERY_MINUTE + 'frequency': 1, + 'startDate': MIN_TIMESTAMP_MILLIS, + 'endDate': EARLIER_MILLIS, + } self.mock_session.get.assert_called_once_with( - self.make_url('/v1/marketdata/chains'), params={ - 'apikey': API_KEY, - 'symbol': 'AAPL', - 'range': 'ITM'}) + self.make_url('/marketdata/v1/pricehistory'), + params=params) - - def test_get_option_chain_strike_range_unchecked(self): - self.client.set_enforce_enums(False) - self.client.get_option_chain('AAPL', strike_range='ITM') - self.mock_session.get.assert_called_once_with( - self.make_url('/v1/marketdata/chains'), params={ - 'apikey': API_KEY, - 'symbol': 'AAPL', - 'range': 'ITM'}) - - def test_get_option_chain_from_date_datetime(self): - self.client.get_option_chain( - 'AAPL', from_date=NOW_DATETIME) - self.mock_session.get.assert_called_once_with( - self.make_url('/v1/marketdata/chains'), params={ - 'apikey': API_KEY, - 'symbol': 'AAPL', - 'fromDate': NOW_DATE_ISO}) - - - def test_get_option_chain_from_date_date(self): - self.client.get_option_chain('AAPL', from_date=NOW_DATE) + @patch('schwab.client.base.datetime.datetime', mockdatetime) + def test_get_price_history_every_minute_empty_extendedhours(self): + self.client.get_price_history_every_minute( + 'AAPL', need_extended_hours_data=None) + params = { + 'symbol': SYMBOL, + 'periodType': 'day', + # ONE_DAY + 'period': 1, + 'frequencyType': 'minute', + # EVERY_MINUTE + 'frequency': 1, + 'startDate': MIN_TIMESTAMP_MILLIS, + 'endDate': NOW_DATETIME_PLUS_SEVEN_DAYS_TIMESTAMP_MILLIS, + } self.mock_session.get.assert_called_once_with( - self.make_url('/v1/marketdata/chains'), params={ - 'apikey': API_KEY, - 'symbol': 'AAPL', - 'fromDate': NOW_DATE_ISO}) + self.make_url('/marketdata/v1/pricehistory'), + params=params) - - def test_get_option_chain_from_date_str(self): - with self.assertRaises(ValueError) as cm: - self.client.get_option_chain('AAPL', from_date='2020-01-01') - self.assertEqual(str(cm.exception), - "expected type in (datetime.date, datetime.datetime) for " + - "from_date, got 'builtins.str'") - - def test_get_option_chain_to_date_datetime(self): - self.client.get_option_chain('AAPL', to_date=NOW_DATETIME) + @patch('schwab.client.base.datetime.datetime', mockdatetime) + def test_get_price_history_every_minute_extendedhours(self): + self.client.get_price_history_every_minute( + 'AAPL', need_extended_hours_data=True) + params = { + 'symbol': SYMBOL, + 'periodType': 'day', + # ONE_DAY + 'period': 1, + 'frequencyType': 'minute', + # EVERY_MINUTE + 'frequency': 1, + 'startDate': MIN_TIMESTAMP_MILLIS, + 'endDate': NOW_DATETIME_PLUS_SEVEN_DAYS_TIMESTAMP_MILLIS, + 'needExtendedHoursData': True, + } self.mock_session.get.assert_called_once_with( - self.make_url('/v1/marketdata/chains'), params={ - 'apikey': API_KEY, - 'symbol': 'AAPL', - 'toDate': NOW_DATE_ISO}) + self.make_url('/marketdata/v1/pricehistory'), + params=params) - - def test_get_option_chain_to_date_date(self): - self.client.get_option_chain('AAPL', to_date=NOW_DATE) + @patch('schwab.client.base.datetime.datetime', mockdatetime) + def test_get_price_history_every_minute_empty_previous_close(self): + self.client.get_price_history_every_minute( + 'AAPL', need_previous_close=None) + params = { + 'symbol': SYMBOL, + 'periodType': 'day', + # ONE_DAY + 'period': 1, + 'frequencyType': 'minute', + # EVERY_MINUTE + 'frequency': 1, + 'startDate': MIN_TIMESTAMP_MILLIS, + 'endDate': NOW_DATETIME_PLUS_SEVEN_DAYS_TIMESTAMP_MILLIS, + } self.mock_session.get.assert_called_once_with( - self.make_url('/v1/marketdata/chains'), params={ - 'apikey': API_KEY, - 'symbol': 'AAPL', - 'toDate': NOW_DATE_ISO}) + self.make_url('/marketdata/v1/pricehistory'), + params=params) - - def test_get_option_chain_to_date_str(self): - with self.assertRaises(ValueError) as cm: - self.client.get_option_chain('AAPL', to_date='2020-01-01') - self.assertEqual(str(cm.exception), - "expected type in (datetime.date, datetime.datetime) for " + - "to_date, got 'builtins.str'") - - def test_get_option_chain_volatility(self): - self.client.get_option_chain('AAPL', volatility=40.0) + @patch('schwab.client.base.datetime.datetime', mockdatetime) + def test_get_price_history_every_minute_previous_close(self): + self.client.get_price_history_every_minute( + 'AAPL', need_previous_close=True) + params = { + 'symbol': SYMBOL, + 'periodType': 'day', + # ONE_DAY + 'period': 1, + 'frequencyType': 'minute', + # EVERY_MINUTE + 'frequency': 1, + 'startDate': MIN_TIMESTAMP_MILLIS, + 'endDate': NOW_DATETIME_PLUS_SEVEN_DAYS_TIMESTAMP_MILLIS, + 'needPreviousClose': True, + } self.mock_session.get.assert_called_once_with( - self.make_url('/v1/marketdata/chains'), params={ - 'apikey': API_KEY, - 'symbol': 'AAPL', - 'volatility': 40.0}) + self.make_url('/marketdata/v1/pricehistory'), + params=params) - - def test_get_option_chain_underlying_price(self): - self.client.get_option_chain('AAPL', underlying_price=234.0) - self.mock_session.get.assert_called_once_with( - self.make_url('/v1/marketdata/chains'), params={ - 'apikey': API_KEY, - 'symbol': 'AAPL', - 'underlyingPrice': 234.0}) - - def test_get_option_chain_interest_rate(self): - self.client.get_option_chain('AAPL', interest_rate=0.07) - self.mock_session.get.assert_called_once_with( - self.make_url('/v1/marketdata/chains'), params={ - 'apikey': API_KEY, - 'symbol': 'AAPL', - 'interestRate': 0.07}) - - def test_get_option_chain_days_to_expiration(self): - self.client.get_option_chain('AAPL', days_to_expiration=12) - self.mock_session.get.assert_called_once_with( - self.make_url('/v1/marketdata/chains'), params={ - 'apikey': API_KEY, - 'symbol': 'AAPL', - 'daysToExpiration': 12}) + # get_price_history_every_five_minutes - - def test_get_option_chain_exp_month(self): - self.client.get_option_chain( - 'AAPL', exp_month=self.client_class.Options.ExpirationMonth.JANUARY) - self.mock_session.get.assert_called_once_with( - self.make_url('/v1/marketdata/chains'), params={ - 'apikey': API_KEY, - 'symbol': 'AAPL', - 'expMonth': 'JAN'}) - - def test_get_option_chain_exp_month_unchecked(self): - self.client.set_enforce_enums(False) - self.client.get_option_chain('AAPL', exp_month='JAN') + @patch('schwab.client.base.datetime.datetime', mockdatetime) + def test_get_price_history_every_five_minutes_vanilla(self): + self.client.get_price_history_every_five_minutes('AAPL') + params = { + 'symbol': SYMBOL, + 'periodType': 'day', + # ONE_DAY + 'period': 1, + 'frequencyType': 'minute', + # EVERY_FIVE_MINUTES + 'frequency': 5, + 'startDate': MIN_TIMESTAMP_MILLIS, + 'endDate': NOW_DATETIME_PLUS_SEVEN_DAYS_TIMESTAMP_MILLIS, + } self.mock_session.get.assert_called_once_with( - self.make_url('/v1/marketdata/chains'), params={ - 'apikey': API_KEY, - 'symbol': 'AAPL', - 'expMonth': 'JAN'}) + self.make_url('/marketdata/v1/pricehistory'), + params=params) - - def test_get_option_chain_option_type(self): - self.client.get_option_chain( - 'AAPL', option_type=self.client_class.Options.Type.STANDARD) - self.mock_session.get.assert_called_once_with( - self.make_url('/v1/marketdata/chains'), params={ - 'apikey': API_KEY, - 'symbol': 'AAPL', - 'optionType': 'S'}) - - def test_get_option_chain_option_type_unchecked(self): - self.client.set_enforce_enums(False) - self.client.get_option_chain('AAPL', option_type='S') + @patch('schwab.client.base.datetime.datetime', mockdatetime) + def test_get_price_history_every_five_minutes_start_datetime(self): + self.client.get_price_history_every_five_minutes( + 'AAPL', start_datetime=EARLIER_DATETIME) + params = { + 'symbol': SYMBOL, + 'periodType': 'day', + # ONE_DAY + 'period': 1, + 'frequencyType': 'minute', + # EVERY_FIVE_MINUTES + 'frequency': 5, + 'startDate': EARLIER_MILLIS, + 'endDate': NOW_DATETIME_PLUS_SEVEN_DAYS_TIMESTAMP_MILLIS, + } self.mock_session.get.assert_called_once_with( - self.make_url('/v1/marketdata/chains'), params={ - 'apikey': API_KEY, - 'symbol': 'AAPL', - 'optionType': 'S'}) - ''' - - # get_price_history + self.make_url('/marketdata/v1/pricehistory'), + params=params) - - def test_get_price_history_vanilla(self): - self.client.get_price_history(SYMBOL) - self.mock_session.get.assert_called_once_with( - self.make_url('/marketdata/v1/pricehistory'), params={ - 'symbol': SYMBOL}) - - def test_get_price_history_period_type(self): - self.client.get_price_history( - SYMBOL, period_type=self.client_class.PriceHistory.PeriodType.MONTH) - self.mock_session.get.assert_called_once_with( - self.make_url('/marketdata/v1/pricehistory'), params={ + @patch('schwab.client.base.datetime.datetime', mockdatetime) + def test_get_price_history_every_five_minutes_end_datetime(self): + self.client.get_price_history_every_five_minutes( + 'AAPL', end_datetime=EARLIER_DATETIME) + params = { 'symbol': SYMBOL, - 'periodType': 'month'}) - - - def test_get_price_history_period_type_unchecked(self): - self.client.set_enforce_enums(False) - self.client.get_price_history(SYMBOL, period_type='month') + 'periodType': 'day', + # ONE_DAY + 'period': 1, + 'frequencyType': 'minute', + # EVERY_FIVE_MINUTES + 'frequency': 5, + 'startDate': MIN_TIMESTAMP_MILLIS, + 'endDate': EARLIER_MILLIS, + } self.mock_session.get.assert_called_once_with( - self.make_url('/marketdata/v1/pricehistory'), params={ - 'symbol': SYMBOL, - 'periodType': 'month'}) + self.make_url('/marketdata/v1/pricehistory'), + params=params) - - def test_get_price_history_num_periods(self): - self.client.get_price_history( - SYMBOL, period=self.client_class.PriceHistory.Period.TEN_DAYS) - self.mock_session.get.assert_called_once_with( - self.make_url('/marketdata/v1/pricehistory'), params={ - 'symbol': SYMBOL, - 'period': 10}) - - def test_get_price_history_num_periods_unchecked(self): - self.client.set_enforce_enums(False) - self.client.get_price_history(SYMBOL, period=10) - self.mock_session.get.assert_called_once_with( - self.make_url('/marketdata/v1/pricehistory'), params={ - 'symbol': SYMBOL, - 'period': 10}) - - - def test_get_price_history_frequency_type(self): - self.client.get_price_history( - SYMBOL, - frequency_type=self.client_class.PriceHistory.FrequencyType.DAILY) - self.mock_session.get.assert_called_once_with( - self.make_url('/marketdata/v1/pricehistory'), params={ - 'symbol': SYMBOL, - 'frequencyType': 'daily'}) - - - def test_get_price_history_frequency_type_unchecked(self): - self.client.set_enforce_enums(False) - self.client.get_price_history(SYMBOL, frequency_type='daily') - self.mock_session.get.assert_called_once_with( - self.make_url('/marketdata/v1/pricehistory'), params={ + @patch('schwab.client.base.datetime.datetime', mockdatetime) + def test_get_price_history_every_five_minutes_empty_extendedhours(self): + self.client.get_price_history_every_five_minutes( + 'AAPL', need_extended_hours_data=None) + params = { 'symbol': SYMBOL, - 'frequencyType': 'daily'}) - - - def test_get_price_history_frequency(self): - self.client.get_price_history( - SYMBOL, - frequency=self.client_class.PriceHistory.Frequency.EVERY_FIVE_MINUTES) + 'periodType': 'day', + # ONE_DAY + 'period': 1, + 'frequencyType': 'minute', + # EVERY_FIVE_MINUTES + 'frequency': 5, + 'startDate': MIN_TIMESTAMP_MILLIS, + 'endDate': NOW_DATETIME_PLUS_SEVEN_DAYS_TIMESTAMP_MILLIS, + } self.mock_session.get.assert_called_once_with( - self.make_url('/marketdata/v1/pricehistory'), params={ - 'symbol': SYMBOL, - 'frequency': 5}) + self.make_url('/marketdata/v1/pricehistory'), + params=params) - def test_get_price_history_frequency_unchecked(self): - self.client.set_enforce_enums(False) - self.client.get_price_history(SYMBOL, frequency=5) - self.mock_session.get.assert_called_once_with( - self.make_url('/marketdata/v1/pricehistory'), params={ + @patch('schwab.client.base.datetime.datetime', mockdatetime) + def test_get_price_history_every_five_minutes_extendedhours(self): + self.client.get_price_history_every_five_minutes( + 'AAPL', need_extended_hours_data=True) + params = { 'symbol': SYMBOL, - 'frequency': 5}) - - - def test_get_price_history_start_datetime(self): - self.client.get_price_history( - SYMBOL, start_datetime=EARLIER_DATETIME) + 'periodType': 'day', + # ONE_DAY + 'period': 1, + 'frequencyType': 'minute', + # EVERY_FIVE_MINUTES + 'frequency': 5, + 'startDate': MIN_TIMESTAMP_MILLIS, + 'endDate': NOW_DATETIME_PLUS_SEVEN_DAYS_TIMESTAMP_MILLIS, + 'needExtendedHoursData': True, + } self.mock_session.get.assert_called_once_with( - self.make_url('/marketdata/v1/pricehistory'), params={ - 'symbol': SYMBOL, - 'startDate': EARLIER_MILLIS}) - - - def test_get_price_history_start_datetime_str(self): - with self.assertRaises(ValueError) as cm: - self.client.get_price_history(SYMBOL, start_datetime='2020-01-01') - self.assertEqual(str(cm.exception), - "expected type 'datetime.datetime' for " + - "start_datetime, got 'builtins.str'") + self.make_url('/marketdata/v1/pricehistory'), + params=params) - - def test_get_price_history_end_datetime(self): - self.client.get_price_history(SYMBOL, end_datetime=EARLIER_DATETIME) - self.mock_session.get.assert_called_once_with( - self.make_url('/marketdata/v1/pricehistory'), params={ + @patch('schwab.client.base.datetime.datetime', mockdatetime) + def test_get_price_history_every_five_minutes_empty_previous_close(self): + self.client.get_price_history_every_five_minutes( + 'AAPL', need_previous_close=None) + params = { 'symbol': SYMBOL, - 'endDate': EARLIER_MILLIS}) - - - def test_get_price_history_end_datetime_str(self): - with self.assertRaises(ValueError) as cm: - self.client.get_price_history(SYMBOL, end_datetime='2020-01-01') - self.assertEqual(str(cm.exception), - "expected type 'datetime.datetime' for " + - "end_datetime, got 'builtins.str'") - - - def test_get_price_history_need_extended_hours_data(self): - self.client.get_price_history(SYMBOL, need_extended_hours_data=True) + 'periodType': 'day', + # ONE_DAY + 'period': 1, + 'frequencyType': 'minute', + # EVERY_FIVE_MINUTES + 'frequency': 5, + 'startDate': MIN_TIMESTAMP_MILLIS, + 'endDate': NOW_DATETIME_PLUS_SEVEN_DAYS_TIMESTAMP_MILLIS, + } self.mock_session.get.assert_called_once_with( - self.make_url('/marketdata/v1/pricehistory'), params={ - 'symbol': SYMBOL, - 'needExtendedHoursData': True}) + self.make_url('/marketdata/v1/pricehistory'), + params=params) - def test_get_price_history_need_previous_close(self): - self.client.get_price_history(SYMBOL, need_previous_close=True) - self.mock_session.get.assert_called_once_with( - self.make_url('/marketdata/v1/pricehistory'), params={ + @patch('schwab.client.base.datetime.datetime', mockdatetime) + def test_get_price_history_every_five_minutes_previous_close(self): + self.client.get_price_history_every_five_minutes( + 'AAPL', need_previous_close=True) + params = { 'symbol': SYMBOL, - 'needPreviousClose': True}) + 'periodType': 'day', + # ONE_DAY + 'period': 1, + 'frequencyType': 'minute', + # EVERY_FIVE_MINUTES + 'frequency': 5, + 'startDate': MIN_TIMESTAMP_MILLIS, + 'endDate': NOW_DATETIME_PLUS_SEVEN_DAYS_TIMESTAMP_MILLIS, + 'needPreviousClose': True, + } + self.mock_session.get.assert_called_once_with( + self.make_url('/marketdata/v1/pricehistory'), + params=params) - # get_price_history_every_minute + # get_price_history_every_ten_minutes @patch('schwab.client.base.datetime.datetime', mockdatetime) - def test_get_price_history_every_minute_vanilla(self): - self.client.get_price_history_every_minute('AAPL') + def test_get_price_history_every_ten_minutes_vanilla(self): + self.client.get_price_history_every_ten_minutes('AAPL') params = { - 'symbol': 'AAPL', + 'symbol': SYMBOL, 'periodType': 'day', # ONE_DAY 'period': 1, 'frequencyType': 'minute', - # EVERY_MINUTE - 'frequency': 1, + # EVERY_TEN_MINUTES + 'frequency': 10, 'startDate': MIN_TIMESTAMP_MILLIS, 'endDate': NOW_DATETIME_PLUS_SEVEN_DAYS_TIMESTAMP_MILLIS, } @@ -1117,8 +846,8 @@ def test_get_price_history_every_minute_vanilla(self): @patch('schwab.client.base.datetime.datetime', mockdatetime) - def test_get_price_history_every_minute_start_datetime(self): - self.client.get_price_history_every_minute( + def test_get_price_history_every_ten_minutes_start_datetime(self): + self.client.get_price_history_every_ten_minutes( 'AAPL', start_datetime=EARLIER_DATETIME) params = { 'symbol': SYMBOL, @@ -1126,8 +855,8 @@ def test_get_price_history_every_minute_start_datetime(self): # ONE_DAY 'period': 1, 'frequencyType': 'minute', - # EVERY_MINUTE - 'frequency': 1, + # EVERY_TEN_MINUTES + 'frequency': 10, 'startDate': EARLIER_MILLIS, 'endDate': NOW_DATETIME_PLUS_SEVEN_DAYS_TIMESTAMP_MILLIS, } @@ -1137,8 +866,8 @@ def test_get_price_history_every_minute_start_datetime(self): @patch('schwab.client.base.datetime.datetime', mockdatetime) - def test_get_price_history_every_minute_end_datetime(self): - self.client.get_price_history_every_minute( + def test_get_price_history_every_ten_minutes_end_datetime(self): + self.client.get_price_history_every_ten_minutes( 'AAPL', end_datetime=EARLIER_DATETIME) params = { 'symbol': SYMBOL, @@ -1146,8 +875,8 @@ def test_get_price_history_every_minute_end_datetime(self): # ONE_DAY 'period': 1, 'frequencyType': 'minute', - # EVERY_MINUTE - 'frequency': 1, + # EVERY_TEN_MINUTES + 'frequency': 10, 'startDate': MIN_TIMESTAMP_MILLIS, 'endDate': EARLIER_MILLIS, } @@ -1157,8 +886,8 @@ def test_get_price_history_every_minute_end_datetime(self): @patch('schwab.client.base.datetime.datetime', mockdatetime) - def test_get_price_history_every_minute_empty_extendedhours(self): - self.client.get_price_history_every_minute( + def test_get_price_history_every_ten_minutes_empty_extendedhours(self): + self.client.get_price_history_every_ten_minutes( 'AAPL', need_extended_hours_data=None) params = { 'symbol': SYMBOL, @@ -1166,8 +895,8 @@ def test_get_price_history_every_minute_empty_extendedhours(self): # ONE_DAY 'period': 1, 'frequencyType': 'minute', - # EVERY_MINUTE - 'frequency': 1, + # EVERY_TEN_MINUTES + 'frequency': 10, 'startDate': MIN_TIMESTAMP_MILLIS, 'endDate': NOW_DATETIME_PLUS_SEVEN_DAYS_TIMESTAMP_MILLIS, } @@ -1177,8 +906,8 @@ def test_get_price_history_every_minute_empty_extendedhours(self): @patch('schwab.client.base.datetime.datetime', mockdatetime) - def test_get_price_history_every_minute_extendedhours(self): - self.client.get_price_history_every_minute( + def test_get_price_history_every_ten_minutes_extendedhours(self): + self.client.get_price_history_every_ten_minutes( 'AAPL', need_extended_hours_data=True) params = { 'symbol': SYMBOL, @@ -1186,8 +915,8 @@ def test_get_price_history_every_minute_extendedhours(self): # ONE_DAY 'period': 1, 'frequencyType': 'minute', - # EVERY_MINUTE - 'frequency': 1, + # EVERY_TEN_MINUTES + 'frequency': 10, 'startDate': MIN_TIMESTAMP_MILLIS, 'endDate': NOW_DATETIME_PLUS_SEVEN_DAYS_TIMESTAMP_MILLIS, 'needExtendedHoursData': True, @@ -1197,8 +926,8 @@ def test_get_price_history_every_minute_extendedhours(self): params=params) @patch('schwab.client.base.datetime.datetime', mockdatetime) - def test_get_price_history_every_minute_empty_previous_close(self): - self.client.get_price_history_every_minute( + def test_get_price_history_every_ten_minutes_empty_previous_close(self): + self.client.get_price_history_every_ten_minutes( 'AAPL', need_previous_close=None) params = { 'symbol': SYMBOL, @@ -1206,8 +935,8 @@ def test_get_price_history_every_minute_empty_previous_close(self): # ONE_DAY 'period': 1, 'frequencyType': 'minute', - # EVERY_MINUTE - 'frequency': 1, + # EVERY_TEN_MINUTES + 'frequency': 10, 'startDate': MIN_TIMESTAMP_MILLIS, 'endDate': NOW_DATETIME_PLUS_SEVEN_DAYS_TIMESTAMP_MILLIS, } @@ -1217,8 +946,8 @@ def test_get_price_history_every_minute_empty_previous_close(self): @patch('schwab.client.base.datetime.datetime', mockdatetime) - def test_get_price_history_every_minute_previous_close(self): - self.client.get_price_history_every_minute( + def test_get_price_history_every_ten_minutes_previous_close(self): + self.client.get_price_history_every_ten_minutes( 'AAPL', need_previous_close=True) params = { 'symbol': SYMBOL, @@ -1226,8 +955,8 @@ def test_get_price_history_every_minute_previous_close(self): # ONE_DAY 'period': 1, 'frequencyType': 'minute', - # EVERY_MINUTE - 'frequency': 1, + # EVERY_TEN_MINUTES + 'frequency': 10, 'startDate': MIN_TIMESTAMP_MILLIS, 'endDate': NOW_DATETIME_PLUS_SEVEN_DAYS_TIMESTAMP_MILLIS, 'needPreviousClose': True, @@ -1237,21 +966,20 @@ def test_get_price_history_every_minute_previous_close(self): params=params) - - # get_price_history_every_five_minutes + # get_price_history_every_fifteen_minutes @patch('schwab.client.base.datetime.datetime', mockdatetime) - def test_get_price_history_every_five_minutes_vanilla(self): - self.client.get_price_history_every_five_minutes('AAPL') + def test_get_price_history_every_fifteen_minutes_vanilla(self): + self.client.get_price_history_every_fifteen_minutes('AAPL') params = { 'symbol': SYMBOL, 'periodType': 'day', # ONE_DAY 'period': 1, 'frequencyType': 'minute', - # EVERY_FIVE_MINUTES - 'frequency': 5, + # EVERY_FIFTEEN_MINUTES + 'frequency': 15, 'startDate': MIN_TIMESTAMP_MILLIS, 'endDate': NOW_DATETIME_PLUS_SEVEN_DAYS_TIMESTAMP_MILLIS, } @@ -1261,8 +989,8 @@ def test_get_price_history_every_five_minutes_vanilla(self): @patch('schwab.client.base.datetime.datetime', mockdatetime) - def test_get_price_history_every_five_minutes_start_datetime(self): - self.client.get_price_history_every_five_minutes( + def test_get_price_history_every_fifteen_minutes_start_datetime(self): + self.client.get_price_history_every_fifteen_minutes( 'AAPL', start_datetime=EARLIER_DATETIME) params = { 'symbol': SYMBOL, @@ -1270,8 +998,8 @@ def test_get_price_history_every_five_minutes_start_datetime(self): # ONE_DAY 'period': 1, 'frequencyType': 'minute', - # EVERY_FIVE_MINUTES - 'frequency': 5, + # EVERY_FIFTEEN_MINUTES + 'frequency': 15, 'startDate': EARLIER_MILLIS, 'endDate': NOW_DATETIME_PLUS_SEVEN_DAYS_TIMESTAMP_MILLIS, } @@ -1281,8 +1009,8 @@ def test_get_price_history_every_five_minutes_start_datetime(self): @patch('schwab.client.base.datetime.datetime', mockdatetime) - def test_get_price_history_every_five_minutes_end_datetime(self): - self.client.get_price_history_every_five_minutes( + def test_get_price_history_every_fifteen_minutes_end_datetime(self): + self.client.get_price_history_every_fifteen_minutes( 'AAPL', end_datetime=EARLIER_DATETIME) params = { 'symbol': SYMBOL, @@ -1290,8 +1018,8 @@ def test_get_price_history_every_five_minutes_end_datetime(self): # ONE_DAY 'period': 1, 'frequencyType': 'minute', - # EVERY_FIVE_MINUTES - 'frequency': 5, + # EVERY_FIFTEEN_MINUTES + 'frequency': 15, 'startDate': MIN_TIMESTAMP_MILLIS, 'endDate': EARLIER_MILLIS, } @@ -1301,8 +1029,8 @@ def test_get_price_history_every_five_minutes_end_datetime(self): @patch('schwab.client.base.datetime.datetime', mockdatetime) - def test_get_price_history_every_five_minutes_empty_extendedhours(self): - self.client.get_price_history_every_five_minutes( + def test_get_price_history_every_fifteen_minutes_empty_extendedhours(self): + self.client.get_price_history_every_fifteen_minutes( 'AAPL', need_extended_hours_data=None) params = { 'symbol': SYMBOL, @@ -1310,8 +1038,8 @@ def test_get_price_history_every_five_minutes_empty_extendedhours(self): # ONE_DAY 'period': 1, 'frequencyType': 'minute', - # EVERY_FIVE_MINUTES - 'frequency': 5, + # EVERY_FIFTEEN_MINUTES + 'frequency': 15, 'startDate': MIN_TIMESTAMP_MILLIS, 'endDate': NOW_DATETIME_PLUS_SEVEN_DAYS_TIMESTAMP_MILLIS, } @@ -1321,8 +1049,8 @@ def test_get_price_history_every_five_minutes_empty_extendedhours(self): @patch('schwab.client.base.datetime.datetime', mockdatetime) - def test_get_price_history_every_five_minutes_extendedhours(self): - self.client.get_price_history_every_five_minutes( + def test_get_price_history_every_fifteen_minutes_extendedhours(self): + self.client.get_price_history_every_fifteen_minutes( 'AAPL', need_extended_hours_data=True) params = { 'symbol': SYMBOL, @@ -1330,8 +1058,8 @@ def test_get_price_history_every_five_minutes_extendedhours(self): # ONE_DAY 'period': 1, 'frequencyType': 'minute', - # EVERY_FIVE_MINUTES - 'frequency': 5, + # EVERY_FIFTEEN_MINUTES + 'frequency': 15, 'startDate': MIN_TIMESTAMP_MILLIS, 'endDate': NOW_DATETIME_PLUS_SEVEN_DAYS_TIMESTAMP_MILLIS, 'needExtendedHoursData': True, @@ -1341,8 +1069,8 @@ def test_get_price_history_every_five_minutes_extendedhours(self): params=params) @patch('schwab.client.base.datetime.datetime', mockdatetime) - def test_get_price_history_every_five_minutes_empty_previous_close(self): - self.client.get_price_history_every_five_minutes( + def test_get_price_history_every_fifteen_minutes_empty_previous_close(self): + self.client.get_price_history_every_fifteen_minutes( 'AAPL', need_previous_close=None) params = { 'symbol': SYMBOL, @@ -1350,8 +1078,8 @@ def test_get_price_history_every_five_minutes_empty_previous_close(self): # ONE_DAY 'period': 1, 'frequencyType': 'minute', - # EVERY_FIVE_MINUTES - 'frequency': 5, + # EVERY_FIFTEEN_MINUTES + 'frequency': 15, 'startDate': MIN_TIMESTAMP_MILLIS, 'endDate': NOW_DATETIME_PLUS_SEVEN_DAYS_TIMESTAMP_MILLIS, } @@ -1361,8 +1089,8 @@ def test_get_price_history_every_five_minutes_empty_previous_close(self): @patch('schwab.client.base.datetime.datetime', mockdatetime) - def test_get_price_history_every_five_minutes_previous_close(self): - self.client.get_price_history_every_five_minutes( + def test_get_price_history_every_fifteen_minutes_previous_close(self): + self.client.get_price_history_every_fifteen_minutes( 'AAPL', need_previous_close=True) params = { 'symbol': SYMBOL, @@ -1370,8 +1098,8 @@ def test_get_price_history_every_five_minutes_previous_close(self): # ONE_DAY 'period': 1, 'frequencyType': 'minute', - # EVERY_FIVE_MINUTES - 'frequency': 5, + # EVERY_FIFTEEN_MINUTES + 'frequency': 15, 'startDate': MIN_TIMESTAMP_MILLIS, 'endDate': NOW_DATETIME_PLUS_SEVEN_DAYS_TIMESTAMP_MILLIS, 'needPreviousClose': True, @@ -1381,20 +1109,20 @@ def test_get_price_history_every_five_minutes_previous_close(self): params=params) - # get_price_history_every_ten_minutes + # get_price_history_every_thirty_minutes @patch('schwab.client.base.datetime.datetime', mockdatetime) - def test_get_price_history_every_ten_minutes_vanilla(self): - self.client.get_price_history_every_ten_minutes('AAPL') + def test_get_price_history_every_thirty_minutes_vanilla(self): + self.client.get_price_history_every_thirty_minutes('AAPL') params = { 'symbol': SYMBOL, 'periodType': 'day', # ONE_DAY 'period': 1, 'frequencyType': 'minute', - # EVERY_TEN_MINUTES - 'frequency': 10, + # EVERY_THIRTY_MINUTES + 'frequency': 30, 'startDate': MIN_TIMESTAMP_MILLIS, 'endDate': NOW_DATETIME_PLUS_SEVEN_DAYS_TIMESTAMP_MILLIS, } @@ -1404,8 +1132,8 @@ def test_get_price_history_every_ten_minutes_vanilla(self): @patch('schwab.client.base.datetime.datetime', mockdatetime) - def test_get_price_history_every_ten_minutes_start_datetime(self): - self.client.get_price_history_every_ten_minutes( + def test_get_price_history_every_thirty_minutes_start_datetime(self): + self.client.get_price_history_every_thirty_minutes( 'AAPL', start_datetime=EARLIER_DATETIME) params = { 'symbol': SYMBOL, @@ -1413,8 +1141,8 @@ def test_get_price_history_every_ten_minutes_start_datetime(self): # ONE_DAY 'period': 1, 'frequencyType': 'minute', - # EVERY_TEN_MINUTES - 'frequency': 10, + # EVERY_THIRTY_MINUTES + 'frequency': 30, 'startDate': EARLIER_MILLIS, 'endDate': NOW_DATETIME_PLUS_SEVEN_DAYS_TIMESTAMP_MILLIS, } @@ -1424,8 +1152,8 @@ def test_get_price_history_every_ten_minutes_start_datetime(self): @patch('schwab.client.base.datetime.datetime', mockdatetime) - def test_get_price_history_every_ten_minutes_end_datetime(self): - self.client.get_price_history_every_ten_minutes( + def test_get_price_history_every_thirty_minutes_end_datetime(self): + self.client.get_price_history_every_thirty_minutes( 'AAPL', end_datetime=EARLIER_DATETIME) params = { 'symbol': SYMBOL, @@ -1433,8 +1161,8 @@ def test_get_price_history_every_ten_minutes_end_datetime(self): # ONE_DAY 'period': 1, 'frequencyType': 'minute', - # EVERY_TEN_MINUTES - 'frequency': 10, + # EVERY_THIRTY_MINUTES + 'frequency': 30, 'startDate': MIN_TIMESTAMP_MILLIS, 'endDate': EARLIER_MILLIS, } @@ -1444,8 +1172,8 @@ def test_get_price_history_every_ten_minutes_end_datetime(self): @patch('schwab.client.base.datetime.datetime', mockdatetime) - def test_get_price_history_every_ten_minutes_empty_extendedhours(self): - self.client.get_price_history_every_ten_minutes( + def test_get_price_history_every_thirty_minutes_empty_extendedhours(self): + self.client.get_price_history_every_thirty_minutes( 'AAPL', need_extended_hours_data=None) params = { 'symbol': SYMBOL, @@ -1453,8 +1181,8 @@ def test_get_price_history_every_ten_minutes_empty_extendedhours(self): # ONE_DAY 'period': 1, 'frequencyType': 'minute', - # EVERY_TEN_MINUTES - 'frequency': 10, + # EVERY_THIRTY_MINUTES + 'frequency': 30, 'startDate': MIN_TIMESTAMP_MILLIS, 'endDate': NOW_DATETIME_PLUS_SEVEN_DAYS_TIMESTAMP_MILLIS, } @@ -1464,8 +1192,8 @@ def test_get_price_history_every_ten_minutes_empty_extendedhours(self): @patch('schwab.client.base.datetime.datetime', mockdatetime) - def test_get_price_history_every_ten_minutes_extendedhours(self): - self.client.get_price_history_every_ten_minutes( + def test_get_price_history_every_thirty_minutes_extendedhours(self): + self.client.get_price_history_every_thirty_minutes( 'AAPL', need_extended_hours_data=True) params = { 'symbol': SYMBOL, @@ -1473,8 +1201,8 @@ def test_get_price_history_every_ten_minutes_extendedhours(self): # ONE_DAY 'period': 1, 'frequencyType': 'minute', - # EVERY_TEN_MINUTES - 'frequency': 10, + # EVERY_THIRTY_MINUTES + 'frequency': 30, 'startDate': MIN_TIMESTAMP_MILLIS, 'endDate': NOW_DATETIME_PLUS_SEVEN_DAYS_TIMESTAMP_MILLIS, 'needExtendedHoursData': True, @@ -1484,8 +1212,8 @@ def test_get_price_history_every_ten_minutes_extendedhours(self): params=params) @patch('schwab.client.base.datetime.datetime', mockdatetime) - def test_get_price_history_every_ten_minutes_empty_previous_close(self): - self.client.get_price_history_every_ten_minutes( + def test_get_price_history_every_thirty_minutes_empty_previous_close(self): + self.client.get_price_history_every_thirty_minutes( 'AAPL', need_previous_close=None) params = { 'symbol': SYMBOL, @@ -1493,8 +1221,8 @@ def test_get_price_history_every_ten_minutes_empty_previous_close(self): # ONE_DAY 'period': 1, 'frequencyType': 'minute', - # EVERY_TEN_MINUTES - 'frequency': 10, + # EVERY_THIRTY_MINUTES + 'frequency': 30, 'startDate': MIN_TIMESTAMP_MILLIS, 'endDate': NOW_DATETIME_PLUS_SEVEN_DAYS_TIMESTAMP_MILLIS, } @@ -1504,8 +1232,8 @@ def test_get_price_history_every_ten_minutes_empty_previous_close(self): @patch('schwab.client.base.datetime.datetime', mockdatetime) - def test_get_price_history_every_ten_minutes_previous_close(self): - self.client.get_price_history_every_ten_minutes( + def test_get_price_history_every_thirty_minutes_previous_close(self): + self.client.get_price_history_every_thirty_minutes( 'AAPL', need_previous_close=True) params = { 'symbol': SYMBOL, @@ -1513,8 +1241,8 @@ def test_get_price_history_every_ten_minutes_previous_close(self): # ONE_DAY 'period': 1, 'frequencyType': 'minute', - # EVERY_TEN_MINUTES - 'frequency': 10, + # EVERY_THIRTY_MINUTES + 'frequency': 30, 'startDate': MIN_TIMESTAMP_MILLIS, 'endDate': NOW_DATETIME_PLUS_SEVEN_DAYS_TIMESTAMP_MILLIS, 'needPreviousClose': True, @@ -1524,20 +1252,20 @@ def test_get_price_history_every_ten_minutes_previous_close(self): params=params) - # get_price_history_every_fifteen_minutes + # get_price_history_every_day @patch('schwab.client.base.datetime.datetime', mockdatetime) - def test_get_price_history_every_fifteen_minutes_vanilla(self): - self.client.get_price_history_every_fifteen_minutes('AAPL') + def test_get_price_history_every_day_vanilla(self): + self.client.get_price_history_every_day('AAPL') params = { 'symbol': SYMBOL, - 'periodType': 'day', - # ONE_DAY - 'period': 1, - 'frequencyType': 'minute', - # EVERY_FIFTEEN_MINUTES - 'frequency': 15, + 'periodType': 'year', + # TWENTY_YEARS + 'period': 20, + 'frequencyType': 'daily', + # DAILY + 'frequency': 1, 'startDate': MIN_TIMESTAMP_MILLIS, 'endDate': NOW_DATETIME_PLUS_SEVEN_DAYS_TIMESTAMP_MILLIS, } @@ -1547,17 +1275,17 @@ def test_get_price_history_every_fifteen_minutes_vanilla(self): @patch('schwab.client.base.datetime.datetime', mockdatetime) - def test_get_price_history_every_fifteen_minutes_start_datetime(self): - self.client.get_price_history_every_fifteen_minutes( + def test_get_price_history_every_day_start_datetime(self): + self.client.get_price_history_every_day( 'AAPL', start_datetime=EARLIER_DATETIME) params = { 'symbol': SYMBOL, - 'periodType': 'day', - # ONE_DAY - 'period': 1, - 'frequencyType': 'minute', - # EVERY_FIFTEEN_MINUTES - 'frequency': 15, + 'periodType': 'year', + # TWENTY_YEARS + 'period': 20, + 'frequencyType': 'daily', + # DAILY + 'frequency': 1, 'startDate': EARLIER_MILLIS, 'endDate': NOW_DATETIME_PLUS_SEVEN_DAYS_TIMESTAMP_MILLIS, } @@ -1567,17 +1295,17 @@ def test_get_price_history_every_fifteen_minutes_start_datetime(self): @patch('schwab.client.base.datetime.datetime', mockdatetime) - def test_get_price_history_every_fifteen_minutes_end_datetime(self): - self.client.get_price_history_every_fifteen_minutes( + def test_get_price_history_every_day_end_datetime(self): + self.client.get_price_history_every_day( 'AAPL', end_datetime=EARLIER_DATETIME) params = { 'symbol': SYMBOL, - 'periodType': 'day', - # ONE_DAY - 'period': 1, - 'frequencyType': 'minute', - # EVERY_FIFTEEN_MINUTES - 'frequency': 15, + 'periodType': 'year', + # TWENTY_YEARS + 'period': 20, + 'frequencyType': 'daily', + # DAILY + 'frequency': 1, 'startDate': MIN_TIMESTAMP_MILLIS, 'endDate': EARLIER_MILLIS, } @@ -1587,17 +1315,17 @@ def test_get_price_history_every_fifteen_minutes_end_datetime(self): @patch('schwab.client.base.datetime.datetime', mockdatetime) - def test_get_price_history_every_fifteen_minutes_empty_extendedhours(self): - self.client.get_price_history_every_fifteen_minutes( + def test_get_price_history_every_day_empty_extendedhours(self): + self.client.get_price_history_every_day( 'AAPL', need_extended_hours_data=None) params = { 'symbol': SYMBOL, - 'periodType': 'day', - # ONE_DAY - 'period': 1, - 'frequencyType': 'minute', - # EVERY_FIFTEEN_MINUTES - 'frequency': 15, + 'periodType': 'year', + # TWENTY_YEARS + 'period': 20, + 'frequencyType': 'daily', + # DAILY + 'frequency': 1, 'startDate': MIN_TIMESTAMP_MILLIS, 'endDate': NOW_DATETIME_PLUS_SEVEN_DAYS_TIMESTAMP_MILLIS, } @@ -1607,17 +1335,17 @@ def test_get_price_history_every_fifteen_minutes_empty_extendedhours(self): @patch('schwab.client.base.datetime.datetime', mockdatetime) - def test_get_price_history_every_fifteen_minutes_extendedhours(self): - self.client.get_price_history_every_fifteen_minutes( + def test_get_price_history_every_day_extendedhours(self): + self.client.get_price_history_every_day( 'AAPL', need_extended_hours_data=True) params = { 'symbol': SYMBOL, - 'periodType': 'day', - # ONE_DAY - 'period': 1, - 'frequencyType': 'minute', - # EVERY_FIFTEEN_MINUTES - 'frequency': 15, + 'periodType': 'year', + # TWENTY_YEARS + 'period': 20, + 'frequencyType': 'daily', + # DAILY + 'frequency': 1, 'startDate': MIN_TIMESTAMP_MILLIS, 'endDate': NOW_DATETIME_PLUS_SEVEN_DAYS_TIMESTAMP_MILLIS, 'needExtendedHoursData': True, @@ -1627,17 +1355,17 @@ def test_get_price_history_every_fifteen_minutes_extendedhours(self): params=params) @patch('schwab.client.base.datetime.datetime', mockdatetime) - def test_get_price_history_every_fifteen_minutes_empty_previous_close(self): - self.client.get_price_history_every_fifteen_minutes( + def test_get_price_history_every_day_empty_previous_close(self): + self.client.get_price_history_every_day( 'AAPL', need_previous_close=None) params = { 'symbol': SYMBOL, - 'periodType': 'day', - # ONE_DAY - 'period': 1, - 'frequencyType': 'minute', - # EVERY_FIFTEEN_MINUTES - 'frequency': 15, + 'periodType': 'year', + # TWENTY_YEARS + 'period': 20, + 'frequencyType': 'daily', + # DAILY + 'frequency': 1, 'startDate': MIN_TIMESTAMP_MILLIS, 'endDate': NOW_DATETIME_PLUS_SEVEN_DAYS_TIMESTAMP_MILLIS, } @@ -1647,17 +1375,17 @@ def test_get_price_history_every_fifteen_minutes_empty_previous_close(self): @patch('schwab.client.base.datetime.datetime', mockdatetime) - def test_get_price_history_every_fifteen_minutes_previous_close(self): - self.client.get_price_history_every_fifteen_minutes( + def test_get_price_history_every_day_previous_close(self): + self.client.get_price_history_every_day( 'AAPL', need_previous_close=True) params = { 'symbol': SYMBOL, - 'periodType': 'day', - # ONE_DAY - 'period': 1, - 'frequencyType': 'minute', - # EVERY_FIFTEEN_MINUTES - 'frequency': 15, + 'periodType': 'year', + # TWENTY_YEARS + 'period': 20, + 'frequencyType': 'daily', + # DAILY + 'frequency': 1, 'startDate': MIN_TIMESTAMP_MILLIS, 'endDate': NOW_DATETIME_PLUS_SEVEN_DAYS_TIMESTAMP_MILLIS, 'needPreviousClose': True, @@ -1667,20 +1395,20 @@ def test_get_price_history_every_fifteen_minutes_previous_close(self): params=params) - # get_price_history_every_thirty_minutes + # get_price_history_every_week @patch('schwab.client.base.datetime.datetime', mockdatetime) - def test_get_price_history_every_thirty_minutes_vanilla(self): - self.client.get_price_history_every_thirty_minutes('AAPL') + def test_get_price_history_every_week_vanilla(self): + self.client.get_price_history_every_week('AAPL') params = { 'symbol': SYMBOL, - 'periodType': 'day', - # ONE_DAY - 'period': 1, - 'frequencyType': 'minute', - # EVERY_THIRTY_MINUTES - 'frequency': 30, + 'periodType': 'year', + # TWENTY_YEARS + 'period': 20, + 'frequencyType': 'weekly', + # DAILY + 'frequency': 1, 'startDate': MIN_TIMESTAMP_MILLIS, 'endDate': NOW_DATETIME_PLUS_SEVEN_DAYS_TIMESTAMP_MILLIS, } @@ -1690,17 +1418,17 @@ def test_get_price_history_every_thirty_minutes_vanilla(self): @patch('schwab.client.base.datetime.datetime', mockdatetime) - def test_get_price_history_every_thirty_minutes_start_datetime(self): - self.client.get_price_history_every_thirty_minutes( + def test_get_price_history_every_week_start_datetime(self): + self.client.get_price_history_every_week( 'AAPL', start_datetime=EARLIER_DATETIME) params = { 'symbol': SYMBOL, - 'periodType': 'day', - # ONE_DAY - 'period': 1, - 'frequencyType': 'minute', - # EVERY_THIRTY_MINUTES - 'frequency': 30, + 'periodType': 'year', + # TWENTY_YEARS + 'period': 20, + 'frequencyType': 'weekly', + # DAILY + 'frequency': 1, 'startDate': EARLIER_MILLIS, 'endDate': NOW_DATETIME_PLUS_SEVEN_DAYS_TIMESTAMP_MILLIS, } @@ -1710,17 +1438,17 @@ def test_get_price_history_every_thirty_minutes_start_datetime(self): @patch('schwab.client.base.datetime.datetime', mockdatetime) - def test_get_price_history_every_thirty_minutes_end_datetime(self): - self.client.get_price_history_every_thirty_minutes( + def test_get_price_history_every_week_end_datetime(self): + self.client.get_price_history_every_week( 'AAPL', end_datetime=EARLIER_DATETIME) params = { 'symbol': SYMBOL, - 'periodType': 'day', - # ONE_DAY - 'period': 1, - 'frequencyType': 'minute', - # EVERY_THIRTY_MINUTES - 'frequency': 30, + 'periodType': 'year', + # TWENTY_YEARS + 'period': 20, + 'frequencyType': 'weekly', + # DAILY + 'frequency': 1, 'startDate': MIN_TIMESTAMP_MILLIS, 'endDate': EARLIER_MILLIS, } @@ -1730,17 +1458,17 @@ def test_get_price_history_every_thirty_minutes_end_datetime(self): @patch('schwab.client.base.datetime.datetime', mockdatetime) - def test_get_price_history_every_thirty_minutes_empty_extendedhours(self): - self.client.get_price_history_every_thirty_minutes( + def test_get_price_history_every_week_empty_extendedhours(self): + self.client.get_price_history_every_week( 'AAPL', need_extended_hours_data=None) params = { 'symbol': SYMBOL, - 'periodType': 'day', - # ONE_DAY - 'period': 1, - 'frequencyType': 'minute', - # EVERY_THIRTY_MINUTES - 'frequency': 30, + 'periodType': 'year', + # TWENTY_YEARS + 'period': 20, + 'frequencyType': 'weekly', + # DAILY + 'frequency': 1, 'startDate': MIN_TIMESTAMP_MILLIS, 'endDate': NOW_DATETIME_PLUS_SEVEN_DAYS_TIMESTAMP_MILLIS, } @@ -1750,158 +1478,15 @@ def test_get_price_history_every_thirty_minutes_empty_extendedhours(self): @patch('schwab.client.base.datetime.datetime', mockdatetime) - def test_get_price_history_every_thirty_minutes_extendedhours(self): - self.client.get_price_history_every_thirty_minutes( - 'AAPL', need_extended_hours_data=True) - params = { - 'symbol': SYMBOL, - 'periodType': 'day', - # ONE_DAY - 'period': 1, - 'frequencyType': 'minute', - # EVERY_THIRTY_MINUTES - 'frequency': 30, - 'startDate': MIN_TIMESTAMP_MILLIS, - 'endDate': NOW_DATETIME_PLUS_SEVEN_DAYS_TIMESTAMP_MILLIS, - 'needExtendedHoursData': True, - } - self.mock_session.get.assert_called_once_with( - self.make_url('/marketdata/v1/pricehistory'), - params=params) - - @patch('schwab.client.base.datetime.datetime', mockdatetime) - def test_get_price_history_every_thirty_minutes_empty_previous_close(self): - self.client.get_price_history_every_thirty_minutes( - 'AAPL', need_previous_close=None) - params = { - 'symbol': SYMBOL, - 'periodType': 'day', - # ONE_DAY - 'period': 1, - 'frequencyType': 'minute', - # EVERY_THIRTY_MINUTES - 'frequency': 30, - 'startDate': MIN_TIMESTAMP_MILLIS, - 'endDate': NOW_DATETIME_PLUS_SEVEN_DAYS_TIMESTAMP_MILLIS, - } - self.mock_session.get.assert_called_once_with( - self.make_url('/marketdata/v1/pricehistory'), - params=params) - - - @patch('schwab.client.base.datetime.datetime', mockdatetime) - def test_get_price_history_every_thirty_minutes_previous_close(self): - self.client.get_price_history_every_thirty_minutes( - 'AAPL', need_previous_close=True) - params = { - 'symbol': SYMBOL, - 'periodType': 'day', - # ONE_DAY - 'period': 1, - 'frequencyType': 'minute', - # EVERY_THIRTY_MINUTES - 'frequency': 30, - 'startDate': MIN_TIMESTAMP_MILLIS, - 'endDate': NOW_DATETIME_PLUS_SEVEN_DAYS_TIMESTAMP_MILLIS, - 'needPreviousClose': True, - } - self.mock_session.get.assert_called_once_with( - self.make_url('/marketdata/v1/pricehistory'), - params=params) - - - # get_price_history_every_day - - - @patch('schwab.client.base.datetime.datetime', mockdatetime) - def test_get_price_history_every_day_vanilla(self): - self.client.get_price_history_every_day('AAPL') - params = { - 'symbol': SYMBOL, - 'periodType': 'year', - # TWENTY_YEARS - 'period': 20, - 'frequencyType': 'daily', - # DAILY - 'frequency': 1, - 'startDate': MIN_TIMESTAMP_MILLIS, - 'endDate': NOW_DATETIME_PLUS_SEVEN_DAYS_TIMESTAMP_MILLIS, - } - self.mock_session.get.assert_called_once_with( - self.make_url('/marketdata/v1/pricehistory'), - params=params) - - - @patch('schwab.client.base.datetime.datetime', mockdatetime) - def test_get_price_history_every_day_start_datetime(self): - self.client.get_price_history_every_day( - 'AAPL', start_datetime=EARLIER_DATETIME) - params = { - 'symbol': SYMBOL, - 'periodType': 'year', - # TWENTY_YEARS - 'period': 20, - 'frequencyType': 'daily', - # DAILY - 'frequency': 1, - 'startDate': EARLIER_MILLIS, - 'endDate': NOW_DATETIME_PLUS_SEVEN_DAYS_TIMESTAMP_MILLIS, - } - self.mock_session.get.assert_called_once_with( - self.make_url('/marketdata/v1/pricehistory'), - params=params) - - - @patch('schwab.client.base.datetime.datetime', mockdatetime) - def test_get_price_history_every_day_end_datetime(self): - self.client.get_price_history_every_day( - 'AAPL', end_datetime=EARLIER_DATETIME) - params = { - 'symbol': SYMBOL, - 'periodType': 'year', - # TWENTY_YEARS - 'period': 20, - 'frequencyType': 'daily', - # DAILY - 'frequency': 1, - 'startDate': MIN_TIMESTAMP_MILLIS, - 'endDate': EARLIER_MILLIS, - } - self.mock_session.get.assert_called_once_with( - self.make_url('/marketdata/v1/pricehistory'), - params=params) - - - @patch('schwab.client.base.datetime.datetime', mockdatetime) - def test_get_price_history_every_day_empty_extendedhours(self): - self.client.get_price_history_every_day( - 'AAPL', need_extended_hours_data=None) - params = { - 'symbol': SYMBOL, - 'periodType': 'year', - # TWENTY_YEARS - 'period': 20, - 'frequencyType': 'daily', - # DAILY - 'frequency': 1, - 'startDate': MIN_TIMESTAMP_MILLIS, - 'endDate': NOW_DATETIME_PLUS_SEVEN_DAYS_TIMESTAMP_MILLIS, - } - self.mock_session.get.assert_called_once_with( - self.make_url('/marketdata/v1/pricehistory'), - params=params) - - - @patch('schwab.client.base.datetime.datetime', mockdatetime) - def test_get_price_history_every_day_extendedhours(self): - self.client.get_price_history_every_day( + def test_get_price_history_every_week_extendedhours(self): + self.client.get_price_history_every_week( 'AAPL', need_extended_hours_data=True) params = { 'symbol': SYMBOL, 'periodType': 'year', # TWENTY_YEARS 'period': 20, - 'frequencyType': 'daily', + 'frequencyType': 'weekly', # DAILY 'frequency': 1, 'startDate': MIN_TIMESTAMP_MILLIS, @@ -1913,15 +1498,15 @@ def test_get_price_history_every_day_extendedhours(self): params=params) @patch('schwab.client.base.datetime.datetime', mockdatetime) - def test_get_price_history_every_day_empty_previous_close(self): - self.client.get_price_history_every_day( + def test_get_price_history_every_week_empty_previous_close(self): + self.client.get_price_history_every_week( 'AAPL', need_previous_close=None) params = { 'symbol': SYMBOL, 'periodType': 'year', # TWENTY_YEARS 'period': 20, - 'frequencyType': 'daily', + 'frequencyType': 'weekly', # DAILY 'frequency': 1, 'startDate': MIN_TIMESTAMP_MILLIS, @@ -1933,15 +1518,15 @@ def test_get_price_history_every_day_empty_previous_close(self): @patch('schwab.client.base.datetime.datetime', mockdatetime) - def test_get_price_history_every_day_previous_close(self): - self.client.get_price_history_every_day( + def test_get_price_history_every_week_previous_close(self): + self.client.get_price_history_every_week( 'AAPL', need_previous_close=True) params = { 'symbol': SYMBOL, 'periodType': 'year', # TWENTY_YEARS 'period': 20, - 'frequencyType': 'daily', + 'frequencyType': 'weekly', # DAILY 'frequency': 1, 'startDate': MIN_TIMESTAMP_MILLIS, @@ -1953,148 +1538,680 @@ def test_get_price_history_every_day_previous_close(self): params=params) - # get_price_history_every_week + ''' + # place_order + + def test_place_order(self): + order_spec = {'order': 'spec'} + self.client.place_order(ACCOUNT_HASH, order_spec) + self.mock_session.post.assert_called_once_with( + self.make_url('/v1/accounts/{accountHash}/orders'), json=order_spec) - @patch('schwab.client.base.datetime.datetime', mockdatetime) - def test_get_price_history_every_week_vanilla(self): - self.client.get_price_history_every_week('AAPL') - params = { - 'symbol': SYMBOL, - 'periodType': 'year', - # TWENTY_YEARS - 'period': 20, - 'frequencyType': 'weekly', - # DAILY - 'frequency': 1, - 'startDate': MIN_TIMESTAMP_MILLIS, - 'endDate': NOW_DATETIME_PLUS_SEVEN_DAYS_TIMESTAMP_MILLIS, - } - self.mock_session.get.assert_called_once_with( - self.make_url('/marketdata/v1/pricehistory'), - params=params) + + def test_place_order_order_builder(self): + order_spec = OrderBuilder(enforce_enums=False).set_order_type('LIMIT') + expected_spec = {'orderType': 'LIMIT'} + self.client.place_order(ACCOUNT_HASH, order_spec) + self.mock_session.post.assert_called_once_with( + self.make_url('/v1/accounts/{accountHash}/orders'), + json=expected_spec) + + def test_place_order_str(self): + order_spec = {'order': 'spec'} + self.client.place_order(str(ACCOUNT_HASH), order_spec) + self.mock_session.post.assert_called_once_with( + self.make_url('/v1/accounts/{accountHash}/orders'), json=order_spec) - @patch('schwab.client.base.datetime.datetime', mockdatetime) - def test_get_price_history_every_week_start_datetime(self): - self.client.get_price_history_every_week( - 'AAPL', start_datetime=EARLIER_DATETIME) - params = { - 'symbol': SYMBOL, - 'periodType': 'year', - # TWENTY_YEARS - 'period': 20, - 'frequencyType': 'weekly', - # DAILY - 'frequency': 1, - 'startDate': EARLIER_MILLIS, - 'endDate': NOW_DATETIME_PLUS_SEVEN_DAYS_TIMESTAMP_MILLIS, - } - self.mock_session.get.assert_called_once_with( - self.make_url('/marketdata/v1/pricehistory'), - params=params) + # replace_order + + def test_replace_order(self): + order_spec = {'order': 'spec'} + self.client.replace_order(ACCOUNT_HASH, ORDER_ID, order_spec) + self.mock_session.put.assert_called_once_with( + self.make_url('/v1/accounts/{accountHash}/orders/{orderId}'), + json=order_spec) - @patch('schwab.client.base.datetime.datetime', mockdatetime) - def test_get_price_history_every_week_end_datetime(self): - self.client.get_price_history_every_week( - 'AAPL', end_datetime=EARLIER_DATETIME) - params = { - 'symbol': SYMBOL, - 'periodType': 'year', - # TWENTY_YEARS - 'period': 20, - 'frequencyType': 'weekly', - # DAILY - 'frequency': 1, - 'startDate': MIN_TIMESTAMP_MILLIS, - 'endDate': EARLIER_MILLIS, - } - self.mock_session.get.assert_called_once_with( - self.make_url('/marketdata/v1/pricehistory'), - params=params) + + def test_replace_order_order_builder(self): + order_spec = OrderBuilder(enforce_enums=False).set_order_type('LIMIT') + expected_spec = {'orderType': 'LIMIT'} + self.client.replace_order(ACCOUNT_HASH, ORDER_ID, order_spec) + self.mock_session.put.assert_called_once_with( + self.make_url('/v1/accounts/{accountHash}/orders/{orderId}'), + json=expected_spec) + + def test_replace_order_str(self): + order_spec = {'order': 'spec'} + self.client.replace_order(str(ACCOUNT_HASH), str(ORDER_ID), order_spec) + self.mock_session.put.assert_called_once_with( + self.make_url('/v1/accounts/{accountHash}/orders/{orderId}'), + json=order_spec) - @patch('schwab.client.base.datetime.datetime', mockdatetime) - def test_get_price_history_every_week_empty_extendedhours(self): - self.client.get_price_history_every_week( - 'AAPL', need_extended_hours_data=None) - params = { - 'symbol': SYMBOL, - 'periodType': 'year', - # TWENTY_YEARS - 'period': 20, - 'frequencyType': 'weekly', - # DAILY - 'frequency': 1, - 'startDate': MIN_TIMESTAMP_MILLIS, - 'endDate': NOW_DATETIME_PLUS_SEVEN_DAYS_TIMESTAMP_MILLIS, - } + # create_saved_order + + + def test_create_saved_order(self): + order_spec = {'order': 'spec'} + self.client.create_saved_order(ACCOUNT_HASH, order_spec) + self.mock_session.post.assert_called_once_with( + self.make_url('/v1/accounts/{accountHash}/savedorders'), + json=order_spec) + + + def test_create_saved_order_order_builder(self): + order_spec = OrderBuilder(enforce_enums=False).set_order_type('LIMIT') + expected_spec = {'orderType': 'LIMIT'} + self.client.create_saved_order(ACCOUNT_HASH, order_spec) + self.mock_session.post.assert_called_once_with( + self.make_url('/v1/accounts/{accountHash}/savedorders'), + json=expected_spec) + + + def test_create_saved_order_str(self): + order_spec = {'order': 'spec'} + self.client.create_saved_order(str(ACCOUNT_HASH), order_spec) + self.mock_session.post.assert_called_once_with( + self.make_url('/v1/accounts/{accountHash}/savedorders'), + json=order_spec) + + # delete_saved_order + + + def test_delete_saved_order(self): + self.client.delete_saved_order(ACCOUNT_HASH, SAVED_ORDER_ID) + self.mock_session.delete.assert_called_once_with( + self.make_url('/v1/accounts/{accountHash}/savedorders/{savedOrderId}')) + + + def test_delete_saved_order_str(self): + self.client.delete_saved_order(str(ACCOUNT_HASH), str(SAVED_ORDER_ID)) + self.mock_session.delete.assert_called_once_with( + self.make_url('/v1/accounts/{accountHash}/savedorders/{savedOrderId}')) + + # delete_saved_order + + + def test_get_saved_order(self): + self.client.get_saved_order(ACCOUNT_HASH, SAVED_ORDER_ID) self.mock_session.get.assert_called_once_with( - self.make_url('/marketdata/v1/pricehistory'), - params=params) + self.make_url( + '/v1/accounts/{accountHash}/savedorders/{savedOrderId}'), + params={}) + + def test_get_saved_order_str(self): + self.client.get_saved_order(str(ACCOUNT_HASH), str(SAVED_ORDER_ID)) + self.mock_session.get.assert_called_once_with( + self.make_url( + '/v1/accounts/{accountHash}/savedorders/{savedOrderId}'), + params={}) + + # get_saved_orders_by_path + + + def test_get_saved_orders_by_path(self): + self.client.get_saved_orders_by_path(ACCOUNT_HASH) + self.mock_session.get.assert_called_once_with( + self.make_url('/v1/accounts/{accountHash}/savedorders'), params={}) + + + def test_get_saved_orders_by_path_str(self): + self.client.get_saved_orders_by_path(str(ACCOUNT_HASH)) + self.mock_session.get.assert_called_once_with( + self.make_url('/v1/accounts/{accountHash}/savedorders'), params={}) + + # replace_saved_order + + + def test_replace_saved_order(self): + order_spec = {'order': 'spec'} + self.client.replace_saved_order(ACCOUNT_HASH, SAVED_ORDER_ID, order_spec) + self.mock_session.put.assert_called_once_with( + self.make_url( + '/v1/accounts/{accountHash}/savedorders/{savedOrderId}'), + json=order_spec) + + def test_replace_saved_order_order_builder(self): + order_spec = OrderBuilder(enforce_enums=False).set_order_type('LIMIT') + expected_spec = {'orderType': 'LIMIT'} + self.client.replace_saved_order(ACCOUNT_HASH, SAVED_ORDER_ID, order_spec) + self.mock_session.put.assert_called_once_with( + self.make_url( + '/v1/accounts/{accountHash}/savedorders/{savedOrderId}'), + json=expected_spec) + + + def test_replace_saved_order_str(self): + order_spec = {'order': 'spec'} + self.client.replace_saved_order( + str(ACCOUNT_HASH), str(SAVED_ORDER_ID), order_spec) + self.mock_session.put.assert_called_once_with( + self.make_url( + '/v1/accounts/{accountHash}/savedorders/{savedOrderId}'), + json=order_spec) + ''' + + ''' + + + # get_orders_by_query + + @patch('schwab.client.base.datetime.datetime', mockdatetime) - def test_get_price_history_every_week_extendedhours(self): - self.client.get_price_history_every_week( - 'AAPL', need_extended_hours_data=True) - params = { - 'symbol': SYMBOL, - 'periodType': 'year', - # TWENTY_YEARS - 'period': 20, - 'frequencyType': 'weekly', - # DAILY - 'frequency': 1, - 'startDate': MIN_TIMESTAMP_MILLIS, - 'endDate': NOW_DATETIME_PLUS_SEVEN_DAYS_TIMESTAMP_MILLIS, - 'needExtendedHoursData': True, - } + def test_get_orders_by_query_vanilla(self): + self.client.get_orders_by_query() self.mock_session.get.assert_called_once_with( - self.make_url('/marketdata/v1/pricehistory'), - params=params) + self.make_url('/v1/orders'), params={ + 'fromEnteredTime': MIN_ISO, + 'toEnteredTime': NOW_DATETIME_ISO + }) + @patch('schwab.client.base.datetime.datetime', mockdatetime) - def test_get_price_history_every_week_empty_previous_close(self): - self.client.get_price_history_every_week( - 'AAPL', need_previous_close=None) - params = { - 'symbol': SYMBOL, - 'periodType': 'year', - # TWENTY_YEARS - 'period': 20, - 'frequencyType': 'weekly', - # DAILY - 'frequency': 1, - 'startDate': MIN_TIMESTAMP_MILLIS, - 'endDate': NOW_DATETIME_PLUS_SEVEN_DAYS_TIMESTAMP_MILLIS, - } + def test_get_orders_by_query_max_results(self): + self.client.get_orders_by_query(max_results=100) self.mock_session.get.assert_called_once_with( - self.make_url('/marketdata/v1/pricehistory'), - params=params) + self.make_url('/v1/orders'), params={ + 'fromEnteredTime': MIN_ISO, + 'toEnteredTime': NOW_DATETIME_ISO, + 'maxResults': 100, + }) + + @patch('schwab.client.base.datetime.datetime', mockdatetime) + def test_get_orders_by_query_from_entered_datetime(self): + self.client.get_orders_by_query(from_entered_datetime=EARLIER_DATETIME) + self.mock_session.get.assert_called_once_with( + self.make_url('/v1/orders'), params={ + 'fromEnteredTime': EARLIER_ISO, + 'toEnteredTime': NOW_DATETIME_ISO, + }) + @patch('schwab.client.base.datetime.datetime', mockdatetime) - def test_get_price_history_every_week_previous_close(self): - self.client.get_price_history_every_week( - 'AAPL', need_previous_close=True) - params = { - 'symbol': SYMBOL, - 'periodType': 'year', - # TWENTY_YEARS - 'period': 20, - 'frequencyType': 'weekly', - # DAILY - 'frequency': 1, - 'startDate': MIN_TIMESTAMP_MILLIS, - 'endDate': NOW_DATETIME_PLUS_SEVEN_DAYS_TIMESTAMP_MILLIS, - 'needPreviousClose': True, - } + def test_get_orders_by_query_to_entered_datetime(self): + self.client.get_orders_by_query(to_entered_datetime=EARLIER_DATETIME) self.mock_session.get.assert_called_once_with( - self.make_url('/marketdata/v1/pricehistory'), - params=params) + self.make_url('/v1/orders'), params={ + 'fromEnteredTime': MIN_ISO, + 'toEnteredTime': EARLIER_ISO, + }) + + + @patch('schwab.client.base.datetime.datetime', mockdatetime) + def test_get_orders_by_query_status_and_statuses(self): + with self.assertRaises( + ValueError, msg='at most one of status or statuses may be set'): + self.client.get_orders_by_query( + to_entered_datetime=EARLIER_DATETIME, + status='EXPIRED', statuses=[ + self.client_class.Order.Status.FILLED, + self.client_class.Order.Status.EXPIRED]) + + + @patch('schwab.client.base.datetime.datetime', mockdatetime) + def test_get_orders_by_query_status(self): + self.client.get_orders_by_query(status=self.client_class.Order.Status.FILLED) + self.mock_session.get.assert_called_once_with( + self.make_url('/v1/orders'), params={ + 'fromEnteredTime': MIN_ISO, + 'toEnteredTime': NOW_DATETIME_ISO, + 'status': 'FILLED' + }) + + + @patch('schwab.client.base.datetime.datetime', mockdatetime) + def test_get_orders_by_query_status_unchecked(self): + self.client.set_enforce_enums(False) + self.client.get_orders_by_query(status='FILLED') + self.mock_session.get.assert_called_once_with( + self.make_url('/v1/orders'), params={ + 'fromEnteredTime': MIN_ISO, + 'toEnteredTime': NOW_DATETIME_ISO, + 'status': 'FILLED' + }) + + + @patch('schwab.client.base.datetime.datetime', mockdatetime) + def test_get_orders_by_query_statuses(self): + self.client.get_orders_by_query(statuses=[ + self.client_class.Order.Status.FILLED, + self.client_class.Order.Status.EXPIRED]) + self.mock_session.get.assert_called_once_with( + self.make_url('/v1/orders'), params={ + 'fromEnteredTime': MIN_ISO, + 'toEnteredTime': NOW_DATETIME_ISO, + 'status': 'FILLED,EXPIRED' + }) + + + @patch('schwab.client.base.datetime.datetime', mockdatetime) + def test_get_orders_by_query_statuses_scalar(self): + self.client.get_orders_by_query(statuses=self.client_class.Order.Status.FILLED) + self.mock_session.get.assert_called_once_with( + self.make_url('/v1/orders'), params={ + 'fromEnteredTime': MIN_ISO, + 'toEnteredTime': NOW_DATETIME_ISO, + 'status': 'FILLED' + }) + + + @patch('schwab.client.base.datetime.datetime', mockdatetime) + def test_get_orders_by_query_statuses_unchecked(self): + self.client.set_enforce_enums(False) + self.client.get_orders_by_query(statuses=['FILLED', 'EXPIRED']) + self.mock_session.get.assert_called_once_with( + self.make_url('/v1/orders'), params={ + 'fromEnteredTime': MIN_ISO, + 'toEnteredTime': NOW_DATETIME_ISO, + 'status': 'FILLED,EXPIRED' + }) + + ''' + + ''' + # search_instruments + + + def test_search_instruments(self): + self.client.search_instruments( + ['AAPL', 'MSFT'], self.client_class.Instrument.Projection.FUNDAMENTAL) + self.mock_session.get.assert_called_once_with( + self.make_url('/v1/instruments'), params={ + 'apikey': API_KEY, + 'symbol': 'AAPL,MSFT', + 'projection': 'fundamental'}) + + + def test_search_instruments_one_instrument(self): + self.client.search_instruments( + 'AAPL', self.client_class.Instrument.Projection.FUNDAMENTAL) + self.mock_session.get.assert_called_once_with( + self.make_url('/v1/instruments'), params={ + 'apikey': API_KEY, + 'symbol': 'AAPL', + 'projection': 'fundamental'}) + + def test_search_instruments_unchecked(self): + self.client.set_enforce_enums(False) + self.client.search_instruments(['AAPL', 'MSFT'], 'fundamental') + self.mock_session.get.assert_called_once_with( + self.make_url('/v1/instruments'), params={ + 'apikey': API_KEY, + 'symbol': 'AAPL,MSFT', + 'projection': 'fundamental'}) + + # get_instrument + + + def test_get_instrument(self): + self.client.get_instrument(CUSIP) + self.mock_session.get.assert_called_once_with( + self.make_url('/v1/instruments/{cusip}'), + params={'apikey': API_KEY}) + + + def test_get_instrument_cusip_must_be_string(self): + msg = 'CUSIPs must be passed as strings to preserve leading zeroes' + with self.assertRaises(ValueError, msg=msg): + self.client.get_instrument(123456) + + # get_hours_for_multiple_markets + + + def test_get_hours_for_multiple_markets_datetime(self): + self.client.get_hours_for_multiple_markets([ + self.client_class.Markets.EQUITY, + self.client_class.Markets.BOND], NOW_DATETIME) + self.mock_session.get.assert_called_once_with( + self.make_url('/v1/marketdata/hours'), params={ + 'apikey': API_KEY, + 'markets': 'EQUITY,BOND', + 'date': NOW_DATE_ISO}) + + + def test_get_hours_for_multiple_markets_single_market(self): + self.client.get_hours_for_multiple_markets( + self.client_class.Markets.EQUITY, NOW_DATETIME) + self.mock_session.get.assert_called_once_with( + self.make_url('/v1/marketdata/hours'), params={ + 'apikey': API_KEY, + 'markets': 'EQUITY', + 'date': NOW_DATE_ISO}) + + + def test_get_hours_for_multiple_markets_date(self): + self.client.get_hours_for_multiple_markets([ + self.client_class.Markets.EQUITY, + self.client_class.Markets.BOND], NOW_DATE) + self.mock_session.get.assert_called_once_with( + self.make_url('/v1/marketdata/hours'), params={ + 'apikey': API_KEY, + 'markets': 'EQUITY,BOND', + 'date': NOW_DATE_ISO}) + + + def test_get_hours_for_multiple_markets_str(self): + with self.assertRaises(ValueError) as cm: + self.client.get_hours_for_multiple_markets([ + self.client_class.Markets.EQUITY, + self.client_class.Markets.BOND], '2020-01-01') + self.assertEqual(str(cm.exception), + "expected type in (datetime.date, datetime.datetime) " + "for date, got 'builtins.str'") + + + def test_get_hours_for_multiple_markets_unchecked(self): + self.client.set_enforce_enums(False) + self.client.get_hours_for_multiple_markets( + ['EQUITY', 'BOND'], NOW_DATETIME) + self.mock_session.get.assert_called_once_with( + self.make_url('/v1/marketdata/hours'), params={ + 'apikey': API_KEY, + 'markets': 'EQUITY,BOND', + 'date': NOW_DATE_ISO}) + + # get_hours_for_single_market + + + def test_get_hours_for_single_market_datetime(self): + self.client.get_hours_for_single_market( + self.client_class.Markets.EQUITY, NOW_DATETIME) + self.mock_session.get.assert_called_once_with( + self.make_url('/v1/marketdata/{market}/hours'), params={ + 'apikey': API_KEY, + 'date': NOW_DATE_ISO}) + + + def test_get_hours_for_single_market_date(self): + self.client.get_hours_for_single_market( + self.client_class.Markets.EQUITY, NOW_DATE) + self.mock_session.get.assert_called_once_with( + self.make_url('/v1/marketdata/{market}/hours'), params={ + 'apikey': API_KEY, + 'date': NOW_DATE_ISO}) + + + def test_get_hours_for_single_market_str(self): + with self.assertRaises(ValueError) as cm: + self.client.get_hours_for_single_market( + self.client_class.Markets.EQUITY, '2020-01-01') + self.assertEqual(str(cm.exception), + "expected type in (datetime.date, datetime.datetime) for " + + "date, got 'builtins.str'") + + + def test_get_hours_for_single_market_unchecked(self): + self.client.set_enforce_enums(False) + self.client.get_hours_for_single_market('EQUITY', NOW_DATETIME) + self.mock_session.get.assert_called_once_with( + self.make_url('/v1/marketdata/{market}/hours'), params={ + 'apikey': API_KEY, + 'date': NOW_DATE_ISO}) + + # get_movers + + + def test_get_movers(self): + self.client.get_movers( + INDEX, self.client_class.Movers.Direction.UP, self.client_class.Movers.Change.PERCENT) + self.mock_session.get.assert_called_once_with( + self.make_url('/v1/marketdata/{index}/movers'), params={ + 'apikey': API_KEY, + 'direction': 'up', + 'change': 'percent'}) + + + def test_get_movers_unchecked(self): + self.client.set_enforce_enums(False) + self.client.get_movers(INDEX, 'up', 'percent') + self.mock_session.get.assert_called_once_with( + self.make_url('/v1/marketdata/{index}/movers'), params={ + 'apikey': API_KEY, + 'direction': 'up', + 'change': 'percent'}) + + # get_option_chain + + + def test_get_option_chain_vanilla(self): + self.client.get_option_chain('AAPL') + self.mock_session.get.assert_called_once_with( + self.make_url('/v1/marketdata/chains'), params={ + 'apikey': API_KEY, + 'symbol': 'AAPL'}) + + + def test_get_option_chain_contract_type(self): + self.client.get_option_chain( + 'AAPL', contract_type=self.client_class.Options.ContractType.PUT) + self.mock_session.get.assert_called_once_with( + self.make_url('/v1/marketdata/chains'), params={ + 'apikey': API_KEY, + 'symbol': 'AAPL', + 'contractType': 'PUT'}) + + + def test_get_option_chain_contract_type_unchecked(self): + self.client.set_enforce_enums(False) + self.client.get_option_chain('AAPL', contract_type='PUT') + self.mock_session.get.assert_called_once_with( + self.make_url('/v1/marketdata/chains'), params={ + 'apikey': API_KEY, + 'symbol': 'AAPL', + 'contractType': 'PUT'}) + + + def test_get_option_chain_strike_count(self): + self.client.get_option_chain('AAPL', strike_count=100) + self.mock_session.get.assert_called_once_with( + self.make_url('/v1/marketdata/chains'), params={ + 'apikey': API_KEY, + 'symbol': 'AAPL', + 'strikeCount': 100}) + + + def test_get_option_chain_include_quotes(self): + self.client.get_option_chain('AAPL', include_quotes=True) + self.mock_session.get.assert_called_once_with( + self.make_url('/v1/marketdata/chains'), params={ + 'apikey': API_KEY, + 'symbol': 'AAPL', + 'includeQuotes': True}) + + + def test_get_option_chain_strategy(self): + self.client.get_option_chain( + 'AAPL', strategy=self.client_class.Options.Strategy.STRANGLE) + self.mock_session.get.assert_called_once_with( + self.make_url('/v1/marketdata/chains'), params={ + 'apikey': API_KEY, + 'symbol': 'AAPL', + 'strategy': 'STRANGLE'}) + + + def test_get_option_chain_strategy_unchecked(self): + self.client.set_enforce_enums(False) + self.client.get_option_chain('AAPL', strategy='STRANGLE') + self.mock_session.get.assert_called_once_with( + self.make_url('/v1/marketdata/chains'), params={ + 'apikey': API_KEY, + 'symbol': 'AAPL', + 'strategy': 'STRANGLE'}) + + + def test_get_option_chain_interval(self): + self.client.get_option_chain('AAPL', interval=10.0) + self.mock_session.get.assert_called_once_with( + self.make_url('/v1/marketdata/chains'), params={ + 'apikey': API_KEY, + 'symbol': 'AAPL', + 'interval': 10.0}) + + + def test_get_option_chain_strike(self): + self.client.get_option_chain('AAPL', strike=123) + self.mock_session.get.assert_called_once_with( + self.make_url('/v1/marketdata/chains'), params={ + 'apikey': API_KEY, + 'symbol': 'AAPL', + 'strike': 123}) + + + def test_get_option_chain_strike_range(self): + self.client.get_option_chain( + 'AAPL', strike_range=self.client_class.Options.StrikeRange.IN_THE_MONEY) + self.mock_session.get.assert_called_once_with( + self.make_url('/v1/marketdata/chains'), params={ + 'apikey': API_KEY, + 'symbol': 'AAPL', + 'range': 'ITM'}) + + + def test_get_option_chain_strike_range_unchecked(self): + self.client.set_enforce_enums(False) + self.client.get_option_chain('AAPL', strike_range='ITM') + self.mock_session.get.assert_called_once_with( + self.make_url('/v1/marketdata/chains'), params={ + 'apikey': API_KEY, + 'symbol': 'AAPL', + 'range': 'ITM'}) + + + def test_get_option_chain_from_date_datetime(self): + self.client.get_option_chain( + 'AAPL', from_date=NOW_DATETIME) + self.mock_session.get.assert_called_once_with( + self.make_url('/v1/marketdata/chains'), params={ + 'apikey': API_KEY, + 'symbol': 'AAPL', + 'fromDate': NOW_DATE_ISO}) + + + def test_get_option_chain_from_date_date(self): + self.client.get_option_chain('AAPL', from_date=NOW_DATE) + self.mock_session.get.assert_called_once_with( + self.make_url('/v1/marketdata/chains'), params={ + 'apikey': API_KEY, + 'symbol': 'AAPL', + 'fromDate': NOW_DATE_ISO}) + + + def test_get_option_chain_from_date_str(self): + with self.assertRaises(ValueError) as cm: + self.client.get_option_chain('AAPL', from_date='2020-01-01') + self.assertEqual(str(cm.exception), + "expected type in (datetime.date, datetime.datetime) for " + + "from_date, got 'builtins.str'") + + + def test_get_option_chain_to_date_datetime(self): + self.client.get_option_chain('AAPL', to_date=NOW_DATETIME) + self.mock_session.get.assert_called_once_with( + self.make_url('/v1/marketdata/chains'), params={ + 'apikey': API_KEY, + 'symbol': 'AAPL', + 'toDate': NOW_DATE_ISO}) + + + def test_get_option_chain_to_date_date(self): + self.client.get_option_chain('AAPL', to_date=NOW_DATE) + self.mock_session.get.assert_called_once_with( + self.make_url('/v1/marketdata/chains'), params={ + 'apikey': API_KEY, + 'symbol': 'AAPL', + 'toDate': NOW_DATE_ISO}) + + + def test_get_option_chain_to_date_str(self): + with self.assertRaises(ValueError) as cm: + self.client.get_option_chain('AAPL', to_date='2020-01-01') + self.assertEqual(str(cm.exception), + "expected type in (datetime.date, datetime.datetime) for " + + "to_date, got 'builtins.str'") + + + def test_get_option_chain_volatility(self): + self.client.get_option_chain('AAPL', volatility=40.0) + self.mock_session.get.assert_called_once_with( + self.make_url('/v1/marketdata/chains'), params={ + 'apikey': API_KEY, + 'symbol': 'AAPL', + 'volatility': 40.0}) + + + def test_get_option_chain_underlying_price(self): + self.client.get_option_chain('AAPL', underlying_price=234.0) + self.mock_session.get.assert_called_once_with( + self.make_url('/v1/marketdata/chains'), params={ + 'apikey': API_KEY, + 'symbol': 'AAPL', + 'underlyingPrice': 234.0}) + + + def test_get_option_chain_interest_rate(self): + self.client.get_option_chain('AAPL', interest_rate=0.07) + self.mock_session.get.assert_called_once_with( + self.make_url('/v1/marketdata/chains'), params={ + 'apikey': API_KEY, + 'symbol': 'AAPL', + 'interestRate': 0.07}) + + + def test_get_option_chain_days_to_expiration(self): + self.client.get_option_chain('AAPL', days_to_expiration=12) + self.mock_session.get.assert_called_once_with( + self.make_url('/v1/marketdata/chains'), params={ + 'apikey': API_KEY, + 'symbol': 'AAPL', + 'daysToExpiration': 12}) + + + def test_get_option_chain_exp_month(self): + self.client.get_option_chain( + 'AAPL', exp_month=self.client_class.Options.ExpirationMonth.JANUARY) + self.mock_session.get.assert_called_once_with( + self.make_url('/v1/marketdata/chains'), params={ + 'apikey': API_KEY, + 'symbol': 'AAPL', + 'expMonth': 'JAN'}) + + + def test_get_option_chain_exp_month_unchecked(self): + self.client.set_enforce_enums(False) + self.client.get_option_chain('AAPL', exp_month='JAN') + self.mock_session.get.assert_called_once_with( + self.make_url('/v1/marketdata/chains'), params={ + 'apikey': API_KEY, + 'symbol': 'AAPL', + 'expMonth': 'JAN'}) + + + def test_get_option_chain_option_type(self): + self.client.get_option_chain( + 'AAPL', option_type=self.client_class.Options.Type.STANDARD) + self.mock_session.get.assert_called_once_with( + self.make_url('/v1/marketdata/chains'), params={ + 'apikey': API_KEY, + 'symbol': 'AAPL', + 'optionType': 'S'}) + + + def test_get_option_chain_option_type_unchecked(self): + self.client.set_enforce_enums(False) + self.client.get_option_chain('AAPL', option_type='S') + self.mock_session.get.assert_called_once_with( + self.make_url('/v1/marketdata/chains'), params={ + 'apikey': API_KEY, + 'symbol': 'AAPL', + 'optionType': 'S'}) + ''' ''' # get_quote