def get_stock_orders(self) -> List[RobinhoodOrder]: ''' Fetches the stock orders from the remote Robinhood exchange. ''' if self.client is None: raise Exception("Initialize the client first.") raw_orders = StockOrder.all(self.client) return self.__raw_to_robinhood_orders(raw_orders)
def stock_orders(client, options={}): ''' options: - only_filled. Only return filled orders. Default = False. ''' orders = StockOrder.all(client) only_filled = util.get_key(options, "only_filled", True) if only_filled: orders = list(filter(lambda x: x["state"] == "filled", orders)) return orders
def stock_orders(account, options={}): ''' options: - only_filled. Only return filled orders. Default = False. ''' client = _init_client(account["username"], account["password"]) orders = StockOrder.all(client) only_filled = util.get_key(options, "only_filled", True) if only_filled: orders = list(filter(lambda x: x["state"] == "filled", orders)) return orders
def test_fetch_fields(self): client = gen_client() with gen_vcr().use_cassette('stockorder_all.yaml'): orders = StockOrder.all(client) order = orders[0] expected_fields = [ 'updated_at', 'ref_id', 'time_in_force', 'fees', 'cancel', 'response_category', 'id', 'cumulative_quantity', 'stop_price', 'reject_reason', 'instrument', 'state', 'trigger', 'override_dtbp_checks', 'type', 'last_transaction_at', 'price', 'executions', 'extended_hours', 'account', 'url', 'created_at', 'side', 'override_day_trade_checks', 'position', 'average_price', 'quantity' ] actual_fields = list(order.keys()) assert (set(expected_fields) == set(actual_fields))
def stock_orders(account, options={}): token = _get_token(account["username"], account["password"]) orders = StockOrder.all(token) if ("only_filled" in options) and options["only_filled"]: orders = list(filter(lambda x: x["state"] == "filled", orders)) return orders