frontend config added
This commit is contained in:
@ -6,7 +6,7 @@ from alpaca.data.requests import StockTradesRequest, StockBarsRequest
|
||||
from alpaca.data.enums import DataFeed
|
||||
from alpaca.data.timeframe import TimeFrame
|
||||
from v2realbot.enums.enums import RecordType, StartBarAlign, Mode, Account, OrderSide
|
||||
from v2realbot.common.model import StrategyInstance, Runner, RunRequest, RunArchive, RunArchiveDetail, RunArchiveChange, Bar, TradeEvent, TestList, Intervals
|
||||
from v2realbot.common.model import StrategyInstance, Runner, RunRequest, RunArchive, RunArchiveDetail, RunArchiveChange, Bar, TradeEvent, TestList, Intervals, ConfigItem
|
||||
from v2realbot.utils.utils import AttributeDict, zoneNY, dict_replace_value, Store, parse_toml_string, json_serial, is_open_hours, send_to_telegram
|
||||
from v2realbot.utils.ilog import delete_logs
|
||||
from v2realbot.common.PrescribedTradeModel import Trade, TradeDirection, TradeStatus, TradeStoplossType
|
||||
@ -761,6 +761,7 @@ def get_all_archived_runners_detail():
|
||||
c = conn.cursor()
|
||||
res = c.execute(f"SELECT data FROM runner_detail")
|
||||
finally:
|
||||
conn.row_factory = None
|
||||
pool.release_connection(conn)
|
||||
return 0, res.fetchall()
|
||||
|
||||
@ -780,6 +781,7 @@ def get_archived_runner_details_byID(id: UUID):
|
||||
result = c.execute(f"SELECT data FROM runner_detail WHERE runner_id='{str(id)}'")
|
||||
res= result.fetchone()
|
||||
finally:
|
||||
conn.row_factory = None
|
||||
pool.release_connection(conn)
|
||||
if res==None:
|
||||
return -2, "not found"
|
||||
@ -797,6 +799,114 @@ def insert_archive_detail(archdetail: RunArchiveDetail):
|
||||
pool.release_connection(conn)
|
||||
return res.rowcount
|
||||
|
||||
# region TESTLISTS db services
|
||||
def get_testlists():
|
||||
try:
|
||||
conn = pool.get_connection()
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("SELECT id, name, dates FROM test_list")
|
||||
rows = cursor.fetchall()
|
||||
finally:
|
||||
pool.release_connection(conn)
|
||||
|
||||
testlists = []
|
||||
for row in rows:
|
||||
print(row)
|
||||
testlist = TestList(id=row[0], name=row[1], dates=json.loads(row[2]))
|
||||
testlists.append(testlist)
|
||||
|
||||
return 0, testlists
|
||||
|
||||
# endregion
|
||||
|
||||
# region CONFIG db services
|
||||
|
||||
def get_all_config_items():
|
||||
conn = pool.get_connection()
|
||||
try:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('SELECT id, item_name, json_data FROM config_table')
|
||||
config_items = [{"id": row[0], "item_name": row[1], "json_data": row[2]} for row in cursor.fetchall()]
|
||||
finally:
|
||||
pool.release_connection(conn)
|
||||
return 0, config_items
|
||||
|
||||
# Function to get a config item by ID
|
||||
def get_config_item_by_id(item_id):
|
||||
conn = pool.get_connection()
|
||||
try:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('SELECT item_name, json_data FROM config_table WHERE id = ?', (item_id,))
|
||||
row = cursor.fetchone()
|
||||
finally:
|
||||
pool.release_connection(conn)
|
||||
if row is None:
|
||||
return -2, "not found"
|
||||
else:
|
||||
return 0, {"item_name": row[0], "json_data": row[1]}
|
||||
|
||||
# Function to get a config item by ID
|
||||
def get_config_item_by_name(item_name):
|
||||
#print(item_name)
|
||||
conn = pool.get_connection()
|
||||
try:
|
||||
cursor = conn.cursor()
|
||||
query = f"SELECT item_name, json_data FROM config_table WHERE item_name = '{item_name}'"
|
||||
#print(query)
|
||||
cursor.execute(query)
|
||||
row = cursor.fetchone()
|
||||
#print(row)
|
||||
finally:
|
||||
pool.release_connection(conn)
|
||||
if row is None:
|
||||
return -2, "not found"
|
||||
else:
|
||||
return 0, {"item_name": row[0], "json_data": row[1]}
|
||||
|
||||
# Function to create a new config item
|
||||
def create_config_item(config_item: ConfigItem):
|
||||
conn = pool.get_connection()
|
||||
try:
|
||||
try:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('INSERT INTO config_table (item_name, json_data) VALUES (?, ?)', (config_item.item_name, config_item.json_data))
|
||||
item_id = cursor.lastrowid
|
||||
conn.commit()
|
||||
print(item_id)
|
||||
finally:
|
||||
pool.release_connection(conn)
|
||||
|
||||
return 0, {"id": item_id, "item_name":config_item.item_name, "json_data":config_item.json_data}
|
||||
except Exception as e:
|
||||
return -2, str(e)
|
||||
|
||||
# Function to update a config item by ID
|
||||
def update_config_item(item_id, config_item: ConfigItem):
|
||||
conn = pool.get_connection()
|
||||
try:
|
||||
try:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('UPDATE config_table SET item_name = ?, json_data = ? WHERE id = ?', (config_item.item_name, config_item.json_data, item_id))
|
||||
conn.commit()
|
||||
finally:
|
||||
pool.release_connection(conn)
|
||||
return 0, {"id": item_id, **config_item.dict()}
|
||||
except Exception as e:
|
||||
return -2, str(e)
|
||||
|
||||
# Function to delete a config item by ID
|
||||
def delete_config_item(item_id):
|
||||
conn = pool.get_connection()
|
||||
try:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('DELETE FROM config_table WHERE id = ?', (item_id,))
|
||||
conn.commit()
|
||||
finally:
|
||||
pool.release_connection(conn)
|
||||
return 0, {"id": item_id}
|
||||
|
||||
# endregion
|
||||
|
||||
#returns b
|
||||
def get_alpaca_history_bars(symbol: str, datetime_object_from: datetime, datetime_object_to: datetime, timeframe: TimeFrame):
|
||||
"""Returns Bar object
|
||||
|
||||
Reference in New Issue
Block a user