forked from 9homme/awesome-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.py
37 lines (30 loc) · 1.2 KB
/
helper.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
import math
from client import telegram_helper
from datetime import datetime
from constant import POSITION_LONG, POSITION_SHORT
def round_decimals_down(number: float, decimals: int = 2):
"""
Returns a value rounded down to a specific number of decimal places.
"""
if not isinstance(decimals, int):
raise TypeError("decimal places must be an integer")
elif decimals < 0:
raise ValueError("decimal places has to be 0 or more")
elif decimals == 0:
return math.floor(number)
factor = 10**decimals
return math.floor(number * factor) / factor
def calculate_total_revenue(
position, current_revenue, quantity, entry_price, exit_price
):
new_revenue = current_revenue
if position == POSITION_LONG:
new_revenue = current_revenue + (quantity * (exit_price - entry_price))
elif position == POSITION_SHORT:
new_revenue = current_revenue + (quantity * (entry_price - exit_price))
position_result = "Win" if new_revenue > current_revenue else "Lose"
telegram_helper.send_telegram_and_print(
datetime.now(),
f"{position_result}!!!!! {(abs(new_revenue - current_revenue)/current_revenue)*100}%",
)
return new_revenue