-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.py
More file actions
56 lines (48 loc) · 1.89 KB
/
Copy pathbot.py
File metadata and controls
56 lines (48 loc) · 1.89 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import MetaTrader5 as mt5
import RSI, threading, orders
class Bot:
def __init__(self, lotage: float, time_period: int, market: str):
"""Constructor of the bot. It justs fills the needed informartion for the bot.
Args:
lotage (float): Lotage to be used by the bot.
time_period (int): Time period of the bot, 1 minute, 15 minutes... (in seconds)
market (str): Market to operate in.
"""
self.threads = []
self.data = {'RSI': None}
self.pill2kill = threading.Event()
self.trading_data = {}
self.trading_data['lotage'] = lotage
self.trading_data['time_period'] = time_period
self.trading_data['market'] = market
def thread_rsi(self):
"""Function to launch the data thread."""
t = threading.Thread(target=RSI.thread_rsi,
args=(self.pill2kill, self.data))
self.threads.append(t)
t.start()
print('Thread - DATA. LAUNCHED')
def thread_orders(self):
"""Function to launch the thread for sending orders."""
t = threading.Thread(target=orders.thread_orders,
args=(self.pill2kill, self.data, self.trading_data))
self.threads.append(t)
t.start()
print('Thread - ORDERS. LAUNCHED')
def kill_threads(self):
"""Function to kill all the loaded threads."""
print('Threads - Stopping threads')
self.pill2kill.set()
for thread in self.threads:
thread.join()
def start(self):
"""Function to start all the threads"""
self.thread_rsi()
self.thread_orders()
def wait(self):
"""Function to make the thread wait."""
# Input to stop the bot
print('\nPress ENTER to stop the bot\n')
input()
self.kill_threads()
mt5.shutdown()