From 3feb61470744a213abfb9d07d50c5df7d6cf7f14 Mon Sep 17 00:00:00 2001 From: Casey Jones Date: Sat, 23 Dec 2023 02:22:49 +0200 Subject: [PATCH] robinhood/orders: document market_hours, correspond with extendedHours add market_hours argument to relevant docstrings correct type hint for extendedHours from str to bool change market_hours to "extended_hours" if market hours unset and extendedHours is truthy --- robin_stocks/robinhood/orders.py | 81 ++++++++++++++++++-------------- 1 file changed, 45 insertions(+), 36 deletions(-) diff --git a/robin_stocks/robinhood/orders.py b/robin_stocks/robinhood/orders.py index 7e95d177..4a089f83 100644 --- a/robin_stocks/robinhood/orders.py +++ b/robin_stocks/robinhood/orders.py @@ -311,8 +311,8 @@ def order_buy_market(symbol, quantity, account_number=None, timeInForce='gtc', e :param timeInForce: Changes how long the order will be in effect for. 'gtc' = good until cancelled. \ 'gfd' = good for the day. :type timeInForce: Optional[str] - :param extendedHours: Premium users only. Allows trading during extended hours. Should be true or false. - :type extendedHours: Optional[str] + :param extendedHours: Premium users only. Allows trading during extended hours. + :type extendedHours: Optional[bool] :param jsonify: If set to False, function will return the request object which contains status code and headers. :type jsonify: Optional[str] :returns: Dictionary that contains information regarding the purchase of stocks, \ @@ -337,8 +337,8 @@ def order_buy_fractional_by_quantity(symbol, quantity, account_number=None, time :type account_number: Optional[str] :param timeInForce: Changes how long the order will be in effect for. 'gfd' = good for the day. :type timeInForce: Optional[str] - :param extendedHours: Premium users only. Allows trading during extended hours. Should be true or false. - :type extendedHours: Optional[str] + :param extendedHours: Premium users only. Allows trading during extended hours. + :type extendedHours: Optional[bool] :param jsonify: If set to False, function will return the request object which contains status code and headers. :type jsonify: Optional[str] :returns: Dictionary that contains information regarding the purchase of stocks, \ @@ -363,10 +363,12 @@ def order_buy_fractional_by_price(symbol, amountInDollars, account_number=None, :type account_number: Optional[str] :param timeInForce: Changes how long the order will be in effect for. 'gfd' = good for the day. :type timeInForce: Optional[str] - :param extendedHours: Premium users only. Allows trading during extended hours. Should be true or false. - :type extendedHours: Optional[str] + :param extendedHours: Premium users only. Allows trading during extended hours. + :type extendedHours: Optional[bool] :param jsonify: If set to False, function will return the request object which contains status code and headers. :type jsonify: Optional[str] + :param market_hours: Valid values are 'regular_hours', 'extended_hours' and 'all_day_hours'. + :type market_hours: Optional[str] :returns: Dictionary that contains information regarding the purchase of stocks, \ such as the order id, the state of order (queued, confired, filled, failed, canceled, etc.), \ the price, and the quantity. @@ -398,8 +400,8 @@ def order_buy_limit(symbol, quantity, limitPrice, account_number=None, timeInFor :param timeInForce: Changes how long the order will be in effect for. 'gtc' = good until cancelled. \ 'gfd' = good for the day. :type timeInForce: Optional[str] - :param extendedHours: Premium users only. Allows trading during extended hours. Should be true or false. - :type extendedHours: Optional[str] + :param extendedHours: Premium users only. Allows trading during extended hours. + :type extendedHours: Optional[bool] :param jsonify: If set to False, function will return the request object which contains status code and headers. :type jsonify: Optional[str] :returns: Dictionary that contains information regarding the purchase of stocks, \ @@ -425,8 +427,8 @@ def order_buy_stop_loss(symbol, quantity, stopPrice, account_number=None, timeIn :param timeInForce: Changes how long the order will be in effect for. 'gtc' = good until cancelled. \ 'gfd' = good for the day. :type timeInForce: Optional[str] - :param extendedHours: Premium users only. Allows trading during extended hours. Should be true or false. - :type extendedHours: Optional[str] + :param extendedHours: Premium users only. Allows trading during extended hours. + :type extendedHours: Optional[bool] :param jsonify: If set to False, function will return the request object which contains status code and headers. :type jsonify: Optional[str] :returns: Dictionary that contains information regarding the purchase of stocks, \ @@ -454,8 +456,8 @@ def order_buy_stop_limit(symbol, quantity, limitPrice, stopPrice, account_number :param timeInForce: Changes how long the order will be in effect for. 'gtc' = good until cancelled. \ 'gfd' = good for the day. :type timeInForce: Optional[str] - :param extendedHours: Premium users only. Allows trading during extended hours. Should be true or false. - :type extendedHours: Optional[str] + :param extendedHours: Premium users only. Allows trading during extended hours. + :type extendedHours: Optional[bool] :param jsonify: If set to False, function will return the request object which contains status code and headers. :type jsonify: Optional[str] :returns: Dictionary that contains information regarding the purchase of stocks, \ @@ -481,8 +483,8 @@ def order_buy_trailing_stop(symbol, quantity, trailAmount, trailType='percentage :param timeInForce: Changes how long the order will be in effect for. 'gtc' = good until cancelled. \ 'gfd' = good for the day. :type timeInForce: Optional[str] - :param extendedHours: Premium users only. Allows trading during extended hours. Should be true or false. - :type extendedHours: Optional[str] + :param extendedHours: Premium users only. Allows trading during extended hours. + :type extendedHours: Optional[bool] :param jsonify: If set to False, function will return the request object which contains status code and headers. :type jsonify: Optional[str] :returns: Dictionary that contains information regarding the selling of stocks, \ @@ -509,8 +511,8 @@ def order_sell_market(symbol, quantity, account_number=None, timeInForce='gtc', :param timeInForce: Changes how long the order will be in effect for. 'gtc' = good until cancelled. \ 'gfd' = good for the day. :type timeInForce: Optional[str] - :param extendedHours: Premium users only. Allows trading during extended hours. Should be true or false. - :type extendedHours: Optional[str] + :param extendedHours: Premium users only. Allows trading during extended hours. + :type extendedHours: Optional[bool] :param jsonify: If set to False, function will return the request object which contains status code and headers. :type jsonify: Optional[str] :returns: Dictionary that contains information regarding the selling of stocks, \ @@ -535,10 +537,12 @@ def order_sell_fractional_by_quantity(symbol, quantity, account_number=None, tim :type account_number: Optional[str] :param timeInForce: Changes how long the order will be in effect for. 'gfd' = good for the day. :type timeInForce: Optional[str] - :param extendedHours: Premium users only. Allows trading during extended hours. Should be true or false. - :type extendedHours: Optional[str] + :param extendedHours: Premium users only. Allows trading during extended hours. + :type extendedHours: Optional[bool] :param jsonify: If set to False, function will return the request object which contains status code and headers. :type jsonify: Optional[str] + :param market_hours: Valid values are 'regular_hours', 'extended_hours' and 'all_day_hours'. + :type market_hours: Optional[str] :returns: Dictionary that contains information regarding the purchase of stocks, \ such as the order id, the state of order (queued, confired, filled, failed, canceled, etc.), \ the price, and the quantity. @@ -561,8 +565,8 @@ def order_sell_fractional_by_price(symbol, amountInDollars, account_number=None, :type account_number: Optional[str] :param timeInForce: Changes how long the order will be in effect for. 'gfd' = good for the day. :type timeInForce: Optional[str] - :param extendedHours: Premium users only. Allows trading during extended hours. Should be true or false. - :type extendedHours: Optional[str] + :param extendedHours: Premium users only. Allows trading during extended hours. + :type extendedHours: Optional[bool] :param jsonify: If set to False, function will return the request object which contains status code and headers. :type jsonify: Optional[str] :returns: Dictionary that contains information regarding the purchase of stocks, \ @@ -595,8 +599,8 @@ def order_sell_limit(symbol, quantity, limitPrice, account_number=None, timeInFo :param timeInForce: Changes how long the order will be in effect for. 'gtc' = good until cancelled. \ 'gfd' = good for the day. :type timeInForce: Optional[str] - :param extendedHours: Premium users only. Allows trading during extended hours. Should be true or false. - :type extendedHours: Optional[str] + :param extendedHours: Premium users only. Allows trading during extended hours. + :type extendedHours: Optional[bool] :param jsonify: If set to False, function will return the request object which contains status code and headers. :type jsonify: Optional[str] :returns: Dictionary that contains information regarding the selling of stocks, \ @@ -622,8 +626,8 @@ def order_sell_stop_loss(symbol, quantity, stopPrice, account_number=None, timeI :param timeInForce: Changes how long the order will be in effect for. 'gtc' = good until cancelled. \ 'gfd' = good for the day. :type timeInForce: Optional[str] - :param extendedHours: Premium users only. Allows trading during extended hours. Should be true or false. - :type extendedHours: Optional[str] + :param extendedHours: Premium users only. Allows trading during extended hours. + :type extendedHours: Optional[bool] :param jsonify: If set to False, function will return the request object which contains status code and headers. :type jsonify: Optional[str] :returns: Dictionary that contains information regarding the selling of stocks, \ @@ -651,8 +655,8 @@ def order_sell_stop_limit(symbol, quantity, limitPrice, stopPrice, account_numbe :param timeInForce: Changes how long the order will be in effect for. 'gtc' = good until cancelled. \ 'gfd' = good for the day. :type timeInForce: Optional[str] - :param extendedHours: Premium users only. Allows trading during extended hours. Should be true or false. - :type extendedHours: Optional[str] + :param extendedHours: Premium users only. Allows trading during extended hours. + :type extendedHours: Optional[bool] :param jsonify: If set to False, function will return the request object which contains status code and headers. :type jsonify: Optional[str] :returns: Dictionary that contains information regarding the selling of stocks, \ @@ -678,8 +682,8 @@ def order_sell_trailing_stop(symbol, quantity, trailAmount, trailType='percentag :param timeInForce: Changes how long the order will be in effect for. 'gtc' = good until cancelled. \ 'gfd' = good for the day. :type timeInForce: Optional[str] - :param extendedHours: Premium users only. Allows trading during extended hours. Should be true or false. - :type extendedHours: Optional[str] + :param extendedHours: Premium users only. Allows trading during extended hours. + :type extendedHours: Optional[bool] :param jsonify: If set to False, function will return the request object which contains status code and headers. :type jsonify: Optional[str] :returns: Dictionary that contains information regarding the selling of stocks, \ @@ -712,8 +716,8 @@ def order_trailing_stop(symbol, quantity, side, trailAmount, trailType='percenta :param timeInForce: Changes how long the order will be in effect for. 'gtc' = good until cancelled. \ 'gfd' = good for the day. :type timeInForce: Optional[str] - :param extendedHours: Premium users only. Allows trading during extended hours. Should be true or false. - :type extendedHours: Optional[str] + :param extendedHours: Premium users only. Allows trading during extended hours. + :type extendedHours: Optional[bool] :param jsonify: If set to False, function will return the request object which contains status code and headers. :type jsonify: Optional[str] :returns: Dictionary that contains information regarding the purchase of stocks, \ @@ -793,10 +797,12 @@ def order(symbol, quantity, side, limitPrice=None, stopPrice=None, account_numbe :param timeInForce: Changes how long the order will be in effect for. 'gtc' = good until cancelled. \ 'gfd' = good for the day. :type timeInForce: str - :param extendedHours: Premium users only. Allows trading during extended hours. Should be true or false. - :type extendedHours: Optional[str] + :param extendedHours: Premium users only. Allows trading during extended hours. + :type extendedHours: Optional[bool] :param jsonify: If set to False, function will return the request object which contains status code and headers. :type jsonify: Optional[str] + :param market_hours: Valid values are 'regular_hours', 'extended_hours' and 'all_day_hours'. + :type market_hours: Optional[str] :returns: Dictionary that contains information regarding the purchase or selling of stocks, \ such as the order id, the state of order (queued, confired, filled, failed, canceled, etc.), \ the price, and the quantity. @@ -816,6 +822,9 @@ def order(symbol, quantity, side, limitPrice=None, stopPrice=None, account_numbe else: priceType = "bid_price" + if extendedHours and market_hours == 'regular_hours': + market_hours = 'extended_hours' + if limitPrice and stopPrice: price = round_price(limitPrice) stopPrice = round_price(stopPrice) @@ -845,15 +854,15 @@ def order(symbol, quantity, side, limitPrice=None, stopPrice=None, account_numbe 'time_in_force': timeInForce, 'trigger': trigger, 'side': side, - 'market_hours': market_hours, # choices are ['regular_hours', 'all_day_hours'] + 'market_hours': market_hours, 'extended_hours': extendedHours, 'order_form_version': 4 } # adjust market orders if orderType == 'market': del payload['stop_price'] - del payload['extended_hours'] - + del payload['extended_hours'] + if market_hours == 'regular_hours': if side == "buy": payload['preset_percent_limit'] = "0.05" @@ -861,7 +870,7 @@ def order(symbol, quantity, side, limitPrice=None, stopPrice=None, account_numbe # regular market sell elif orderType == 'market' and side == 'sell': del payload['price'] - elif market_hours == 'all_day_hours': + elif market_hours in ('extended_hours', 'all_day_hours'): payload['type'] = 'limit' payload['quantity']=int(payload['quantity']) # round to integer instead of fractional