def get_history_binance_result_processor(json_document, pair_name, timest): """ { "a": 26129, // Aggregate tradeId "p": "0.01633102", // Price "q": "4.70443515", // Quantity "f": 27781, // First tradeId "l": 27781, // Last tradeId "T": 1498793709153, // Timestamp "m": true, // Was the buyer the maker? "M": true // Was the trade the best price match? } """ all_history_records = [] if is_error(json_document): msg = "get_history_binance_result_processor - error response - {er}".format( er=json_document) log_to_file(msg, ERROR_LOG_FILE_NAME) return all_history_records for record in json_document: all_history_records.append( TradeHistory.from_binance(record, pair_name, timest)) return all_history_records
def get_ohlc_binance_result_processor(json_response, currency, date_start, date_end): """ [ 1499040000000, // Open time "0.01634790", // Open "0.80000000", // High "0.01575800", // Low "0.01577100", // Close "148976.11427815", // Volume 1499644799999, // Close time "2434.19055334", // Quote asset volume 308, // Number of trades "1756.87402397", // Taker buy base asset volume "28.46694368", // Taker buy quote asset volume "17928899.62484339" // Can be ignored ] """ result_set = [] if is_error(json_response): msg = "get_ohlc_binance_result_processor - error response - {er}".format( er=json_response) log_to_file(msg, ERROR_LOG_FILE_NAME) return result_set for record in json_response: result_set.append(Candle.from_binance(record, currency)) return result_set
def parse_order_id_binance(json_document): """ {u'orderId': 6599290, u'clientOrderId': u'oGDxv6VeLXRdvUA8PiK8KR', u'origQty': u'27.79000000', u'symbol': u'OMGBTC', u'side': u'SELL', u'timeInForce': u'GTC', u'status': u'FILLED', u'transactTime': 1514223327566, u'type': u'LIMIT', u'price': u'0.00111100', u'executedQty': u'27.79000000'} """ if is_error(json_document): msg = "parse_order_id_binance - error response - {er}".format( er=json_document) log_to_file(msg, ERROR_LOG_FILE_NAME) return None if "orderId" in json_document: return json_document["orderId"] return None
def get_balance_binance_result_processor(json_document, timest): if not is_error(json_document) and "balances" in json_document: return STATUS.SUCCESS, Balance.from_binance(timest, json_document) msg = "get_balance_binance_result_processor - error response - {er}".format( er=json_document) log_to_file(msg, ERROR_LOG_FILE_NAME) return STATUS.FAILURE, None
def get_order_book_binance_result_processor(json_document, pair_name, timest): if is_error(json_document): msg = "get_order_book_binance_result_processor - error response - {er}".format( er=json_document) log_to_file(msg, ERROR_LOG_FILE_NAME) return None return OrderBook.from_binance(json_document, pair_name, timest)
def get_ticker_binance_result_processor(json_document, pair_name, timest): if is_error(json_document): msg = "get_ticker_binance_result_processor - error response - {er}".format( er=json_document) log_to_file(msg, ERROR_LOG_FILE_NAME) return None for entry in json_document: if pair_name in entry["symbol"]: return Ticker.from_binance(entry["symbol"], timest, entry) return None
def get_orders_binance_result_processor(msg, json_document, pair_name): """ json_document - response from exchange api as json string pair_name - for backwards compatibilities """ orders = [] if is_error(json_document): log_to_file(msg, ERROR_LOG_FILE_NAME) return STATUS.FAILURE, orders for entry in json_document: order = Trade.from_binance(entry) if order is not None: orders.append(order) return STATUS.SUCCESS, orders