Skip to content

Commit

Permalink
Don't increase price spreads
Browse files Browse the repository at this point in the history
After waiting to update an order price, sometimes the midpoint goes in
the wrong direction after we place the order. We don't want to increase
the spread because it almost always makes the order not fill. Instead,
leave the price as-is if the change would increase the spread.
  • Loading branch information
brndnmtthws committed Apr 16, 2024
1 parent e6cbc61 commit c70309a
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions thetagang/portfolio_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2270,6 +2270,19 @@ def adjust_prices(self) -> None:
),
]
)

# We only want to tighten spreads, not widen them. If the
# resulting price change would increase the spread, we'll
# skip it.
if (order.lmtPrice < 0 and updated_price < order.lmtPrice) or (
order.lmtPrice > 0 and updated_price > order.lmtPrice
):
console.print(
f"[yellow]Skipping order for {contract.symbol}"
f" with old lmtPrice={dfmt(order.lmtPrice)} updated lmtPrice={dfmt(updated_price)}, because updated price would increase spread"
)
continue

# Check if the updated price is actually any different
# before proceeding, and make sure the signs match so we
# don't switch a credit to a debit or vice versa.
Expand Down

0 comments on commit c70309a

Please sign in to comment.