示例#1
0
    def setUp(self):
        self.skipIfBase()
        super().setUp()

        if self.is_rest:
            self.client = create_rest_client(self.platform_id, version=self.version)
            self.client_authed = create_rest_client(self.platform_id, True, self.version)
        else:
            self.client = create_ws_client(self.platform_id, version=self.version)
            self.client_authed = create_ws_client(self.platform_id, True, self.version)
示例#2
0
    def test_create_rest_client__credentials(self):
        client = create_rest_client(Platform.BINANCE,
                                    is_private=True,
                                    credentials=("aaa", "sss"))

        self.assertEqual(client._api_key, "aaa")
        self.assertEqual(client._api_secret, "sss")
        self.assertEqual(client._credentials, ("aaa", "sss"))

        client._send("", None)
        client._send("", None)

        self.assertEqual(client._api_key, "aaa")
        self.assertEqual(client._api_secret, "sss")
        self.assertEqual(client._credentials, ("aaa", "sss"))
示例#3
0
    def test_create_rest_client__callable_credentials(self):
        credentials_list = [("aaa", "sss"), ("aaa22", "sss22")]
        client = create_rest_client(
            Platform.BINANCE,
            is_private=True,
            credentials=lambda: credentials_list.pop(0))

        self.assertEqual(client._api_key, "aaa")
        self.assertEqual(client._api_secret, "sss")
        self.assertTrue(callable(client._credentials))

        client._send(None, None)

        self.assertEqual(client._api_key, "aaa22")
        self.assertEqual(client._api_secret, "sss22")
        self.assertTrue(callable(client._credentials))
示例#4
0
from hyperquant.clients.tests.utils import set_up_logging

settings.configure(DEBUG=True, default_settings=hqlib_settings)

# Enable logging if needed
# set_up_logging()

# Change to Platform.BINANCE to see example
TEST_PLATFORM = Platform.OKEX

TEST_SYMBOLS = {
    Platform.BINANCE: ['ETHBTC', 'BTCUSDT'],
    Platform.OKEX: ['eth_btc', 'btc_usdt'],
}

client = utils.create_rest_client(platform_id=TEST_PLATFORM)
print('\n\nTrade history\n\n')
print(client.fetch_trades_history(TEST_SYMBOLS[TEST_PLATFORM][0], limit=10))
print('\n\n---------------------')
print('\n\nCandles\n\n')
print(
    client.fetch_candles(TEST_SYMBOLS[TEST_PLATFORM][0],
                         Interval.MIN_1,
                         limit=10))
print('\n\n---------------------')

client = utils.create_ws_client(platform_id=TEST_PLATFORM)
client.on_data_item = lambda item: print(item)  # print received parsed objects
client.subscribe(endpoints=[Endpoint.TRADE, Endpoint.CANDLE],
                 symbols=TEST_SYMBOLS[TEST_PLATFORM],
                 interval=Interval.MIN_1)