def get_order_history_huobi(key, pair_name, time_start=0, time_end=get_now_seconds_utc()): post_details = get_order_history_huobi_post_details( key, pair_name, time_start, time_end) err_msg = "get_all_orders_huobi for {pair_name}".format( pair_name=pair_name) status_code, json_response = send_get_request_with_header( post_details.final_url, post_details.headers, err_msg, timeout=HUOBI_DEAL_TIMEOUT) if get_logging_level() >= LOG_ALL_DEBUG: msg = "get_order_history_huobi: {sc} {resp}".format(sc=status_code, resp=json_response) print_to_console(msg, LOG_ALL_DEBUG) log_to_file(msg, DEBUG_LOG_FILE_NAME) historical_orders = [] if status_code == STATUS.SUCCESS: status_code, historical_orders = get_orders_huobi_result_processor( json_response, pair_name) return status_code, historical_orders
def get_order_history_binance(key, pair_name, limit=BINANCE_ORDER_HISTORY_LIMIT, last_order_id=None): post_details = get_order_history_binance_post_details( key, pair_name, limit, last_order_id) err_msg = "get_all_orders_binance for {pair_name}".format( pair_name=pair_name) status_code, json_response = send_get_request_with_header( post_details.final_url, post_details.headers, err_msg, timeout=BINANCE_DEAL_TIMEOUT) if get_logging_level() >= LOG_ALL_DEBUG: msg = "get_order_history_binance: {sc} {resp}".format( sc=status_code, resp=json_response) print_to_console(msg, LOG_ALL_DEBUG) log_to_file(msg, DEBUG_LOG_FILE_NAME) historical_orders = [] if status_code == STATUS.SUCCESS: msg = "{fn} - error response - {er}".format( fn=get_order_history_binance.func_name, er=json_response) status_code, historical_orders = get_orders_binance_result_processor( json_response, pair_name, msg) return status_code, historical_orders
def cancel_order_bittrex(key, order_id): # https://bittrex.com/api/v1.1/market/cancel?apikey=API_KEY&uuid=ORDER_UUID final_url = BITTREX_CANCEL_ORDER + key.api_key + "&nonce=" + str( generate_nonce()) body = { "uuid": order_id, } final_url += _urlencode(body) headers = {"apisign": signed_string(final_url, key.secret)} post_details = PostRequestDetails(final_url, headers, body) if get_logging_level() >= LOG_ALL_MARKET_RELATED_CRAP: msg = "cancel_order_bittrex: {res}".format(res=post_details) print_to_console(msg, LOG_ALL_MARKET_RELATED_CRAP) log_to_file(msg, "market_utils.log") err_msg = "cancel bittrex order with id {id}".format(id=order_id) res = send_get_request_with_header(post_details.final_url, post_details.headers, err_msg, timeout=BITTREX_DEAL_TIMEOUT) if get_logging_level() >= LOG_ALL_MARKET_RELATED_CRAP: print_to_console(res, LOG_ALL_MARKET_RELATED_CRAP) log_to_file(res, "market_utils.log") return res
def add_sell_order_bittrex(key, pair_name, price, amount): post_details = add_sell_order_bittrex_url(key, pair_name, price, amount) err_msg = "add_sell_order bittrex called for {pair} for amount = {amount} with price {price}".format( pair=pair_name, amount=amount, price=price) res = send_get_request_with_header(post_details.final_url, post_details.headers, err_msg, timeout=BITTREX_DEAL_TIMEOUT) if get_logging_level() >= LOG_ALL_MARKET_RELATED_CRAP: print_to_console(res, LOG_ALL_MARKET_RELATED_CRAP) log_to_file(res, "market_utils.log") return res
def get_order_history_bittrex(key, pair_name): post_details = get_order_history_bittrex_post_details(key, pair_name) err_msg = "get bittrex order history for time interval for pp={pp}".format( pp=post_details) status_code, json_response = send_get_request_with_header( post_details.final_url, post_details.headers, err_msg) historical_orders = [] if status_code == STATUS.SUCCESS: status_code, historical_orders = get_order_history_bittrex_result_processor( json_response, pair_name) return status_code, historical_orders
def get_balance_huobi(key): post_details = get_balance_huobi_post_details(key) err_msg = "check huobi balance called" timest = get_now_seconds_utc() status_code, res = send_get_request_with_header( post_details.final_url, post_details.headers, err_msg, timeout=HUOBI_DEAL_TIMEOUT) if get_logging_level() >= LOG_ALL_DEBUG: log_to_file(res, "balance.log") if status_code == STATUS.SUCCESS: status_code, res = get_balance_huobi_result_processor(res, timest) return status_code, res
def get_open_orders_binance(key, pair_name): post_details = get_open_orders_binance_post_details(key, pair_name) err_msg = "get_orders_binance" status_code, res = send_get_request_with_header( post_details.final_url, post_details.headers, err_msg, timeout=BINANCE_DEAL_TIMEOUT) if get_logging_level() >= LOG_ALL_DEBUG: msg = "get_open_orders_binance: {r}".format(r=res) print_to_console(msg, LOG_ALL_DEBUG) log_to_file(msg, DEBUG_LOG_FILE_NAME) orders = [] if status_code == STATUS.SUCCESS: status_code, orders = get_open_orders_binance_result_processor( res, pair_name) return status_code, orders
def get_huobi_account_impl(key): final_url = HUOBI_API_URL + HUOBI_GET_ACCOUNT_INFO + "?" body, url = generate_body_and_url_get_request(key, HUOBI_API_ONLY, HUOBI_GET_ACCOUNT_INFO) final_url += url post_details = PostRequestDetails(final_url, HUOBI_GET_HEADERS, body) err_msg = "get_huobi_account" error_code, res = send_get_request_with_header(post_details.final_url, post_details.headers, err_msg, timeout=HUOBI_DEAL_TIMEOUT) # {u'status': u'ok', u'data': [{u'subtype': u'', u'state': u'working', u'type': u'spot', u'id': 1245038}]} if error_code == STATUS.SUCCESS and "data" in res and len(res["data"]) > 0: return res["data"][0]["id"] return None
def get_trades_history_binance(key, pair_name, limit, last_order_id=None): final_url = BINANCE_GET_ALL_TRADES body = [] if last_order_id is not None: body.append(("fromId", last_order_id)) body.append(("symbol", pair_name)) body.append(("limit", limit)) body.append(("timestamp", get_now_seconds_utc_ms())) body.append(("recvWindow", 5000)) body.append(("signature", signed_body_256(body, key.secret))) post_details = generate_post_request(final_url, body, key) if get_logging_level() >= LOG_ALL_DEBUG: msg = "get_trades_history_binance: {res}".format(res=post_details) print_to_console(msg, LOG_ALL_DEBUG) log_to_file(msg, DEBUG_LOG_FILE_NAME) err_msg = "get_all_trades_binance for {pair_name}".format( pair_name=pair_name) error_code, res = send_get_request_with_header( post_details.final_url, post_details.headers, err_msg, timeout=BINANCE_DEAL_TIMEOUT) if get_logging_level() >= LOG_ALL_DEBUG: msg = "get_all_trades_binance: {er_c} {r}".format(er_c=error_code, r=res) print_to_console(msg, LOG_ALL_DEBUG) log_to_file(msg, DEBUG_LOG_FILE_NAME) return error_code, res