feat: Add on-chain TP/SL order placement

- Add placeExitOrders() to create reduce-only LIMIT orders for TP1, TP2, and SL
- Orders now visible in Drift UI
- Tested with real tiny position (0 base x 5x = 0)
- All 3 exit orders placed successfully on-chain
- Position manager continues monitoring as backup
- Added test script and results documentation
This commit is contained in:
mindesbunister
2025-10-26 13:30:07 +01:00
parent 993ae64c64
commit 4cc294baef
6 changed files with 365 additions and 17 deletions

View File

@@ -32,6 +32,9 @@ export interface TradingConfig {
// Execution
useMarketOrders: boolean // true = instant execution
confirmationTimeout: number // Max time to wait for confirmation
// Take profit size splits (percentages of position to close at TP1/TP2)
takeProfit1SizePercent: number
takeProfit2SizePercent: number
}
export interface MarketConfig {
@@ -71,6 +74,8 @@ export const DEFAULT_TRADING_CONFIG: TradingConfig = {
// Execution
useMarketOrders: true, // Use market orders for reliable fills
confirmationTimeout: 30000, // 30 seconds max wait
takeProfit1SizePercent: 75,
takeProfit2SizePercent: 100,
}
// Supported markets on Drift Protocol
@@ -165,6 +170,12 @@ export function getConfigFromEnv(): Partial<TradingConfig> {
takeProfit2Percent: process.env.TAKE_PROFIT_2_PERCENT
? parseFloat(process.env.TAKE_PROFIT_2_PERCENT)
: undefined,
takeProfit1SizePercent: process.env.TAKE_PROFIT_1_SIZE_PERCENT
? parseFloat(process.env.TAKE_PROFIT_1_SIZE_PERCENT)
: undefined,
takeProfit2SizePercent: process.env.TAKE_PROFIT_2_SIZE_PERCENT
? parseFloat(process.env.TAKE_PROFIT_2_SIZE_PERCENT)
: undefined,
maxDailyDrawdown: process.env.MAX_DAILY_DRAWDOWN
? parseFloat(process.env.MAX_DAILY_DRAWDOWN)
: undefined,