Esempio n. 1
0
def get_balance_huobi_result_processor(json_document, timest):
    if not is_error(json_document) and "data" in json_document and json_document["data"]:
        return STATUS.SUCCESS, Balance.from_huobi(timest, json_document["data"])

    msg = "get_balance_huobi_result_processor - error response - {er}".format(er=json_document)
    log_to_file(msg, ERROR_LOG_FILE_NAME)

    return STATUS.FAILURE, None
Esempio n. 2
0
def get_ticker_huobi_result_processor(json_document, pair_name, timest):
    if is_error(json_document) or json_document.get("tick") is None:

        msg = "get_ticker_huobi_result_processor - error response - {er}".format(
            er=json_document)
        log_to_file(msg, ERROR_LOG_FILE_NAME)

        return None

    return Ticker.from_huobi(pair_name, timest, json_document["tick"])
Esempio n. 3
0
def get_history_huobi_result_processor(json_document, pair_name, timest):
    all_history_records = []

    if is_error(json_document) or "data" not in json_document:

        msg = "get_history_huobi_result_processor - error response - {er}".format(
            er=json_document)
        log_to_file(msg, ERROR_LOG_FILE_NAME)

        return all_history_records

    for entry in json_document["data"]:
        for record in entry["data"]:
            all_history_records.append(
                TradeHistory.from_huobi(record, pair_name, timest))

    return all_history_records
Esempio n. 4
0
def parse_order_id_huobi(json_document):
    """
    {
        "status": "ok",
        "data": "59378"
    }
    """

    if is_error(json_document) or "data" not in json_document:

        msg = "parse_order_id_huobi - error response - {er}".format(
            er=json_document)
        log_to_file(msg, ERROR_LOG_FILE_NAME)

        return None

    return str(json_document["data"])
Esempio n. 5
0
def get_ohlc_huobi_result_processor(json_response, pair_name, date_start,
                                    date_end):
    """
        {
          "status": "ok",
          "ch": "market.btcusdt.kline.1day",
          "ts": 1499223904680,
          “data”: [
            {
                "id": 1499184000,
                "amount": 37593.0266,
                "count": 0,
                "open": 1935.2000,
                "close": 1879.0000,
                "low": 1856.0000,
                "high": 1940.0000,
                "vol": 71031537.97866500
            },
            // more data here
            ]
        }
    """
    result_set = []

    if is_error(json_response) or "data" not in json_response:

        msg = "get_ohlc_huobi_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["data"]:
        record["artifical_ts"] = json_response["ts"]
        result_set.append(Candle.from_huobi(record, pair_name))

    return result_set