Skip to content

Commit

Permalink
Fix percentage order
Browse files Browse the repository at this point in the history
  • Loading branch information
MDUYN committed Oct 15, 2023
1 parent edeca54 commit f27fc00
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
7 changes: 5 additions & 2 deletions investing_algorithm_framework/app/algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,13 @@ def create_limit_order(
portfolio = self.portfolio_service.find({"market": market})

if percentage_of_portfolio is not None:

if not OrderSide.BUY.equals(side):
raise ApiException(
"Percentage of portfolio is only supported for BUY orders."
)

size = float(portfolio.net_size) * (percentage_of_portfolio / 100)
amount = floor(size / price)
amount = size / price

elif percentage_of_position is not None:

Expand Down Expand Up @@ -560,6 +559,10 @@ def has_open_orders(self, target_symbol, identifier=None, market=None):

query_params["target_symbol"] = target_symbol
query_params["status"] = OrderStatus.OPEN.value

print(query_params)
for order in self.order_service.get_all():
print(order)
return self.order_service.exists(query_params)

def check_pending_orders(self):
Expand Down
1 change: 1 addition & 0 deletions investing_algorithm_framework/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ def create_portfolios(self):
continue

balances = market_service.get_balance()

if portfolio_configuration.trading_symbol.upper() not in balances:
raise OperationalException(
f"Trading symbol balance not available "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def _apply_query_params(self, db, query, query_params):
"position", query_params, many=True
)
target_symbol_query_param = self.get_query_param(
"symbol", query_params
"target_symbol", query_params
)
trading_symbol_query_param = self.get_query_param(
"trading_symbol", query_params
Expand Down

0 comments on commit f27fc00

Please sign in to comment.