コード例 #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)))