def json_parse(data): obj = OrderChangeEvent() if isinstance(data[0], list): data = data[0] obj.timestamp = Utils.safe_integer(data, 3) obj.data = [OrderChange.json_parse(item) for item in data[4]] obj.data_size = len(obj.data) else: obj.timestamp = Utils.safe_integer(data, 3) obj.data = [OrderChange.json_parse(data[4:])] obj.data_size = 1 return obj
def json_parse(json_object): data_obj = PriceDepth() data_obj.timestamp = Utils.safe_integer(json_object, 'timestamp') data_obj.asks = [DepthEntry.json_parse(e) for e in json_object['asks']] data_obj.bids = [DepthEntry.json_parse(e) for e in json_object['bids']] return data_obj
def json_parse(json_array): trade = Trade() trade.price = Utils.safe_float(json_array, 5) trade.amount = Utils.safe_float(json_array, 6) trade.side = 'buy' if Utils.safe_string(json_array, 4) == 'bid' else 'sell' trade.timestamp = Utils.safe_integer(json_array, 2) return trade
def json_parse(data): obj = PriceDepthEvent() if isinstance(data[0], list): data = data[0] obj.timestamp = Utils.safe_integer(data, 3) obj.data = { 'asks': [DepthEntry.json_parse(e) for e in data[4]['asks']], 'bids': [DepthEntry.json_parse(e) for e in data[5]['bids']] } else: obj.data_type = 'E' obj.timestamp = Utils.safe_integer(data, 2) obj.data = { 'side': 'buy' if 'bid' == Utils.safe_string(data, 4).lower() else 'sell', 'price': Utils.safe_float(data, 5), 'amount': Utils.safe_float(data, 6), } return obj
def json_parse(item): order = OrderChange() order.order_id = item[0] order.side = 'buy' if Utils.safe_integer(item, 1) == 1 else 'sell' # status : 0:craeted 1:canceled 2: filled 3:partial-filled status = Utils.safe_integer(item, 2) if status == 0: order.status = 'created' elif status == 1: order.status = 'canceled' elif status == 2: order.status = 'filled' elif status == 3: order.status = 'partial-filled' order.price = Utils.safe_float(item, 3) order.amount = Utils.safe_float(item, 4) order.filled_amount = Utils.safe_float(item, 5, 0.0) order.filled_cash_amount = Utils.safe_float(item, 6, 0.0) order.avg_amount = Utils.safe_float(item, 7, 0.0) order.timestamp = Utils.safe_integer(item, 8) return order