コード例 #1
0
    def test_handles_invalid_key_or_secret(self):
        self.bittrex = Bittrex('invalidkey',
                               self.secrets['secret'],
                               api_version=API_V2_0)
        actual = async_get(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 = async_get(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 = async_get(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 = async_get(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 = async_get(self.bittrex.get_balance('BTC'))
        test_auth_basic_failures(self, actual, 'invalid key, invalid secret')
コード例 #2
0
 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)
コード例 #3
0
ファイル: api.py プロジェクト: BlockHub/django-crypto-repo
class BittrexApi(AbstractRestApi):
    def __init__(self, key=None, secret=None, v1=False, v2=False):

        if not v1 and not v2:
            raise ProgrammingError('specify v1 and/or v2')

        self.key = key
        self.secret = secret

        if v1:
            self.v1 = Bittrex(api_key=self.key,
                              api_secret=self.secret,
                              api_version=API_V1_1)

        if v2:
            self.v2 = Bittrex(api_key=self.key,
                              api_secret=self.secret,
                              api_version=API_V2_0)
        self.loop = asyncio.get_event_loop()

    # def tickers(self, market):
    #     return self.__api_call(self.v1.get_orderbook, market, BOTH_ORDERBOOK)

    async def get_orderbook(self, market):
        res = await self.v1.get_orderbook(market.market(), BOTH_ORDERBOOK)

        # a single retry if the api fails
        if not res['success']:
            res = await self.v1.get_orderbook(market.market(), BOTH_ORDERBOOK)

        # our loop might return the orderbooks unordered. This way our FK relations are correct.
        if res['result']:
            res['result'].update({'market': market})
        return res

    def orderbooks(self, markets):
        tasks = [self.get_orderbook(i) for i in markets]
        obs = self.loop.run_until_complete(asyncio.gather(*tasks))
        return obs

    def get_markets(self):
        task = [self.v1.get_markets()]
        return self.loop.run_until_complete(asyncio.gather(*task))[0]

    async def get_ticker(self, market):
        res = await self.v1.get_ticker(market.market())

        # a single retry if the api fails
        if not res['success']:
            res = await self.v1.get_ticker(market.market())

        # our loop might return the orderbooks unordered. This way our FK relations are correct.
        if res['result']:
            res['result'].update({'market': market})
        return res

    def tickers(self, markets):
        tasks = [self.get_ticker(i) for i in markets]
        tks = self.loop.run_until_complete(asyncio.gather(*tasks))
        return tks
コード例 #4
0
ファイル: api.py プロジェクト: BlockHub/django-crypto-repo
    def __init__(self, key=None, secret=None, v1=False, v2=False):

        if not v1 and not v2:
            raise ProgrammingError('specify v1 and/or v2')

        self.key = key
        self.secret = secret

        if v1:
            self.v1 = Bittrex(api_key=self.key,
                              api_secret=self.secret,
                              api_version=API_V1_1)

        if v2:
            self.v2 = Bittrex(api_key=self.key,
                              api_secret=self.secret,
                              api_version=API_V2_0)
        self.loop = asyncio.get_event_loop()
コード例 #5
0
    def test_handles_none_key_or_secret(self):
        self.bittrex = Bittrex(None, None)
        # could call any public method here
        actual = async_get(self.bittrex.get_markets())
        self.assertTrue(actual['success'],
                        "failed with None key and None secret")

        self.bittrex = Bittrex("123", None)
        actual = async_get(self.bittrex.get_markets())
        self.assertTrue(actual['success'], "failed with None secret")

        self.bittrex = Bittrex(None, "123")
        actual = async_get(self.bittrex.get_markets())
        self.assertTrue(actual['success'], "failed with None key")
コード例 #6
0
 def setUp(self):
     self.bittrex = Bittrex(None, None, api_version=API_V1_1)
コード例 #7
0
class TestBittrexV11PublicAPI(unittest.TestCase):
    """
    Integration tests for the Bittrex public API.
    These will fail in the absence of an internet connection or if bittrex API goes down
    """
    def setUp(self):
        self.bittrex = Bittrex(None, None, api_version=API_V1_1)

    def test_handles_none_key_or_secret(self):
        self.bittrex = Bittrex(None, None)
        # could call any public method here
        actual = async_get(self.bittrex.get_markets())
        self.assertTrue(actual['success'],
                        "failed with None key and None secret")

        self.bittrex = Bittrex("123", None)
        actual = async_get(self.bittrex.get_markets())
        self.assertTrue(actual['success'], "failed with None secret")

        self.bittrex = Bittrex(None, "123")
        actual = async_get(self.bittrex.get_markets())
        self.assertTrue(actual['success'], "failed with None key")

    def test_get_markets(self):
        actual = async_get(self.bittrex.get_markets())
        test_basic_response(self, actual, "get_markets")
        self.assertTrue(isinstance(actual['result'], list),
                        "result is not a list")
        self.assertTrue(len(actual['result']) > 0, "result list is 0-length")

    def test_get_currencies(self):
        actual = async_get(self.bittrex.get_currencies())
        test_basic_response(self, actual, "get_currencies")

    def test_get_ticker(self):
        actual = async_get(self.bittrex.get_ticker(market='BTC-LTC'))
        test_basic_response(self, actual, "get_ticker")

    def test_get_market_summaries(self):
        actual = async_get(self.bittrex.get_market_summaries())
        test_basic_response(self, actual, "get_market_summaries")

    def test_get_orderbook(self):
        actual = async_get(
            self.bittrex.get_orderbook('BTC-LTC', depth_type=BUY_ORDERBOOK))
        test_basic_response(self, actual, "get_orderbook")

    def test_get_market_history(self):
        actual = async_get(self.bittrex.get_market_history('BTC-LTC'))
        test_basic_response(self, actual, "get_market_history")

    def test_list_markets_by_currency(self):
        actual = async_get(self.bittrex.list_markets_by_currency('LTC'))
        self.assertListEqual(['BTC-LTC', 'ETH-LTC', 'USDT-LTC'], actual)

    def test_get_wallet_health(self):
        self.assertRaisesRegexp(Exception, 'method call not available',
                                async_get(self.bittrex.get_wallet_health))

    def test_get_balance_distribution(self):
        self.assertRaisesRegexp(
            Exception, 'method call not available',
            async_get(self.bittrex.get_balance_distribution))

    def test_get_candles(self):
        self.assertRaisesRegexp(Exception,
                                'method call not available',
                                async_get(self.bittrex.get_candles),
                                market='BTC-LTC',
                                tick_interval=TICKINTERVAL_ONEMIN)

    def test_get_latest_candle(self):
        self.assertRaisesRegexp(Exception,
                                'method call not available',
                                async_get(self.bittrex.get_latest_candle),
                                market='BTC-LTC',
                                tick_interval=TICKINTERVAL_ONEMIN)
コード例 #8
0
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 = async_get(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 = async_get(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 = async_get(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 = async_get(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 = async_get(self.bittrex.get_balance('BTC'))
        test_auth_basic_failures(self, actual, 'invalid key, invalid secret')

    def test_get_openorders(self):
        actual = async_get(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 = async_get(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 = async_get(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 = async_get(self.bittrex.get_deposit_address('BTC'))
        test_basic_response(self, actual, "get_deposit_address")

    def test_get_order_history_all_markets(self):
        actual = async_get(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 = async_get(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 = async_get(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 = async_get(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 = async_get(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 = async_get(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 = async_get(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 = async_get(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 = async_get(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 = async_get(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 = async_get(
            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")
コード例 #9
0
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 = async_get(self.bittrex.get_balance('BTC'))
        test_auth_basic_failures(self, actual, 'Invalid key, valid secret')

        self.bittrex = Bittrex(None, self.secrets['secret'])
        actual = async_get(self.bittrex.get_balance('BTC'))
        test_auth_basic_failures(self, actual, 'None key, valid secret')

        self.bittrex = Bittrex(self.secrets['key'], 'invalidsecret')
        actual = async_get(self.bittrex.get_balance('BTC'))
        test_auth_basic_failures(self, actual, 'valid key, invalid secret')

        self.bittrex = Bittrex(self.secrets['key'], None)
        actual = async_get(self.bittrex.get_balance('BTC'))
        test_auth_basic_failures(self, actual, 'valid key, None secret')

        self.bittrex = Bittrex('invalidkey', 'invalidsecret')
        actual = async_get(self.bittrex.get_balance('BTC'))
        test_auth_basic_failures(self, actual, 'invalid key, invalid secret')

    def test_get_openorders(self):
        actual = async_get(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 = async_get(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 = async_get(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 = async_get(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 = async_get(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 = async_get(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 = async_get(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 = async_get(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 = async_get(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 = async_get(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',
            async_get(self.bittrex.get_pending_withdrawals))

    def test_get_pending_deposits(self):
        self.assertRaisesRegexp(Exception, 'method call not available',
                                async_get(self.bittrex.get_pending_deposits))

    def test_generate_deposit_address(self):
        self.assertRaisesRegexp(Exception,
                                'method call not available',
                                async_get(
                                    self.bittrex.generate_deposit_address),
                                currency='BTC')
コード例 #10
0
class TestBittrexV20PublicAPI(unittest.TestCase):
    """
    Integration tests for the Bittrex public API.
    These will fail in the absence of an internet connection or if bittrex API goes down
    """
    def setUp(self):
        self.bittrex = Bittrex(None, None, api_version=API_V2_0)

    def test_handles_none_key_or_secret(self):
        self.bittrex = Bittrex(None, None, api_version=API_V2_0)
        # could call any public method here
        actual = async_get(self.bittrex.get_market_summaries())
        self.assertTrue(actual['success'],
                        "failed with None key and None secret")

        self.bittrex = Bittrex("123", None, api_version=API_V2_0)
        actual = async_get(self.bittrex.get_market_summaries())
        self.assertTrue(actual['success'], "failed with None secret")

        self.bittrex = Bittrex(None, "123", api_version=API_V2_0)
        actual = async_get(self.bittrex.get_market_summaries())
        self.assertTrue(actual['success'], "failed with None key")

    def test_get_currencies(self):
        actual = async_get(self.bittrex.get_currencies())
        test_basic_response(self, actual, "get_currencies")

    def test_get_ticker(self):
        self.assertRaisesRegexp(Exception,
                                'method call not available',
                                self.bittrex.get_ticker,
                                market='BTC-LTC')

    def test_get_market_summaries(self):
        actual = async_get(self.bittrex.get_market_summaries())
        test_basic_response(self, actual, "get_market_summaries")

    def test_get_market_summary(self):
        actual = async_get(self.bittrex.get_market_summary(market='BTC-LTC'))
        test_basic_response(self, actual, "get_market_summary")

    def test_get_orderbook(self):
        actual = async_get(self.bittrex.get_orderbook('BTC-LTC'))
        test_basic_response(self, actual, "get_orderbook")

    def test_get_wallet_health(self):
        actual = async_get(self.bittrex.get_wallet_health())
        test_basic_response(self, actual, "get_wallet_health")
        self.assertIsInstance(actual['result'], list)

    @unittest.skip("Endpoint 404s.  Is this still a valid 2.0 API?")
    def test_get_balance_distribution(self):
        actual = async_get(self.bittrex.get_balance_distribution())
        test_basic_response(self, actual, "get_balance_distribution")
        self.assertIsInstance(actual['result'], list)

    def test_get_candles(self):
        actual = async_get(
            self.bittrex.get_candles('BTC-LTC',
                                     tick_interval=TICKINTERVAL_ONEMIN))
        test_basic_response(self, actual, "test_get_candles")
        self.assertIsInstance(actual['result'], list)

    def test_get_latest_candle(self):
        actual = async_get(
            self.bittrex.get_latest_candle('BTC-LTC',
                                           tick_interval=TICKINTERVAL_ONEMIN))
        test_basic_response(self, actual, "test_get_latest_candle")
        self.assertIsInstance(actual['result'], list)