Skip to content

feat: support percent-of-portfolio order sizing#20

Open
subhajitlucky wants to merge 1 commit into
CryptoGnome:mainfrom
subhajitlucky:qty-percent-portfolio-9
Open

feat: support percent-of-portfolio order sizing#20
subhajitlucky wants to merge 1 commit into
CryptoGnome:mainfrom
subhajitlucky:qty-percent-portfolio-9

Conversation

@subhajitlucky
Copy link
Copy Markdown

@subhajitlucky subhajitlucky commented May 12, 2026

Fixes #9.

Summary

  • Add optional qty_percent support for Binance Futures alerts.
  • Calculate order quantity from available quote-currency balance and current/limit reference price.
  • Keep existing qty behavior when qty_percent is not provided.
  • Fix Binance Futures config key casing and route indentation so the Binance Futures webhook path can run.
  • Document qty_percent in the alert settings table.

Verification

  • python3 -m unittest test_order_sizing -v
  • python3 -m py_compile app.py binanceFutures.py order_sizing.py
  • git diff --check

Copilot AI review requested due to automatic review settings May 12, 2026 07:20
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds optional “percent-of-portfolio” sizing for Binance Futures alerts by computing order quantity from available quote-currency balance and a reference price, while keeping existing qty behavior when qty_percent is omitted. Also fixes Binance Futures config key casing/route indentation and documents the new alert field.

Changes:

  • Introduce order_sizing.py helpers to derive quote currency, read available balance, and compute base-asset qty from qty_percent.
  • Update Binance Futures bot to support qty_percent and to use corrected BINANCE-FUTURES config casing.
  • Fix Binance Futures webhook route indentation and document qty_percent in README; add basic unit tests for sizing helpers.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
order_sizing.py New sizing utilities for converting % of quote balance into order quantity.
binanceFutures.py Uses sizing utilities when qty_percent is provided; fixes config key casing usage.
app.py Fixes Binance Futures webhook routing/indentation and returns clearer error response when disabled.
README.md Documents new qty_percent alert field.
test_order_sizing.py Adds unit tests for quote-currency parsing and percent-based sizing.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread order_sizing.py Outdated
return 0
if quote_currency in balance:
if isinstance(balance[quote_currency], dict):
return float(balance[quote_currency].get('free') or balance[quote_currency].get('total') or 0)
Comment thread binanceFutures.py
Comment on lines 162 to 168
if data['order_mode'] == 'Both':
take_profit_percent = float(data['take_profit_percent']) / 100
stop_loss_percent = float(data['stop_loss_percent']) / 100
current_price = exchange.fetch_ticker(data['symbol'])['last']
reference_price = price if data['type'] == 'Limit' and price else current_price
qty = self.get_order_quantity(data, reference_price)
if data['side'] == 'Buy':
Comment thread app.py
Comment on lines +173 to +184
if data['exchange'] == 'binance-futures':
if use_binance_futures:
bot = Bot()
bot.run(data)
return {
"status": "error",
"message": "Invalid Exchange, Please Try Again!"
"status": "success",
"message": "Binance Futures Webhook Received!"
}
return {
"status": "error",
"message": "Binance Futures is not enabled or API validation failed."
}
Comment thread test_order_sizing.py Outdated

qty = calculate_qty_from_percent(balance, 'BTC/USDT', 25000, 10)

self.assertEqual(qty, 0.004)
Comment thread binanceFutures.py
Comment on lines 195 to 200
elif data['order_mode'] == 'Profit':
take_profit_percent = float(data['take_profit_percent']) / 100
current_price = exchange.fetch_ticker(data['symbol'])['last']
reference_price = price if data['type'] == 'Limit' and price else current_price
qty = self.get_order_quantity(data, reference_price)

@subhajitlucky
Copy link
Copy Markdown
Author

Updated after automated review:

  • Preserve zero free balance instead of falling back to total.
  • Parse and validate limit reference prices before sizing.
  • Return structured JSON errors for Binance Futures webhook failures.
  • Use tolerant float assertions in sizing tests.
  • Compute ticker/reference price/quantity once before the order-mode branch.

Verification:

  • python3 -m unittest test_order_sizing -v
  • python3 -m py_compile app.py binanceFutures.py order_sizing.py test_order_sizing.py
  • git diff --check

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

amount percent of portfolio

2 participants