Пример #1
0
    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
Пример #2
0
    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
Пример #3
0
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)
Пример #4
0
def import_prices() -> str:
    return StringUtils.to_json(ResponseModel(__import_service.import_prices()))
Пример #5
0
def sync_orders() -> str:
    return StringUtils.to_json(ResponseModel(__trade_service.sync_orders()))
Пример #6
0
def close_positions() -> str:
    return StringUtils.to_json(ResponseModel(
        __trade_service.close_positions()))
Пример #7
0
def get_suggestions() -> str:
    req: TradeSuggestionsRequest = ModelUtils.get_obj(
        TradeSuggestionsRequest(), request.get_json())
    return StringUtils.to_json(
        ResponseModel(__trade_service.get_suggestions(req)))
Пример #8
0
def get_all_suggestions() -> str:
    return StringUtils.to_json(
        ResponseModel(__trade_service.get_all_suggestions()))
Пример #9
0
def get_key_info(symbol: str) -> str:
    return StringUtils.to_json(
        ResponseModel(__trade_service.get_key_info(symbol)))
Пример #10
0
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)))
Пример #11
0
def run() -> str:
    req: BackTestRunRequest = ModelUtils.get_obj(BackTestRunRequest(),
                                                 request.get_json())
    return StringUtils.to_json(ResponseModel(__back_test_service.run(req)))
Пример #12
0
def get_account() -> str:
    return StringUtils.to_json(ResponseModel(__trade_service.get_account()))
Пример #13
0
def get_sp500_mismatches(is_missing: str) -> str:
    return StringUtils.to_json(
        ResponseModel(
            __stock_service.get_sp500_mismatches(is_missing == 'True')))
Пример #14
0
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)))
Пример #15
0
def delete_old_prices() -> str:
    return StringUtils.to_json(
        ResponseModel(__stock_service.delete_old_prices()))
Пример #16
0
def update_symbol() -> str:
    req: SymbolMaster = ModelUtils.get_obj(SymbolMaster(), request.get_json())
    return StringUtils.to_json(
        ResponseModel(__stock_service.update_symbol(req)))
Пример #17
0
def get_symbols(instrument: str) -> str:
    return StringUtils.to_json(
        ResponseModel(__stock_service.get_symbols(instrument)))