def get_balance_poloniex(key): """ https://poloniex.com/tradingApi {'Key': 'QN6SDFQG-XVG2CGG3-WDDG2WDV-VXZ7MYL3', 'Sign': '368a800fcd4bc0f0d95151ed29c9f84ddf6cae6bc366d3105db1560318da72aa82281b5ea52f4d4ec929dd0eabc7339fe0e7dc824bf0f1c64e099344cd6e74d0'} {'nonce': 1508507033330, 'command': 'returnCompleteBalances'} {"LTC":{"available":"5.015","onOrders":"1.0025","btcValue":"0.078"},"NXT:{...} ... } """ post_details = get_balance_poloniex_post_details(key) err_msg = "check poloniex balance called" timest = get_now_seconds_utc() error_code, res = send_post_request_with_header( post_details, err_msg, max_tries=POLONIEX_NUM_OF_DEAL_RETRY, timeout=POLONIEX_DEAL_TIMEOUT) if error_code == STATUS.SUCCESS: res = Balance.from_poloniex(timest, res) return error_code, res
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
def get_balance_poloniex_result_processor(json_document, timest): if is_error(json_document): msg = "get_balance_poloniex_result_processor - error response - {er}".format( er=json_document) log_to_file(msg, ERROR_LOG_FILE_NAME) return None return Balance.from_poloniex(timest, json_document)
def get_balance_bittrex_result_processor(json_document, timest): if is_error(json_document) or len(json_document["result"]) < 1: msg = "get_balance_bittrex_result_processor - error response - {er}".format( er=json_document) log_to_file(msg, ERROR_LOG_FILE_NAME) return STATUS.FAILURE, None return STATUS.SUCCESS, Balance.from_bittrex(timest, json_document["result"])
def custom_balance_init(timest): balance = {} poloniex_balance = {CURRENCY.BITCOIN: 10.0, CURRENCY.DASH: 15.0, CURRENCY.BCC: 13.0, CURRENCY.XRP: 30000.0, CURRENCY.LTC: 100.0, CURRENCY.ETC: 600.0, CURRENCY.ETH: 20.0} balance[EXCHANGE.POLONIEX] = Balance(EXCHANGE.POLONIEX, timest, poloniex_balance, poloniex_balance) kraken_balance = {CURRENCY.BITCOIN: 10.0, CURRENCY.DASH: 15.0, CURRENCY.BCC: 13.0, CURRENCY.XRP: 30000.0, CURRENCY.LTC: 100.0, CURRENCY.ETC: 600.0, CURRENCY.ETH: 20.0} balance[EXCHANGE.KRAKEN] = Balance(EXCHANGE.KRAKEN, timest, kraken_balance, kraken_balance) bittrex_balance = {CURRENCY.BITCOIN: 10.0, CURRENCY.DASH: 15.0, CURRENCY.BCC: 13.0, CURRENCY.XRP: 30000.0, CURRENCY.LTC: 100.0, CURRENCY.ETC: 600.0, CURRENCY.ETH: 20.0} balance[EXCHANGE.BITTREX] = Balance(EXCHANGE.BITTREX, timest, bittrex_balance, bittrex_balance) # Just a self check to guarantee that our cap is up to date with active list of arbitrage currencies print("\t \t <<< ! ERROR ! >>> \n" "If this is one of the LAST message in stack trace it mean that deal Cap and Arbitrage currencies not update!") assert (len(ARBITRAGE_CURRENCY) == len(poloniex_balance)) return BalanceState(balance)
def dummy_balance_init(timest, default_volume, default_available_volume): balance = {} total_balance = {} available_balance = {} for currency_id in ARBITRAGE_CURRENCY: total_balance[currency_id] = default_volume for currency_id in ARBITRAGE_CURRENCY: available_balance[currency_id] = default_available_volume for exchange_id in EXCHANGE.values(): balance[exchange_id] = Balance(exchange_id, timest, available_balance, total_balance) return BalanceState(balance)
def get_balance(self, accountKey): response_json = self.get(urls.balance_url + accountKey) return Balance(response_json['a'])