Path: blob/master/ invest-robot-contest_sirius-master/strategy/calculate_utils.py
5933 views
from utils.util import price_to_float123def calculate_ma(candles, period, argument_name, ma_name):4current_period = 05avg_val = 067for i in range(1, len(candles) + 1):8candle = candles[-i]9avg_val = avg_val + candle[argument_name]10current_period = current_period + 11112if current_period >= period or i == len(candles):13avg_val = avg_val / current_period14for j in range(0, current_period):15candles[-i + j][ma_name] = avg_val1617current_period = 018avg_val = 0192021def add_prices_to_candles(candles):22close_prices = []2324for candle in candles:25close_price = price_to_float(candle['close']['units'], candle['close']['nano'])26candle_time = candle['time']27close_prices.append({'time': candle_time, 'candle': candle, 'price': close_price})28return close_prices293031def calc_profit_percent(price, buy_price):32percent = price / buy_price * 100 - 10033return percent343536