class TestBittrexMarketAPI(unittest.TestCase): def setUp(self): self.bittrex = Bittrex() def test_secret_and_key(self): try: os.environ['BITTREX_KEY'] os.environ['BITTREX_SECRET'] except KeyError: self.fail("Requires BITTREX_KEY and BITTREX_SECRET env variables") def test_buy_limit(self): self.assertRaises(TypeError, self.bittrex.buy_limit) actual = self.bittrex.buy_limit('BTC-LTC', 1, 1) test_response_structure(self, actual, 'buy_limit') def test_sell_limit(self): self.assertRaises(TypeError, self.bittrex.buy_limit) actual = self.bittrex.sell_limit('BTC-LTC', 1, 1) test_response_structure(self, actual, 'sell_limit') def test_cancel(self): self.assertRaises(TypeError, self.bittrex.cancel) # provide invalid uuid but test the json structure actual = self.bittrex.cancel('BTC-LTC') test_response_structure(self, actual, 'cancel') def test_open_orders(self): invalid_actual = self.bittrex.get_open_orders('Invalid Market') no_param_actual = self.bittrex.get_open_orders() actual = self.bittrex.get_open_orders('BTC-LTC') test_failed_response(self, invalid_actual, 'get_open_orders') test_basic_response(self, no_param_actual, 'get_open_orders') test_basic_response(self, actual, 'get_open_orders')
class TestBittrexV20AccountAPI(unittest.TestCase): """ Integration tests for the Bittrex Account API. * These will fail in the absence of an internet connection or if bittrex API goes down. * They require a valid API key and secret issued by Bittrex. * They also require the presence of a JSON file called secrets.json. It is structured as such: { "key": "12341253456345", "secret": "3345745634234534" } """ def setUp(self): with open("secrets.json") as secrets_file: self.secrets = json.load(secrets_file) secrets_file.close() self.bittrex = Bittrex(self.secrets['key'], self.secrets['secret'], api_version=API_V2_0) def test_handles_invalid_key_or_secret(self): self.bittrex = Bittrex('invalidkey', self.secrets['secret'], api_version=API_V2_0) actual = self.bittrex.get_balance('BTC') test_auth_basic_failures(self, actual, 'Invalid key, valid secret') self.bittrex = Bittrex(None, self.secrets['secret'], api_version=API_V2_0) actual = self.bittrex.get_balance('BTC') test_auth_basic_failures(self, actual, 'None key, valid secret') self.bittrex = Bittrex(self.secrets['key'], 'invalidsecret', api_version=API_V2_0) actual = self.bittrex.get_balance('BTC') test_auth_basic_failures(self, actual, 'valid key, invalid secret') self.bittrex = Bittrex(self.secrets['key'], None, api_version=API_V2_0) actual = self.bittrex.get_balance('BTC') test_auth_basic_failures(self, actual, 'valid key, None secret') self.bittrex = Bittrex('invalidkey', 'invalidsecret', api_version=API_V2_0) actual = self.bittrex.get_balance('BTC') test_auth_basic_failures(self, actual, 'invalid key, invalid secret') def test_get_openorders(self): actual = self.bittrex.get_open_orders('BTC-LTC') test_basic_response(self, actual, "get_openorders") self.assertTrue(isinstance(actual['result'], list), "result is not a list") def test_get_balances(self): actual = self.bittrex.get_balances() test_basic_response(self, actual, "get_balances") self.assertTrue(isinstance(actual['result'], list), "result is not a list") @unittest.skip( "the return result is an empty dict. API bug? the 2.0 get_balances works as expected" ) def test_get_balance(self): actual = self.bittrex.get_balance('BTC') test_basic_response(self, actual, "get_balance") self.assertTrue(isinstance(actual['result'], dict), "result is not a dict") self.assertEqual( actual['result']['Currency'], "BTC", "requested currency {0:s} does not match returned currency {1:s}". format("BTC", actual['result']['Currency'])) @unittest.skip("my testing account is acting funny this should work") def test_get_depositaddress(self): actual = self.bittrex.get_deposit_address('BTC') test_basic_response(self, actual, "get_deposit_address") def test_get_order_history_all_markets(self): actual = self.bittrex.get_order_history() test_basic_response(self, actual, "get_order_history") self.assertIsInstance(actual['result'], list, "result is not a list") def test_get_order_history_one_market(self): actual = self.bittrex.get_order_history(market='BTC-LTC') test_basic_response(self, actual, "get_order_history") self.assertIsInstance(actual['result'], list, "result is not a list") def test_get_withdrawlhistory_all_currencies(self): actual = self.bittrex.get_withdrawal_history() test_basic_response(self, actual, "get_withdrawal_history") self.assertIsInstance(actual['result'], list, "result is not a list") def test_get_withdrawlhistory_one_currency(self): actual = self.bittrex.get_withdrawal_history('BTC') test_basic_response(self, actual, "get_withdrawal_history") self.assertIsInstance(actual['result'], list, "result is not a list") def test_get_deposithistory_all_currencies(self): actual = self.bittrex.get_deposit_history() test_basic_response(self, actual, "get_deposit_history") self.assertIsInstance(actual['result'], list, "result is not a list") def test_get_deposithistory_one_currency(self): actual = self.bittrex.get_deposit_history('BTC') test_basic_response(self, actual, "get_deposit_history") self.assertIsInstance(actual['result'], list, "result is not a list") def test_get_pending_withdrawals_all_currencies(self): actual = self.bittrex.get_pending_withdrawals() test_basic_response(self, actual, "get_pending_withdrawals") self.assertIsInstance(actual['result'], list, "result is not a list") def test_get_pending_withdrawals_one_currency(self): actual = self.bittrex.get_pending_withdrawals('BTC') test_basic_response(self, actual, "get_pending_withdrawals") self.assertIsInstance(actual['result'], list, "result is not a list") def test_get_pending_deposits_all_currencies(self): actual = self.bittrex.get_pending_deposits() test_basic_response(self, actual, "get_pending_deposits") self.assertIsInstance(actual['result'], list, "result is not a list") def test_get_pending_deposits_one_currency(self): actual = self.bittrex.get_pending_deposits('BTC') test_basic_response(self, actual, "get_pending_deposits") self.assertIsInstance(actual['result'], list, "result is not a list") def test_generate_deposit_address(self): actual = self.bittrex.generate_deposit_address(currency='BTC') test_basic_response(self, actual, "generate_deposit_address") self.assertIsInstance(actual['result'], list, "result is not a list")
class TestBittrexV11AccountAPI(unittest.TestCase): """ Integration tests for the Bittrex Account API. * These will fail in the absence of an internet connection or if bittrex API goes down. * They require a valid API key and secret issued by Bittrex. * They also require the presence of a JSON file called secrets.json. It is structured as such: { "key": "12341253456345", "secret": "3345745634234534" } """ def setUp(self): with open("secrets.json") as secrets_file: self.secrets = json.load(secrets_file) secrets_file.close() self.bittrex = Bittrex(self.secrets['key'], self.secrets['secret']) def test_handles_invalid_key_or_secret(self): self.bittrex = Bittrex('invalidkey', self.secrets['secret']) actual = self.bittrex.get_balance('BTC') test_auth_basic_failures(self, actual, 'Invalid key, valid secret') self.bittrex = Bittrex(None, self.secrets['secret']) actual = self.bittrex.get_balance('BTC') test_auth_basic_failures(self, actual, 'None key, valid secret') self.bittrex = Bittrex(self.secrets['key'], 'invalidsecret') actual = self.bittrex.get_balance('BTC') test_auth_basic_failures(self, actual, 'valid key, invalid secret') self.bittrex = Bittrex(self.secrets['key'], None) actual = self.bittrex.get_balance('BTC') test_auth_basic_failures(self, actual, 'valid key, None secret') self.bittrex = Bittrex('invalidkey', 'invalidsecret') actual = self.bittrex.get_balance('BTC') test_auth_basic_failures(self, actual, 'invalid key, invalid secret') def test_get_openorders(self): actual = self.bittrex.get_open_orders('BTC-LTC') test_basic_response(self, actual, "get_openorders") self.assertTrue(isinstance(actual['result'], list), "result is not a list") def test_get_balances(self): actual = self.bittrex.get_balances() test_basic_response(self, actual, "get_balances") self.assertTrue(isinstance(actual['result'], list), "result is not a list") def test_get_balance(self): actual = self.bittrex.get_balance('BTC') test_basic_response(self, actual, "get_balance") self.assertTrue(isinstance(actual['result'], dict), "result is not a dict") self.assertEqual( actual['result']['Currency'], "BTC", "requested currency {0:s} does not match returned currency {1:s}". format("BTC", actual['result']['Currency'])) def test_get_depositaddress(self): actual = self.bittrex.get_deposit_address('BTC') if not actual['success']: self.assertTrue(actual['message'], 'ADDRESS_GENERATING') else: test_basic_response(self, actual, "get_deposit_address") def test_get_order_history_all_markets(self): actual = self.bittrex.get_order_history() test_basic_response(self, actual, "get_order_history") self.assertIsInstance(actual['result'], list, "result is not a list") def test_get_order_history_one_market(self): actual = self.bittrex.get_order_history(market='BTC-LTC') test_basic_response(self, actual, "get_order_history") self.assertIsInstance(actual['result'], list, "result is not a list") def test_get_withdrawlhistory_all_currencies(self): actual = self.bittrex.get_withdrawal_history() test_basic_response(self, actual, "get_withdrawal_history") self.assertIsInstance(actual['result'], list, "result is not a list") def test_get_withdrawlhistory_one_currency(self): actual = self.bittrex.get_withdrawal_history('BTC') test_basic_response(self, actual, "get_withdrawal_history") self.assertIsInstance(actual['result'], list, "result is not a list") def test_get_deposithistory_all_currencies(self): actual = self.bittrex.get_deposit_history() test_basic_response(self, actual, "get_deposit_history") self.assertIsInstance(actual['result'], list, "result is not a list") def test_get_deposithistory_one_currency(self): actual = self.bittrex.get_deposit_history('BTC') test_basic_response(self, actual, "get_deposit_history") self.assertIsInstance(actual['result'], list, "result is not a list") def test_get_pending_withdrawals(self): self.assertRaisesRegexp(Exception, 'method call not available', self.bittrex.get_pending_withdrawals) def test_get_pending_deposits(self): self.assertRaisesRegexp(Exception, 'method call not available', self.bittrex.get_pending_deposits) def test_generate_deposit_address(self): self.assertRaisesRegexp(Exception, 'method call not available', self.bittrex.generate_deposit_address, currency='BTC')
def mainrun(): if Path(PATH+'currencyretain.pickle').is_file(): remaining = pickle.load(open(PATH+'currencyretain.pickle','rb')) else: remaining = OrderedDict() BTX = Bittrex(key=apikey,secret=apisecret) blockPrint() balances = BTX.get_balances()['result'] orders = BTX.get_open_orders()['result'] enablePrint() waitingon = [] for ORDS in orders: EX = ORDS["Exchange"] TYPE = ORDS["OrderType"] if (SelltoCurrency in EX) and ('BUY' in TYPE): continue elif (orderwait==1) and (SelltoCurrency not in EX): EX = EX.replace(SelltoCurrency+'-','') EX = EX.replace('-'+SelltoCurrency,'') if EX not in EX: waitingon.append(EX) else: continue for BAL in balances: Currency = BAL["Currency"] Available = BAL["Available"] if Currency in retainspec.keys(): retained = retainspec[Currency] else: retained = retainednorm if retentionROI == 1: ROI = 1.00 + retained + retained**2 + retained**3 + retained**4 else: ROI = ROI if Currency in remaining.keys(): CurrencyHold = remaining[Currency] Available = Available - CurrencyHold else: CurrencyHold = 0.00 if (Currency not in waitingon) and (Currency != SelltoCurrency) and ( (Available + CurrencyHold) > (CurrencyHold + Minimumtradeorder) ): Quantitytosell = (Available-(retained*Available)) blockPrint() price = BTX.get_market_history(SelltoCurrency+'-'+Currency)['result'][0]["Price"] enablePrint() #Take into account the initial fee zerofeeamount = ( price ) / (1-bidFee) Netprice = (zerofeeamount*ROI) / (1-askFee) if (Quantitytosell*price) > Minimumtradeorder: BTX.sell_limit(SelltoCurrency+'-'+Currency,Quantitytosell,Netprice) #Make sure to 'Hold' the amount remaining until it goes above this amount. remaining[Currency] = retained*Available + CurrencyHold pickle_out = open(PATH+'currencyretain.pickle','wb') pickle.dump(remaining,pickle_out) pickle_out.close() else: print("Minimum Trade order is: "+ str(Minimumtradeorder) + " " + SelltoCurrency + ", You tried to sell: " + str(Quantitytosell*price) + " " + SelltoCurrency + " Worth.")
class TradeBot(): def __init__(self, key=None, secret=None, **kwargs): self.exchange = Bittrex(key, secret) self.orders = [] # Default config config = { 'base_currency': 'ETH', 'min_order': 0.001, 'max_order': 0.05, 'sleep_time': 60, 'profit': 2, 'min_volume': 75, 'max_units': 100 } # Update config from object constructor config.update(kwargs) # Set attributes based on config for attr in config.keys(): setattr(self, attr, config[attr]) def get_markets(self): logging.info(f'Getting markets for {self.base_currency}') all_markets = self.exchange.get_markets()['result'] markets = set() for mkt in all_markets: if mkt['BaseCurrency'] == self.base_currency: markets.add(mkt['MarketName']) return markets def get_coins_with_open_orders(self): open_orders = self.exchange.get_open_orders()['result'] if len(open_orders) == 0: return [] else: return [x['Exchange'] for x in open_orders] def get_market_data(self): mkt_data = [] for mkt in self.markets: logging.info(f'Getting market data for {mkt}') data = self.exchange.get_marketsummary(mkt)['result'][0] data['Change'] = calculate_change(data['Last'], data['Low']) mkt_data.append(data) return mkt_data def has_balance_to_buy(self): logging.info('checking if we have some balance to buy') q = self.exchange.get_balance(self.base_currency) # balance_adjustment to avoid INSUFFICIENT FUNDS MESSAGE balance_adjustment = 0.0005 self.balance = q['result']['Available'] - balance_adjustment logging.debug(f'{self.balance}{self.base_currency} available') if self.balance >= self.min_order: return True else: return False def get_market_to_buy(self): self.update() mkt = [ m for m in self.market_data if m['BaseVolume'] >= self.min_volume ] sorted_mkt = sorted(mkt, key=lambda x: x['BaseVolume'], reverse=True) while sorted_mkt[0]['MarketName'] in self.coins_with_open_orders: sorted_mkt.pop(0) return sorted_mkt[0] def buy(self, mkt): coin = mkt['MarketName'] # get a price between ask and bid price = (mkt['Ask'] + mkt['Bid']) / 2 if self.balance > self.max_order: qnt = self.max_order / price else: qnt = self.balance / price if qnt > self.max_units: qnt = self.max_units if (qnt * price) < self.min_order: qnt = self.min_order / price logging.info(f'BUY {qnt} {coin} - price {price}, total {price * qnt}') order = self.exchange.buy_limit(coin, qnt, price) if order['success']: self.orders.append(order['result']['uuid']) else: logging.error(f'BUY FAIL - {order}') return (order) def sell(self): for order in self.orders: order_info = self.exchange.get_order(order)['result'] if order_info['Closed']: coin = order_info['Exchange'] qnt = order_info['Quantity'] price = profit(order_info['PricePerUnit'], self.profit) sell_order = self.exchange.sell_limit(coin, qnt, price) self.orders.remove(order) logging.info(f'SELL {order} {sell_order}') def update(self): logging.info('Updating data') self.markets = self.get_markets() self.market_data = self.get_market_data() self.coins_with_open_orders = self.get_coins_with_open_orders() def do_trade(self): if self.has_balance_to_buy(): self.buy(self.get_market_to_buy()) if len(self.orders) > 0: self.sell() logging.info(f'Sleeping for {self.sleep_time} seconds') sleep(self.sleep_time) def run(self): logging.info('Starting Bot') while True: self.do_trade()
class BittrexBuysellWorker(object): def __init__(self, key=None, secret=None, token=None): self.EXCHANGE_RATE = 0.9975 # 0.25% for each trading transaction self.api = Bittrex(key, secret) self.token = token try: m = self.api.get_market_summaries() #print m market_list = [] for market in m.get("result"): market_list.append(market.get("MarketName")) #print marketlist except: print "Error: Cannot get market summaries" exit(1) self.market_list = market_list def w_get_api(self): """ Get balance of a coin :return: api Bittrex.py :rtype : Bittrex class """ return self.api def w_get_balance(self, coin): """ Get balance of a coin :return: current balance value :rtype : float """ try: m = self.api.get_balance(coin) print m if (m.get("success")): v = m.get("result").get("Balance") return v if v else 0 else: print("Cannot get {} balance".format(coin)) return ERROR.CMD_UNSUCCESS except: print("Error Account/Connection issue. Get {} balance failed". format(coin)) return ERROR.CONNECTION_FAIL def w_get_market_name(self, coin1, coin2): """ Get marketname for pair of coins :param coin1: String literal for coin 1 (ex: USDT) :param coin2: String literal for coin 2 (ex: XMR) :return: (MarketName, "Buy"/"Sell") :rtype : str """ market = coin1 + "-" + coin2 if market in self.market_list: return (market, "Buy") else: market = coin2 + "-" + coin1 if market in self.market_list: return (market, "Sell") else: print "Error: Invalid coin pair" return (None, None) def w_get_price(self, market, type, unit=0, depth=20): """ Get price Ask Last Bid :param market: String literal for coin1-coin2 (ex: USDT-XMR) :param type: Ask/Last/Bid :param unit: if unit != 0, get price with respect to order book :return: price :rtype : float """ if type is "Last" or "Bid" or "Ask": try: price = self.api.get_marketsummary(market).get( "result")[0].get(type) if type == "Ask": ordertype = "sell" elif type == "Bid": ordertype = "buy" else: #Dont need to check order book for Last return price m = self.api.get_orderbook(market, ordertype, depth) #print m if (m.get("message") != ""): print "Fail to get order book of {}: {}".format( market, m.get("message")) return ERROR.CMD_UNSUCCESS else: order_price_list = m.get("result") #print order_price_list sum_quantity = 0 for o in order_price_list: #print o quantity = o.get("Quantity") price = o.get("Rate") sum_quantity += quantity if (sum_quantity >= unit): return price except: print("Error in get {} price".format(market)) return ERROR.CONNECTION_FAIL else: print("Invalid type of market (Ask/Bid/Last)") return ERROR.PARAMETERS_INVALID '''To do: unit != 0''' def w_get_open_order(self, market=None): """ Get list of uuid of open orders :param market: String literal for coin1-coin2 (ex: USDT-XMR) :return: uuid list :rtype : str """ return self.api.get_open_orders(market) def w_order_buy_sell(self, coin1, coin2, value1, price, timeout, cancel_on_timeout=True): """ Buy/Sell from coin c1 to coin coin2 at price :param coin1: String literal for coin 1 (ex: USDT) :param coin2: String literal for coin 2 (ex: XMR) :param value1: The value of coin1 which is used to buy/sell :param price: buy/sell price, can be Ask, Last or Bid :return: uuid order :rtype : str """ value2_before = self.w_get_balance(coin2) #get current coin2 balance market, type = self.w_get_market_name(coin1, coin2) #print market, type #Buy and sell are seperated from market point of view. if (type == "Buy"): order_buy_sell = self.api.buy_limit quantity = value1 / price * self.EXCHANGE_RATE value2 = quantity * self.EXCHANGE_RATE elif (type) == "Sell": order_buy_sell = self.api.sell_limit quantity = value1 value2 = quantity * price * self.EXCHANGE_RATE else: print "Buy/Sell Error: Invalid market {}-{}".format(coin1, coin2) return ERROR.CMD_INVALID print("@@@ From {} {} buy {} {} at price {}.".format( value1, coin1, value2, coin2, price)) #Process buy/sell within timeout #Several posible cases: # 1. The price is too high/low, no one wants to buy/sell # 2. The connection drops while waiting the result # 3. The quantity is too low -> "INSUFFICIENT_FUNDS" response from server try: m = order_buy_sell(market, quantity, price) if (m.get("success") == True): uuid = m.get("result").get("uuid") process_time = time.time() + timeout while 1: value2_after = self.w_get_balance(coin2) if time.time() > process_time: if cancel_on_timeout: #Cancel order because of timeout self.w_cancel_order(uuid) print "Cancel order!" else: print "Order is still open!" return uuid print "{} transaction was timeout".format(type) return ERROR.TIME_OUT if (value2_after < 0): #Error print "Error: in balance code {}".format(value2_after) return ERROR.CMD_UNSUCCESS if (value2_after - value2_before >= value2 * 0.9): #offset 10% for safety #buy success return uuid elif m.get("message") == "INSUFFICIENT_FUNDS": print("INSUFFICIENT_FUNDS issue") print m return ERROR.PARAMETERS_INVALID else: print m return ERROR.CMD_UNSUCCESS except: print "Error buy/sell. Conection failed." return ERROR.CONNECTION_FAIL def w_cancel_order(self, uuid): """ Cancel an order via uuid :param uuid: order uuid :return: error code :rtype : ERROR """ try: #todo: need check timeout self.api.cancel(uuid) while uuid in self.api.get_open_orders(): print "Wait for cancel order {}".format(uuid) return ERROR.CMD_SUCCESS except: print "Cannot cancel order {}".format(uuid) return ERROR.CONNECTION_FAIL def w_get_price_by_order_book(self, market, ordertype, value, depth=20): """ Get the corresponding price for a given value -> Avoid stuck in buy/sell order :param market: Ex: USDT-XMR :param ordertype: "buy" or "sell" :param value: The value of coin1 which is used to buy/sell :return: uuid order :rtype : str """ return 0
class bittrex_private: def __init__(self): # self.bittrex_public = Bittrex(None, None) # 公開情報を扱うBittrexオブジェクト self.bittrex_private = Bittrex(KEY, SECRET) # 個人の情報を扱うBittrexオブジェクト # トレード履歴を取得 def get_order_history(self): response = self.bittrex_private.get_order_history() pprint(response) return response # 買い注文を出す # marketに通貨ペア、quantityに注文する量、rateに価格を指定 def buy_alt_coin(self, market, quantity, rate): response = self.bittrex_private.buy_limit(market=market, quantity=quantity, rate=rate) # 成功なら注文id、失敗ならfalseを返す if response['success'] is False: print(response) return False else: return response['result']['uuid'] # 売り注文を出す # marketに通貨ペア、quantityに注文する量、rateに価格を指定 def sell_alt_coin(self, market, quantity, rate): response = self.bittrex_private.sell_limit(market=market, quantity=quantity, rate=rate) # 成功なら注文id、失敗ならfalseを返す if response['success'] is False: print(response) return False else: return response['result']['uuid'] # 注文をキャンセルする def order_cancel(self, uuid): response = self.bittrex_private.cancel(uuid=uuid) # 成功ならtrue、失敗ならfalseを返す print(response) return response['success'] # 注文一覧を取得する def get_orders(self): order_list = [] response = self.bittrex_private.get_open_orders() if response['success'] is False: print(response) return False else: # 注文が1件もない場合 if len(response['result']) == 0: return None for item in response['result']: # 通貨の種類と量、注文IDを抜き出す balance = {} balance['market'] = item['Exchange'] balance['quantity'] = item['Quantity'] balance['uuid'] = item['OrderUuid'] order_list.append(balance) return order_list # 所有している通貨をList型で返す def get_balances(self): balance_list = [] response = self.bittrex_private.get_balances() if response['success'] is False: print(response) return False else: for item in response['result']: # 利用可能な通貨量が0の場合はスキップする if item['Available'] == 0: continue # 通貨の種類と量を抜き出す balance = {} balance['currency'] = item['Currency'] balance['available'] = item['Available'] balance_list.append(balance) return balance_list
float(1 - cfg.getfloat('Data', 'commission') / 100), sellOrderBook[x]['Rate']) else: text = my_bittrex.buy_limit( 'BTC-' + last_message['text'], sellOrderBook[x]['Quantity'] * float(1 - cfg.getfloat('Data', 'commission') / 100), sellOrderBook[x]['Rate']) BTC = BTC - BTC / sellOrderBook[x]['Rate'] * float( 1 - cfg.getfloat('Data', 'commission') / 100) if BTC <= 0.00050000: break if BTC <= 0.00050000: break # проверяет исполнился ли ордер bot.sendMessage(chat_id=str(last_message['from']['id']), text="Проверяю покупку (2 сек)...") time.sleep(1) get_open_orders = my_bittrex.get_open_orders('BTC-' + last_message['text']) if len(get_open_orders['result']) == 0: setSell(last_message) break # Если ордер на покупку не исполнился , то отменяет все открытые новые ордера bot.sendMessage(chat_id=str(last_message['from']['id']), text="Не удалось выкупить весь объем.\nПовторяю...") for y in range(0, len(get_open_orders['result'])): my_bittrex.cancel(get_open_orders['result'][y]['OrderUuid']) time.sleep(0.1)
data = [i for i in config] print('Reading configuration file...') slaves = len(data[0]) - 1 print(slaves, ' Slave accounts detected') master_api_key = data[0][1] master_api_secret = data[1][1] count = 1 slave_api = [] order_mapping = [] while count <= slaves: slave_api.append([data[2][count], data[3][count]]) order_mapping.append({}) count += 1 master_bittrex = Bittrex(api_key=master_api_key, api_secret=master_api_secret) print('Opening Master Account...') master_open_orders = master_bittrex.get_open_orders() if master_open_orders['success']: print('Master Open Orders = ', len(master_open_orders['result'])) else: print( 'Error....', master_open_orders['message'], 'Application cannot run...please correct errors and restart application' ) print('Application will terminate after 10 seconds...') sleep(10) exit() master_order_history = master_bittrex.get_order_history() print('Master History Orders = ', len(master_order_history['result'])) print('Opening Slave Accounts...') slave_number = 0