diff --git a/README.md b/README.md index 111cc03..93a6568 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,7 @@ print(portfolio) ## Usage: Placing Orders ```python order = fennel.place_order( + account_id=account_id, symbol="AAPL", quantity=1, side="buy", # Must be "buy" or "sell" diff --git a/fennel_invest_api/endpoints.py b/fennel_invest_api/endpoints.py index bee4210..12cc47a 100644 --- a/fennel_invest_api/endpoints.py +++ b/fennel_invest_api/endpoints.py @@ -145,10 +145,16 @@ def stock_search_query(self, symbol, count=5): variables = {"query": symbol, "count": count} return json.dumps(self.build_graphql_payload(query, variables)) - def stock_order_query(self, symbol, quantity, isin, side, priceRule): + def stock_order_query(self, account_id, symbol, quantity, isin, side, priceRule): query = """ - mutation CreateOrder($order_details: OrderDetailsInput__!){ - orderCreateOrder(order: $order_details) + mutation CreateOrder( + $order_details: OrderDetailsInput__! + $accountId: String! + ) { + createOrder( + accountId: $accountId + order: $order_details + ) } """ variables = { @@ -160,7 +166,8 @@ def stock_order_query(self, symbol, quantity, isin, side, priceRule): "priceRule": priceRule, "timeInForce": "day", "routingOption": "exchange_ats_sdp", - } + }, + "accountId": account_id, } return json.dumps(self.build_graphql_payload(query, variables)) diff --git a/fennel_invest_api/fennel.py b/fennel_invest_api/fennel.py index 753e732..31b7aac 100644 --- a/fennel_invest_api/fennel.py +++ b/fennel_invest_api/fennel.py @@ -229,7 +229,7 @@ def is_market_open(self): return response["data"]["securityMarketInfo"]["isOpen"] @check_login - def place_order(self, ticker, quantity, side, price="market", dry_run=False): + def place_order(self, account_id, ticker, quantity, side, price="market", dry_run=False): if side.lower() not in ["buy", "sell"]: raise Exception("Side must be either 'buy' or 'sell'") # Check if market is open @@ -254,7 +254,7 @@ def place_order(self, ticker, quantity, side, price="market", dry_run=False): ) isin = search_response["data"]["searchSearch"]["searchSecurities"][0]["isin"] # Place order - query = self.endpoints.stock_order_query(ticker, quantity, isin, side, price) + query = self.endpoints.stock_order_query(account_id, ticker, quantity, isin, side, price) order_response = self.session.post( self.endpoints.graphql, headers=headers, data=query ) diff --git a/setup.py b/setup.py index e6c9476..a8a772c 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name="fennel_invest_api", - version="1.0.4", + version="1.0.5", description="Unofficial Fennel.com Invest API written in Python Requests", long_description=open("README.md").read(), long_description_content_type="text/markdown",