Esempio n. 1
0
async def run():
    api_key = os.environ['APIKEY']
    sec_key = os.environ['SECKEY']

    client = CryptoXLib.create_binance_client(api_key, sec_key)

    # Bundle several subscriptions into a single websocket
    client.compose_subscriptions([
        OrderBookTickerSubscription(callbacks=[orderbook_ticker_update]),
        OrderBookSymbolTickerSubscription(pair=Pair("BTC", "USDT"),
                                          callbacks=[orderbook_ticker_update]),
        TradeSubscription(pair=Pair('ETH', 'BTC'), callbacks=[trade_update]),
        CandlestickSubscription(Pair('BTC', 'USDT'),
                                Interval.I_1MIN,
                                callbacks=[candlestick_update])
    ])

    # Bundle another subscriptions into a separate websocket
    client.compose_subscriptions(
        [AccountSubscription(callbacks=[account_update])])

    # Execute all websockets asynchronously
    await client.start_websockets()

    await client.close()
Esempio n. 2
0
    async def test_candlesticks_subscription(self):
        message_counter = WsMessageCounter()
        self.client.compose_subscriptions([
            CandlestickSubscription(Pair("BTC", "USDT"), enums.Interval.I_1MIN,
                                     callbacks = [message_counter.generate_callback(1)])
        ])

        await self.assertWsMessageCount(message_counter, 15.0)
Esempio n. 3
0
async def run():
    api_key = os.environ['APIKEY']
    sec_key = os.environ['SECKEY']

    client = CryptoXLib.create_binance_client(api_key, sec_key)

    # Bundle several subscriptions into a single websocket
    client.compose_subscriptions([
        CandlestickSubscription(Pair('BTC', 'USDT'),
                                Interval.I_1MIN,
                                callbacks=[candlestick_update])
    ])

    # Bundle another subscriptions into a separate websocket
    client.compose_subscriptions([
        # uncomment if isolated margin account is setup
        #AccountIsolatedMarginSubscription(pair = Pair('BTC', 'USDT'), callbacks = [account_update]),
        AccountCrossMarginSubscription(callbacks=[account_update])
    ])

    # Execute all websockets asynchronously
    await client.start_websockets()

    await client.close()