-
Notifications
You must be signed in to change notification settings - Fork 0
/
exit_strategy_manager.py
31 lines (27 loc) · 1.03 KB
/
exit_strategy_manager.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import threading
import time
from freqtrade_client import FtRestClient
class ExitStrategyManager:
"""
Manages exit strategies using Freqtrade's REST API, allowing limit orders to switch to market orders
after a specified wait time.
"""
def __init__(self, url, username, password):
self.client = FtRestClient(url, username, password)
def force_exit(self, trade_id):
"""
Force exit a trade by ID using a market order.
"""
response = self.client.forceexit(trade_id, ordertype='market')
return response
def wait_and_force_exit(self, trade_id, wait_time):
"""
Wait for a specified time and then force exit the trade using a market order.
"""
time.sleep(wait_time)
self.force_exit(trade_id)
def schedule_force_exit(self, trade_id, wait_time):
"""
Schedule a force exit after a specified wait time in a separate thread.
"""
threading.Thread(target=self.wait_and_force_exit, args=(trade_id, wait_time)).start()