def get_subscription(): user_id = request.args.get('userId') if not user_id: return error(ERROR_MISSING_REQUEST_PARAMS, 'user_id') result = esapi.es_get_subscription(user_id) return success(result)
def get_subscription(): user_id = request.args.get('userId') s = PriceSubscription.search() s = s.filter('term', userId=user_id) results = s.execute() return success(results['hits'].to_dict())
def set_subscription(sub_type, id): the_json = request.get_json() if not the_json: return error(ERROR_NO_INPUT_JSON_PROVIDED) # Validate and deserialize input try: sub_dict, _ = price_subscription_shema.load(the_json) except ValidationError as err: return error(ERROR_INVALID_INPUT_JSON, err.messages) # the update operation if id: sub_model = PriceSubscription.get(id=id, ignore=404) sub_dict['id'] = id if not sub_model: logger.warning('could not find subscription:{}'.format(id)) return error(ERROR_SUBSCRIPTION_NOT_FOUND, id) else: # generate securityId sub_dict['securityId'] = get_security_id(sub_dict['securityType'], sub_dict['exchange'], sub_dict['code']) # generate subscription id sub_dict['id'] = "{}_{}".format(sub_dict['userId'], sub_dict['securityId']) sub_dict['timestamp'] = to_time_str(datetime.now(), time_fmt=TIME_FORMAT_MICRO) sub_model = PriceSubscription(meta={'id': sub_dict['id']}) fill_doc_type(sub_model, sub_dict) sub_model.save(force=True) result_json = sub_model.to_dict(include_meta=True) logger.info('subscription:{} saved'.format(result_json)) resp = kafka_producer.send('subscription', bytes(json.dumps(sub_dict), encoding='utf8'), key=bytes(sub_dict['id'], encoding='utf8'), timestamp_ms=int( pd.Timestamp.now().timestamp() * 1000)) kafka_producer.flush() logger.info(resp) return success(payload=result_json)
def get_user_statistic(main_chain, user_id): start_date = request.args.get('start_date') end_date = request.args.get('end_date') security_id = request.args.get('security_id', 'cryptocurrency_contract_RAM-EOS') from_idx = request.args.get('from_idx', 0) size = request.args.get('size', 100) result = esapi.es_get_user_statistic(main_chain=main_chain, security_id=security_id, user_id=user_id, start_date=start_date, end_date=end_date, from_idx=int(from_idx), size=int(size)) return success(result)
def get_statistic(securityid): the_date = request.args.get('the_date') start_date = request.args.get('start_date') end_date = request.args.get('end_date') level = request.args.get('level', 'day') from_idx = request.args.get('from_idx', 0) size = request.args.get('size', 500) result = esapi.es_get_statistic(security_item=securityid, the_date=the_date, start_date=start_date, end_date=end_date, level=level, from_idx=int(from_idx), size=int(size)) return success(result)
def get_security(): security_type = request.args.get('securityType') exchange = request.args.get('exchange') if not exchange: exchange = SECURITY_TYPE_MAP_EXCHANGES[security_type] else: exchange = [exchange] if security_type == 'cryptocurrency': doc_type = CryptoCurrencyMeta s = doc_type().search() s = s.filter('terms', exchange=exchange).filter('terms', name=CRYPTOCURRENCY_PAIR) results = s.execute() return success(results['hits'].to_dict())
def get_kdata(securityid): the_date = request.args.get('the_date') start_date = request.args.get('start_date') end_date = request.args.get('end_date') level = request.args.get('level', 'day') fields = request.args.get('fields') if not fields: fields = ['open', 'high', 'low', 'close', 'volume'] from_idx = request.args.get('from_idx', 0) size = request.args.get('size', 10) result = esapi.es_get_kdata(security_item=securityid, the_date=the_date, start_date=start_date, end_date=end_date, fields=fields, csv=True, level=level, from_idx=int(from_idx), size=int(size)) return success(result)
def get_accounts(main_chain, user_id): start_vol = request.args.get('start_vol') end_vol = request.args.get('end_vol') from_idx = request.args.get('from_idx', 0) size = request.args.get('size', 100) order = request.args.get('order', 'totalEos') fields = get_request_params_as_list(request, 'fields') result = esapi.es_get_accounts(main_chain=main_chain, user_id=user_id, start_vol=int(start_vol), fields=fields, end_vol=int(end_vol), from_idx=int(from_idx), size=int(size), order=order) return success(result)
def set_subscription(id): the_json = request.get_json() if not the_json: return error(ERROR_NO_INPUT_JSON_PROVIDED) # Validate and deserialize input try: sub_dict, _ = price_subscription_shema.load(the_json) except ValidationError as err: return error(ERROR_INVALID_INPUT_JSON, err.messages) # the update operation if id: # FIXME:just check whether exist? sub_model = PriceSubscription.get(id=id, ignore=404) if not sub_model: logger.warning('could not find subscription:{}'.format(id)) return error(ERROR_SUBSCRIPTION_NOT_FOUND, id) else: sub_model = PriceSubscription() fill_doc_type(sub_model, the_json) sub_model.save(force=True) result_json = sub_model.to_dict(include_meta=True) logger.info('subscription:{} saved'.format(result_json)) resp = kafka_producer.send('subscription', bytes(json.dumps(result_json), encoding='utf8'), key=bytes(result_json['_id'], encoding='utf8'), timestamp_ms=int( pd.Timestamp.now().timestamp())) kafka_producer.flush() logger.info(resp) return success(payload=result_json)