frontend config added
This commit is contained in:
@ -14,7 +14,7 @@ import uvicorn
|
||||
from uuid import UUID
|
||||
import v2realbot.controller.services as cs
|
||||
from v2realbot.utils.ilog import get_log_window
|
||||
from v2realbot.common.model import StrategyInstance, RunnerView, RunRequest, Trade, RunArchive, RunArchiveDetail, Bar, RunArchiveChange, TestList
|
||||
from v2realbot.common.model import StrategyInstance, RunnerView, RunRequest, Trade, RunArchive, RunArchiveDetail, Bar, RunArchiveChange, TestList, ConfigItem
|
||||
from fastapi import FastAPI, WebSocket, WebSocketDisconnect, Depends, HTTPException, status, WebSocketException, Cookie, Query
|
||||
from fastapi.responses import HTMLResponse, FileResponse
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
@ -354,18 +354,11 @@ def create_record(testlist: TestList):
|
||||
# API endpoint to retrieve all records
|
||||
@app.get('/testlists/', dependencies=[Depends(api_key_auth)])
|
||||
def get_testlists():
|
||||
conn = pool.get_connection()
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("SELECT id, name, dates FROM test_list")
|
||||
rows = cursor.fetchall()
|
||||
pool.release_connection(conn)
|
||||
|
||||
testlists = []
|
||||
for row in rows:
|
||||
testlist = TestList(id=row[0], name=row[1], dates=json.loads(row[2]))
|
||||
testlists.append(testlist)
|
||||
|
||||
return testlists
|
||||
res, sada = cs.get_testlists()
|
||||
if res == 0:
|
||||
return sada
|
||||
else:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=f"No data found")
|
||||
|
||||
# API endpoint to retrieve a single record by ID
|
||||
@app.get('/testlists/{record_id}')
|
||||
@ -416,6 +409,73 @@ def delete_testlist(record_id: str):
|
||||
|
||||
return {'message': 'Record deleted'}
|
||||
|
||||
# region CONFIG APIS
|
||||
|
||||
# Get all config items
|
||||
@app.get("/config-items/", dependencies=[Depends(api_key_auth)])
|
||||
def get_all_items() -> list[ConfigItem]:
|
||||
res, sada = cs.get_all_config_items()
|
||||
if res == 0:
|
||||
return sada
|
||||
else:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=f"No data found")
|
||||
|
||||
|
||||
# Get a config item by ID
|
||||
@app.get("/config-items/{item_id}", dependencies=[Depends(api_key_auth)])
|
||||
def get_item(item_id: int)-> ConfigItem:
|
||||
res, sada = cs.get_config_item_by_id(item_id)
|
||||
if res == 0:
|
||||
return sada
|
||||
else:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=f"No data found")
|
||||
|
||||
# Get a config item by Name
|
||||
@app.get("/config-items-by-name/", dependencies=[Depends(api_key_auth)])
|
||||
def get_item(item_name: str)-> ConfigItem:
|
||||
res, sada = cs.get_config_item_by_name(item_name)
|
||||
if res == 0:
|
||||
return sada
|
||||
else:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=f"No data found")
|
||||
|
||||
# Create a new config item
|
||||
@app.post("/config-items/", dependencies=[Depends(api_key_auth)], status_code=status.HTTP_200_OK)
|
||||
def create_item(config_item: ConfigItem) -> ConfigItem:
|
||||
res, sada = cs.create_config_item(config_item)
|
||||
if res == 0: return sada
|
||||
else:
|
||||
raise HTTPException(status_code=status.HTTP_406_NOT_ACCEPTABLE, detail=f"Error not created: {res}:{id} {sada}")
|
||||
|
||||
|
||||
# Update a config item by ID
|
||||
@app.put("/config-items/{item_id}", dependencies=[Depends(api_key_auth)])
|
||||
def update_item(item_id: int, config_item: ConfigItem) -> ConfigItem:
|
||||
res, sada = cs.get_config_item_by_id(item_id)
|
||||
if res != 0:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=f"No data found")
|
||||
|
||||
res, sada = cs.update_config_item(item_id, config_item)
|
||||
if res == 0: return sada
|
||||
else:
|
||||
raise HTTPException(status_code=status.HTTP_406_NOT_ACCEPTABLE, detail=f"Error not created: {res}:{id}")
|
||||
|
||||
|
||||
# Delete a config item by ID
|
||||
@app.delete("/config-items/{item_id}", dependencies=[Depends(api_key_auth)])
|
||||
def delete_item(item_id: int) -> dict:
|
||||
res, sada = cs.get_config_item_by_id(item_id)
|
||||
if res != 0:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=f"No data found")
|
||||
|
||||
res, sada = cs.delete_config_item(item_id)
|
||||
if res == 0: return sada
|
||||
else:
|
||||
raise HTTPException(status_code=status.HTTP_406_NOT_ACCEPTABLE, detail=f"Error not created: {res}:{id}")
|
||||
|
||||
# endregion
|
||||
|
||||
|
||||
# Thread function to insert data from the queue into the database
|
||||
def insert_queue2db():
|
||||
print("starting insert_queue2db thread")
|
||||
|
||||
Reference in New Issue
Block a user