def handle(ex: Exception) -> str: response: ResponseModel = ResponseModel() try: LogUtils.error('Handle error', ex) msg: str = str(ex) response.http_status_code = http.HTTPStatus.INTERNAL_SERVER_ERROR response.error_message = msg if msg else 'Error' if isinstance(ex, BadRequestException): response.http_status_code = http.HTTPStatus.BAD_REQUEST if isinstance(ex, NotFoundException): response.http_status_code = http.HTTPStatus.NOT_FOUND if isinstance(ex, DbConnectionException): response.http_status_code = http.HTTPStatus.INTERNAL_SERVER_ERROR except Exception as e: response.http_status_code = http.HTTPStatus.INTERNAL_SERVER_ERROR response.error_message = 'Error' return StringUtils.to_json(response)
def close_positions() -> str: return StringUtils.to_json(ResponseModel( __trade_service.close_positions()))
def sync_orders() -> str: return StringUtils.to_json(ResponseModel(__trade_service.sync_orders()))
def get_all_suggestions() -> str: return StringUtils.to_json( ResponseModel(__trade_service.get_all_suggestions()))
def get_suggestions() -> str: req: TradeSuggestionsRequest = ModelUtils.get_obj( TradeSuggestionsRequest(), request.get_json()) return StringUtils.to_json( ResponseModel(__trade_service.get_suggestions(req)))
def get_trade_orders() -> str: req: GetTradeOrdersRequest = ModelUtils.get_obj(GetTradeOrdersRequest(), request.get_json()) return StringUtils.to_json( ResponseModel(__trade_service.get_trade_orders(req)))
def get_key_info(symbol: str) -> str: return StringUtils.to_json( ResponseModel(__trade_service.get_key_info(symbol)))
def get_account() -> str: return StringUtils.to_json(ResponseModel(__trade_service.get_account()))
def get_sample_prices_for_charts() -> str: req: CR = ModelUtils.get_obj(CR(), request.get_json()) return StringUtils.to_json( ResponseModel(__stock_service.get_sample_prices_for_charts(req)))
def get_sp500_mismatches(is_missing: str) -> str: return StringUtils.to_json( ResponseModel( __stock_service.get_sp500_mismatches(is_missing == 'True')))
def delete_old_prices() -> str: return StringUtils.to_json( ResponseModel(__stock_service.delete_old_prices()))
def update_symbol() -> str: req: SymbolMaster = ModelUtils.get_obj(SymbolMaster(), request.get_json()) return StringUtils.to_json( ResponseModel(__stock_service.update_symbol(req)))
def get_symbols(instrument: str) -> str: return StringUtils.to_json( ResponseModel(__stock_service.get_symbols(instrument)))
def run() -> str: req: BackTestRunRequest = ModelUtils.get_obj(BackTestRunRequest(), request.get_json()) return StringUtils.to_json(ResponseModel(__back_test_service.run(req)))
def import_prices() -> str: return StringUtils.to_json(ResponseModel(__import_service.import_prices()))