Skip to content

Commit

Permalink
multi account orders
Browse files Browse the repository at this point in the history
  • Loading branch information
NelsonDane committed May 21, 2024
1 parent ab637fe commit 31e684f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
15 changes: 11 additions & 4 deletions fennel_invest_api/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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))

Expand Down
4 changes: 2 additions & 2 deletions fennel_invest_api/fennel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 31e684f

Please sign in to comment.