async def test_network_argument():
    async with open_bitmex_websocket('mainnet') as s:
        assert getattr(s, 'listen', None) is not None
    async with open_bitmex_websocket('testnet') as s:
        assert getattr(s, 'listen', None) is not None
    with pytest.raises(ValueError):
        async with open_bitmex_websocket('incorrect') as s:
            assert False, 'BitMEXWebsocket.connect accepted erroneous network argument.'
async def test_auth_fail():
    with pytest.raises(ConnectionRejected):
        async with open_bitmex_websocket('testnet', 'abcd1234',
                                         'efgh5678') as bws:
            async with aclosing(bws.listen('position')) as aiter:
                async for item in aiter:
                    assert False
async def test_spam_requests():
    with pytest.raises(BitMEXWebsocketApiError):
        async with open_bitmex_websocket('testnet') as ws:
            async with Pipeline.create(ws.listen(
                    'instrument',
                    'PAROTCOIN')) as pipeline, pipeline.tap() as aiter:
                async for bundle in aiter:
                    break
Пример #4
0
async def main():
    async with open_bitmex_websocket('testnet') as bws:
        count = 0
        async with aclosing(bws.listen('instrument')) as agen:
            async for msg in agen:
                print(f'Received message, symbol: \'{msg["symbol"]}\', timestamp: \'{msg["timestamp"]}\'')
                count += 1
                if count == 5:
                    break
Пример #5
0
async def main():
    async with open_bitmex_websocket(
            'testnet', os.getenv('TESTNET_API_KEY'),
            os.getenv(
                'TESTNET_API_SECRET')) as bws, trio.open_nursery() as nursery:
        # Only one subscription is added. Both listeners get messages from the same channel.
        nursery.start_soon(instrument, bws, 'XRPUSD')
        nursery.start_soon(instrument, bws, 'XRPUSD')
        nursery.start_soon(close_after, bws, 60)
async def test_funding():
    async with open_bitmex_websocket('testnet') as ws:
        async with Pipeline.create(Group(
                2, ws.listen('funding'))) as pipeline, pipeline.tap() as aiter:
            async for bundle in aiter:
                for funding in bundle:
                    funding['timestamp'] = pendulum.parse(funding['timestamp'])
                    funding['fundingInterval'] = pendulum.parse(
                        funding['fundingInterval'])
                assert isinstance(bundle, tuple)
                assert len(bundle) > 1
                return
            assert False, 'This should not happen.'
async def test_orderbook():
    async with open_bitmex_websocket('testnet') as bws:
        async with aclosing(bws.listen('orderBookL2', 'XBTUSD')) as agen:
            async for msg in agen:
                assert len(msg) == 2
                break