Implement progressive position sizing with max_size parameter

- Add max_size support to trading logic, defaulting to trade_size
- Continue quoting trade_size amounts until max_size is reached
- Implement progressive exit strategy: sell trade_size increments when at max_size
- Track both token positions for better exposure management
- Update buy conditions to use max_size instead of 0.9 * trade_size

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
warproxxx
2025-06-22 09:38:27 -07:00
parent b8de7e7bb1
commit 8456697577
2 changed files with 50 additions and 11 deletions
+32 -5
View File
@@ -128,18 +128,45 @@ def round_up(number, decimals):
factor = 10 ** decimals
return math.ceil(number * factor) / factor
def get_buy_sell_amount(position, bid_price, row):
def get_buy_sell_amount(position, bid_price, row, other_token_position=0):
buy_amount = 0
sell_amount = 0
sell_amount = position
buy_amount = row['trade_size'] - position
# Get max_size, defaulting to trade_size if not specified
max_size = row.get('max_size', row['trade_size'])
trade_size = row['trade_size']
# Calculate total exposure across both sides
total_exposure = position + other_token_position
# If we haven't reached max_size on either side, continue building
if position < max_size:
# Continue quoting trade_size amounts until we reach max_size
remaining_to_max = max_size - position
buy_amount = min(trade_size, remaining_to_max)
# Only sell if we have substantial position (to allow for exit when needed)
if position >= trade_size:
sell_amount = min(position, trade_size)
else:
sell_amount = 0
else:
# We've reached max_size, implement progressive exit strategy
# Always offer to sell trade_size amount when at max_size
sell_amount = min(position, trade_size)
# Continue quoting to buy if total exposure warrants it
if total_exposure < max_size * 2: # Allow some flexibility for market making
buy_amount = trade_size
else:
buy_amount = 0
# Ensure minimum order size compliance
if buy_amount > 0.7 * row['min_size'] and buy_amount < row['min_size']:
buy_amount = row['min_size']
if bid_price < 0.1:
# Apply multiplier for low-priced assets
if bid_price < 0.1 and buy_amount > 0:
if row['multiplier'] != '':
print(f"Multiplying buy amount by {int(row['multiplier'])}")
buy_amount = buy_amount * int(row['multiplier'])