createbatch image tool + send to telefram enrichment
This commit is contained in:
18
testy/createbatchimage.py
Normal file
18
testy/createbatchimage.py
Normal file
@ -0,0 +1,18 @@
|
||||
import argparse
|
||||
import v2realbot.reporting.metricstoolsimage as mt
|
||||
|
||||
# Parse the command-line arguments
|
||||
# parser = argparse.ArgumentParser(description="Generate trading report image with batch ID")
|
||||
# parser.add_argument("batch_id", type=str, help="The batch ID for the report")
|
||||
# args = parser.parse_args()
|
||||
|
||||
# batch_id = args.batch_id
|
||||
|
||||
# Generate the report image
|
||||
res, val = mt.generate_trading_report_image(batch_id="4d7dc163")
|
||||
|
||||
# Print the result
|
||||
if res == 0:
|
||||
print("BATCH REPORT CREATED")
|
||||
else:
|
||||
print(f"BATCH REPORT ERROR - {val}")
|
||||
@ -24,7 +24,6 @@ from tinydb import TinyDB, Query, where
|
||||
from tinydb.operations import set
|
||||
import orjson
|
||||
import numpy as np
|
||||
from numpy import ndarray
|
||||
from rich import print
|
||||
import pandas as pd
|
||||
from traceback import format_exc
|
||||
@ -37,10 +36,10 @@ from v2realbot.strategyblocks.inits.init_indicators import initialize_dynamic_in
|
||||
from v2realbot.strategyblocks.indicators.indicators_hub import populate_dynamic_indicators
|
||||
from v2realbot.interfaces.backtest_interface import BacktestInterface
|
||||
import os
|
||||
from v2realbot.reporting.metricstoolsimage import generate_trading_report_image
|
||||
import msgpack
|
||||
import v2realbot.reporting.metricstoolsimage as mt
|
||||
import gzip
|
||||
import os
|
||||
import msgpack
|
||||
#import gc
|
||||
#from pyinstrument import Profiler
|
||||
#adding lock to ensure thread safety of TinyDB (in future will be migrated to proper db)
|
||||
@ -349,13 +348,15 @@ def capsule(target: object, db: object, inter_batch_params: dict = None):
|
||||
db.runners.remove(i)
|
||||
#vytvoreni report image pro RUNNER
|
||||
try:
|
||||
res, val = generate_trading_report_image(runner_ids=[str(i.id)])
|
||||
res, val = mt.generate_trading_report_image(runner_ids=[str(i.id)])
|
||||
if res == 0:
|
||||
print("DAILY REPORT IMAGE CREATED")
|
||||
else:
|
||||
print(f"Daily report ERROR - {val}")
|
||||
except Exception as e:
|
||||
print("Nepodarilo se vytvorit report image", str(e)+format_exc())
|
||||
err_msg = "Nepodarilo se vytvorit daily report image" + str(e)+format_exc()
|
||||
send_to_telegram(err_msg)
|
||||
print(err_msg)
|
||||
target.release()
|
||||
print("Runner STOPPED")
|
||||
|
||||
@ -567,14 +568,16 @@ def batch_run_manager(id: UUID, runReq: RunRequest, rundays: list[RunDay]):
|
||||
runReq = None
|
||||
#vytvoreni report image pro batch
|
||||
try:
|
||||
res, val = generate_trading_report_image(batch_id=batch_id)
|
||||
res, val = mt.generate_trading_report_image(batch_id=batch_id)
|
||||
if res == 0:
|
||||
print("BATCH REPORT CREATED")
|
||||
else:
|
||||
print(f"BATCH REPORT ERROR - {val}")
|
||||
|
||||
except Exception as e:
|
||||
print("Nepodarilo se vytvorit report image", str(e)+format_exc())
|
||||
err_msg = "Nepodarilo se vytvorit batch report image" + str(e)+format_exc()
|
||||
send_to_telegram(err_msg)
|
||||
print(err_msg)
|
||||
|
||||
#gc.collect()
|
||||
|
||||
@ -915,7 +918,7 @@ def archive_runner(runner: Runner, strat: StrategyInstance, inter_batch_params:
|
||||
#pole indicatoru, kazdy ma svoji casovou osu time
|
||||
flattened_indicators_list = []
|
||||
for key, value in strat.state.indicators.items():
|
||||
if isinstance(value, ndarray):
|
||||
if isinstance(value, np.ndarray):
|
||||
#print("is numpy", key,value)
|
||||
flattened_indicators[key]= value.tolist()
|
||||
#print("changed numpy:",value.tolist())
|
||||
@ -925,7 +928,7 @@ def archive_runner(runner: Runner, strat: StrategyInstance, inter_batch_params:
|
||||
flattened_indicators_list.append(flattened_indicators)
|
||||
flattened_indicators = {}
|
||||
for key, value in strat.state.cbar_indicators.items():
|
||||
if isinstance(value, ndarray):
|
||||
if isinstance(value, np.ndarray):
|
||||
#print("is numpy", key,value)
|
||||
flattened_indicators[key]= value.tolist()
|
||||
#print("changed numpy:",value.tolist())
|
||||
|
||||
@ -90,8 +90,8 @@ class Trade_Offline_Streamer(Thread):
|
||||
time.sleep(backoff_factor * (2 ** attempt))
|
||||
|
||||
print("All attempts to fetch data failed.")
|
||||
send_to_telegram(f"Failed to fetch stock trades after {max_retries} retries. Last exception: {last_exception}")
|
||||
raise ConnectionError(f"Failed to fetch stock trades after {max_retries} retries. Last exception: {last_exception}")
|
||||
send_to_telegram(f"Failed to fetch stock trades after {max_retries} retries. Last exception: {str(last_exception)} and {format_exc()}")
|
||||
raise ConnectionError(f"Failed to fetch stock trades after {max_retries} retries. Last exception: {str(last_exception)} and {format_exc()}")
|
||||
|
||||
# Override the run() function of Thread class
|
||||
#odebrano async
|
||||
|
||||
20
v2realbot/tools/createbatchimage.py
Normal file
20
v2realbot/tools/createbatchimage.py
Normal file
@ -0,0 +1,20 @@
|
||||
import argparse
|
||||
import v2realbot.reporting.metricstoolsimage as mt
|
||||
|
||||
##Generates BATCH REPORT again for the given batch_id
|
||||
##USAGE: python createbatchimage.py <batch_id>
|
||||
#Parse the command-line arguments
|
||||
parser = argparse.ArgumentParser(description="Generate trading report image with batch ID")
|
||||
parser.add_argument("batch_id", type=str, help="The batch ID for the report")
|
||||
args = parser.parse_args()
|
||||
|
||||
batch_id = args.batch_id
|
||||
|
||||
# Generate the report image
|
||||
res, val = mt.generate_trading_report_image(batch_id=batch_id)
|
||||
|
||||
# Print the result
|
||||
if res == 0:
|
||||
print("BATCH REPORT CREATED")
|
||||
else:
|
||||
print(f"BATCH REPORT ERROR - {val}")
|
||||
@ -13,6 +13,7 @@ from collections import defaultdict
|
||||
from pandas import to_datetime
|
||||
from msgpack.ext import Timestamp
|
||||
import time
|
||||
from traceback import format_exc
|
||||
|
||||
def convert_historical_bars(daily_bars):
|
||||
"""Converts a list of daily bars into a dictionary with the specified keys.
|
||||
@ -124,5 +125,5 @@ def get_historical_bars(symbol: str, time_from: datetime, time_to: datetime, tim
|
||||
time.sleep(backoff_factor * (2 ** attempt))
|
||||
|
||||
print("All attempts to fetch historical bar data failed.")
|
||||
send_to_telegram(f"Failed to fetch historical bar data after {max_retries} retries. Last exception: {last_exception}")
|
||||
raise Exception(f"Failed to fetch historical bar data after {max_retries} retries. Last exception: {last_exception}")
|
||||
send_to_telegram(f"Failed to fetch historical bar data after {max_retries} retries. Last exception: {str(last_exception)} and {format_exc()}")
|
||||
raise Exception(f"Failed to fetch historical bar data after {max_retries} retries. Last exception: {str(last_exception)} and {format_exc()}")
|
||||
|
||||
@ -29,6 +29,7 @@ import numpy as np
|
||||
from alpaca.trading.requests import GetCalendarRequest
|
||||
from alpaca.trading.client import TradingClient
|
||||
import time as timepkg
|
||||
from traceback import format_exc
|
||||
|
||||
#Alpaca Calendar wrapper with retry
|
||||
def fetch_calendar_data(start, end, max_retries=5, backoff_factor=1):
|
||||
@ -60,8 +61,8 @@ def fetch_calendar_data(start, end, max_retries=5, backoff_factor=1):
|
||||
timepkg.sleep(backoff_factor * (2 ** attempt))
|
||||
|
||||
richprint("****All attempts to fetch calendar data failed.****")
|
||||
send_to_telegram(f"FETCH_CALENDER_DATA_FAILED. {last_exception} BACKEST STOPPED" )
|
||||
raise ConnectionError(f"Failed to fetch calendar data after {max_retries} retries. Last exception: {last_exception}")
|
||||
send_to_telegram(f"FETCH_CALENDER_DATA_FAILED. {str(last_exception)} and {format_exc()} BACKEST STOPPED" )
|
||||
raise ConnectionError(f"Failed to fetch calendar data after {max_retries} retries. Last exception: {str(last_exception)} and {format_exc()}")
|
||||
|
||||
def concatenate_weekdays(weekday_filter):
|
||||
# Mapping of weekdays where 0 is Monday and 6 is Sunday
|
||||
|
||||
Reference in New Issue
Block a user