def get_all_suggestions(self) -> int: error: Exception = None try: accnt: Account = self.get_account() capital: float = NumberUtils.to_floor( NumberUtils.to_float(accnt._raw['buying_power']) / 2) # 2 to trade everyday # Double Bottoms req: TradeSuggestionsRequest = TradeSuggestionsRequest() req.is_job = True req.current_capital = capital req.pct_risk_per_trade = 2.5 req.volume_limit = 0.01 req.test_limit_symbol = 800 req.adv_min = AppConsts.ADV_MIN_DFLT req.adpv_min = AppConsts.ADPV_MIN_DFLT req.strategy_type = AppConsts.STRATEGY_DOUBLE_BOTTOMS req.strategy_request = {} req.strategy_request['exponential_smoothing_alpha'] = 0.8 req.strategy_request['exponential_smoothing_max_min_diff'] = 0.7 req.strategy_request['double_bottoms_diff'] = 1 LogUtils.debug(StringUtils.to_json(req)) self.get_suggestions(req) # Double Tops req: TradeSuggestionsRequest = TradeSuggestionsRequest() req.is_job = True req.current_capital = capital req.pct_risk_per_trade = 2.5 req.volume_limit = 0.01 req.test_limit_symbol = 800 req.adv_min = AppConsts.ADV_MIN_DFLT req.adpv_min = AppConsts.ADPV_MIN_DFLT req.strategy_type = AppConsts.STRATEGY_DOUBLE_TOPS req.strategy_request = {} req.strategy_request['exponential_smoothing_alpha'] = 0.8 req.strategy_request['exponential_smoothing_max_min_diff'] = 0.7 req.strategy_request['double_tops_diff'] = 1 LogUtils.debug(StringUtils.to_json(req)) self.get_suggestions(req) except Exception as ex: error = ex finally: self.__email_client.send_html( subject=AppConsts.EMAIL_SUBJECT_GET_SUGGESTIONS, template_path=AppConsts.TEMPLATE_PATH_GET_SUGGESTIONS, model={'errors': [error] if error else []}) if error: LogUtils.error('Get Suggestions Error', error) return 1
def cancel_order(self, order_id: str) -> None: try: LogUtils.debug('Submit request = {0}'.format(order_id)) self.__api.cancel_order(order_id) except Exception as ex: LogUtils.error( 'Submit Error for {0}'.format(StringUtils.to_json(order)), ex) raise ex
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 import_prices() -> str: return StringUtils.to_json(ResponseModel(__import_service.import_prices()))
def sync_orders() -> str: return StringUtils.to_json(ResponseModel(__trade_service.sync_orders()))
def close_positions() -> str: return StringUtils.to_json(ResponseModel( __trade_service.close_positions()))
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_all_suggestions() -> str: return StringUtils.to_json( ResponseModel(__trade_service.get_all_suggestions()))
def get_key_info(symbol: str) -> str: return StringUtils.to_json( ResponseModel(__trade_service.get_key_info(symbol)))
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 run() -> str: req: BackTestRunRequest = ModelUtils.get_obj(BackTestRunRequest(), request.get_json()) return StringUtils.to_json(ResponseModel(__back_test_service.run(req)))
def get_account() -> str: return StringUtils.to_json(ResponseModel(__trade_service.get_account()))
def get_sp500_mismatches(is_missing: str) -> str: return StringUtils.to_json( ResponseModel( __stock_service.get_sp500_mismatches(is_missing == 'True')))
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 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)))