Path: blob/master/ invest-robot-contest_tinkoff_invest_competition-master/app/main.py
7800 views
import daily_check_functions1import daily_buy_functions2import config3import parameters_of_trading4import schedule5import time6import pandas as pd7import datetime8910def robot_day_traider():11directory = '/files/'12order_for_sale = daily_check_functions.CheckRobot2_0(directory + 'test_steven_cat.txt', 0).get_all_orders()13if order_for_sale == -1:14daily_check_functions.CheckRobot2_0(directory + 'test_steven_cat.txt', 1).message_alarm()15elif order_for_sale == 1:16df_all_orders_for_analysis = daily_check_functions.CheckRobot2_0(directory + 'test_steven_cat.txt', 0).get_all_for_sell()17output_value, figi_, total, price, payment = daily_check_functions.CheckRobotSellOrder(parameters_of_trading.profit_value(), df_all_orders_for_analysis).make_do_order()1819if output_value == 0:20daily_check_functions.MakeOrders(output_value, figi_, total, price, order_response_sell = '', log_file_address = directory + 'test_steven_cat.txt').update_data_and_send_to_bot()21elif output_value == 1:22order_response_sell = client2.orders.orders_limit_order_post(figi = figi_, limit_order_request={"lots": total, "operation": 'Sell', "price": price})23daily_check_functions.MakeOrders(output_value, figi_, total, price, order_response_sell, log_file_address = directory + 'test_steven_cat.txt').update_data_and_send_to_bot()24elif output_value == 2:25order_response_sell = client2.orders.orders_limit_order_post(figi = figi_, limit_order_request={"lots": total, "operation": 'Sell', "price": price})26daily_check_functions.MakeOrders(output_value, figi_, total, price, order_response_sell, log_file_address = directory + 'test_steven_cat.txt').update_data_and_send_to_bot()27elif output_value == -1:28daily_check_functions.MakeOrders(output_value, figi_, total, price, order_response_sell = '', log_file_address = directory + 'test_steven_cat.txt').update_data_and_send_to_bot()29"""Возможное добавление усреднений"""30if total != 0:31number_of_stocks = parameters_of_trading.position_of_stocks(price, limit_of_step)32status_of_potential_average, figi_, number_of_stocks, curr_price = daily_check_functions.CheckRobotSellOrderAveraging(address_of_positions = directory + 'test_steven_cat.txt', address_of_progons = directory + 'all_progons.txt', price = price, position_limit = parameters_of_trading.limit_all_position(), rsi_threshold = parameters_of_trading.limit_rsi_on_stock(), number_of_stocks = number_of_stocks).make_do_average_order()33if status_of_potential_average == 1:34sell_price_after_average = parameters_of_trading.sell_after_average_price_evalute(parameters_of_trading.profit_value(), price, payment, total, parameters_of_trading.limit_of_step_average())35MakeBuyAverageOrder(figi = figi_, lots_of_average = number_of_stocks, current_price = curr_price, total = total, price = price, log_file_address = log_file_address, evalute_sell_price_after_average = sell_price_after_average).make_order_average_buy()363738def robot_buy_traider(limit_ticker):39directory = '/files/'40figi, ticker, avg_threshold, avg_RSI, price, index_quantille, index_quantille2, min_price_tendention, param_frequency, first_buy_flg = RobotSearcherAndFirstBuy(limit_ticker = limit_ticker, directory = directory).daily_searcher()41if first_buy_flg == 'FirstBuyCondition':42lots = parameters_of_trading.lots_of_first_buy(price)43FirstBuyBot(figi = figi, lots = lots, price = price, directory = directory).potential_first_buy()4445464748if __name__ == '__main__':495051"""Выгрузка DataFrame по нужным тикерам по дню"""52limit_ticker = pd.read_csv('/files/df_of_possible_tickers.txt')53"""Утренняя постановка ордера на премаркете"""54robot_day_traider()55while True:56if datetime.datetime.now().hour <= 17:57"""Ждать каждые 5 минут до начала основной сессии + 30 минут (30 минут берется для дисбаланса рынка и для времени58расчета min_price_tendention"""59time.sleep(5*60)60else:61schedule.every().day.at('23:05').do(parameters_of_trading.exit)62schedule.every(6).minutes.do(robot_day_traider)63schedule.every(5).minutes.do(robot_buy_traider)64while True:65schedule.run_pending()6667686970717273747576