Пример #1
0
    def on_post(self, req, res):
        target_req = req.context['data']
        if target_req:
            target = Target()
            target.code = target_req["code"]
            target.strategy_code = target_req["strategy_code"]
            target.name = target_req["name"]
            target.pointcut = target_req["pointcut"]

            target_est = target_dao.query_by_code(
                strategy_code=target.strategy_code, code=target.code)
            if target_est is not None:
                raise InvalidRequestException("stock has already exists")

            # 订阅
            futu_opend.subscribe(fill_market(target_req["code"]))
            state, data = futu_opend.quote_ctx.get_stock_quote(
                code_list=[fill_market(target_req["code"])])
            if state == RET_OK:
                target.price = data['last_price'].values[0]
            target_dao.add(target)

        else:
            raise InvalidRequestException(target_req)

        self.on_success(res, None)
Пример #2
0
def validate_target_update(req, res, resource, params):
    schema = {
        'id': FIELDS['id'],
        'pointcut': FIELDS['pointcut'],
    }

    v = Validator(schema)

    if not v.validate(req.context['data']):
        raise InvalidRequestException(v.errors)
Пример #3
0
def validate_position_update(req, res, resource, params):
    schema = {
        'id': FIELDS['id'],
        'price_in': FIELDS['price_in'],
        'shares': FIELDS['shares']
    }

    v = Validator(schema)

    if not v.validate(req.context['data']):
        raise InvalidRequestException(v.errors)
Пример #4
0
def validate_target_create(req, res, resource, params):
    schema = {
        'code': FIELDS['code'],
        'name': FIELDS['name'],
        'strategy_code': FIELDS['strategy_code'],
        'pointcut': FIELDS['pointcut']
    }

    v = Validator(schema)

    if not v.validate(req.context['data']):
        raise InvalidRequestException(v.errors)
Пример #5
0
    def on_post(self, req, res):
        position_req = req.context['data']
        if position_req:
            position = Position()
            position.code = position_req["code"]
            position.strategy_code = position_req["strategy_code"]
            position.name = position_req["name"]
            position.price_in = position_req["price_in"]
            position.shares = position_req["shares"]

            position_est = position_dao.query_by_code(strategy_code=position.strategy_code, code=position.code)
            if position_est is not None:
                raise InvalidRequestException("stock has already exists")

            futu_opend.subscribe(fill_market(position_req["code"]))
            state, data = futu_opend.quote_ctx.get_stock_quote(code_list=[fill_market(position_req["code"])])
            if state == RET_OK:
                position.price = data['last_price'].values[0]

            position_dao.add(position)
        else:
            raise InvalidRequestException(position_req)

        self.on_success(res, None)
Пример #6
0
    def on_put(self, req, resp):
        id_list_req = req.context['data']

        id_list = []
        if 'id_list' in id_list_req:
            id_list = id_list_req["id_list"]

        if len(id_list) == 0:
            raise InvalidRequestException("id list can't be null")

        for id in id_list:
            target_result = target_dao.query_by_id(id)
            if target_result is None:
                raise ResourceNotFoundException("Can not found target.")

            target_dao.delete(target_result)

        self.on_success(resp)