Description
Add high-level ordering convenience functions that simplify portfolio management and rebalancing. The framework currently requires users to calculate order amounts manually.
Desired Capabilities
- order_value(symbol, value): Place an order for a fixed currency amount (automatically calculates quantity)
- order_percent(symbol, percent): Order a percentage of current portfolio value
- order_target(symbol, target_amount): Adjust position to a target number of units (calculates the difference)
- order_target_value(symbol, target_value): Adjust position to a target currency value
- order_target_percent(symbol, target_percent): Adjust position to a target percentage of portfolio
Why This Matters
- order_target_percent is essential for portfolio rebalancing strategies (e.g., maintain 60/40 allocation)
- order_value simplifies dollar-cost averaging and fixed-amount strategies
- order_percent makes it easy to allocate a percentage of capital to each asset
- These functions reduce boilerplate code and prevent common calculation errors
- Target-based functions automatically handle existing positions (buy/sell difference)
Current State
The framework has create_limit_order() with percentage_of_portfolio and percentage_of_position parameters, which covers some of these cases. However, there are no target-based functions that automatically compute the difference between current and desired position, and no order_value for fixed currency amounts.
Suggested API
class MyStrategy(TradingStrategy):
def run_strategy(self, context, data):
price = data["btc_ticker"]["price"]
# Rebalance to target allocation — buys or sells to reach target
context.order_target_percent(
target_symbol="BTC",
target_percent=10.0, # Ensure BTC is 10% of portfolio
price=price,
order_type=OrderType.LIMIT
)
# Fixed currency amount order
context.order_value(
target_symbol="ETH",
value=500.0, # Buy 500 EUR worth of ETH
order_side=OrderSide.BUY,
price=price
)
# Adjust to target position size
context.order_target(
target_symbol="BTC",
target_amount=1.5, # End up with exactly 1.5 BTC
price=price
)
These methods would be added to the Context class alongside the existing create_limit_order() and create_order() methods. Internally they would query current positions and portfolio value, calculate the required order, and delegate to create_order().
Description
Add high-level ordering convenience functions that simplify portfolio management and rebalancing. The framework currently requires users to calculate order amounts manually.
Desired Capabilities
Why This Matters
Current State
The framework has
create_limit_order()withpercentage_of_portfolioandpercentage_of_positionparameters, which covers some of these cases. However, there are no target-based functions that automatically compute the difference between current and desired position, and noorder_valuefor fixed currency amounts.Suggested API
These methods would be added to the
Contextclass alongside the existingcreate_limit_order()andcreate_order()methods. Internally they would query current positions and portfolio value, calculate the required order, and delegate tocreate_order().