-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorder.py
41 lines (33 loc) · 1.13 KB
/
order.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
32
33
34
35
36
37
38
39
40
41
import numpy as np
class trade_order():
def __init__(self, order_type, entry_price, order_id, percent_gain=3):
self.order_type = order_type
self.percent_gain = percent_gain
self.entry_price = entry_price
self.life_counter = 0
self.order_id = order_id
def scaled_sigmoid(self, n, i):
if abs(i) > n:
i = n
scaled_x = 10 * (abs(i) / n) - 5
return 1 / (1 + np.exp(-scaled_x))
def get_percent_change(self, current_price):
if current_price == 0:
return 0
result = ((current_price-self.entry_price)/current_price)*100
return result
def check_change(self, current_price):
percent_diff = self.get_percent_change(current_price)
if self.order_type == "buy":
if percent_diff >= self.percent_gain:
return 1
elif percent_diff <= -(self.percent_gain/2):
return 2
pass
elif self.order_type == "sell":
if percent_diff <= -self.percent_gain:
return 1
elif percent_diff >= (self.percent_gain/2):
return 2
pass
return 0