@@ -8,6 +8,7 @@ import { BotProcessing, getWatchers, shouldRunStrategy } from "@opentrader/proce
8
8
import { MarketEvent , MarketId , MarketEventType } from "@opentrader/types" ;
9
9
import { MarketsStream } from "./streams/markets.stream.js" ;
10
10
import { OrderEvent , OrdersStream } from "./streams/orders.stream.js" ;
11
+ import { TradeManager } from "./trade.manager.js" ;
11
12
12
13
type OrderFilledEvent = {
13
14
type : typeof MarketEventType . onOrderFilled ;
@@ -33,6 +34,7 @@ export class Bot {
33
34
public bot : TBotWithExchangeAccount ,
34
35
private ordersStream : OrdersStream ,
35
36
private marketsStream : MarketsStream ,
37
+ private tradeManager : TradeManager ,
36
38
) {
37
39
this . strategy = findStrategy ( this . bot . template ) ;
38
40
this . queue = cargoQueue < QueueEvent > ( this . queueHandler ) ;
@@ -178,6 +180,12 @@ export class Bot {
178
180
this . queue . kill ( ) ;
179
181
this . stopped = true ;
180
182
183
+ // Stop all trades executors
184
+ const trades = this . tradeManager . trades . filter ( ( trade ) => trade . smartTrade . botId === this . bot . id ) ;
185
+ for ( const trade of trades ) {
186
+ trade . destroy ( ) ;
187
+ }
188
+
181
189
// Mark the bot as disabled
182
190
this . bot = await xprisma . bot . custom . update ( {
183
191
where : { id : this . bot . id } ,
0 commit comments