1234567891011121314151617181920212223242526272829303132333435363738 |
- #!/usr/bin/env python
- # -*- encoding: utf-8 -*-
- '''
- @File : socket.py
- @Time : 2019/05/28 02:14:15
- @Author : Liuyuqi
- @Version : 1.0
- @Contact : liuyuqi.gov@msn.cn
- @License : (C)Copyright 2019
- @Desc : None
- pip install asyncio
- pip install aiowebsocket
- '''
- import asyncio
- import logging
- from datetime import datetime
- from aiowebsocket.converses import AioWebSocket
- async def startup(uri):
- async with AioWebSocket(uri) as aws:
- converse = aws.manipulator
- # 客户端给服务端发送消息
- await converse.send('{"action":"subscribe","args":["QuoteBin5m:14"]}')
- while True:
- mes = await converse.receive()
- print('{time}-Client receive: {rec}'.format(
- time=datetime.now().strftime('%Y-%m-%d %H:%M:%S'), rec=mes))
- if __name__ == '__main__':
- url = 'wss://api.bbxapp.vip/v1/ifcontract/realTime'
- try:
- asyncio.get_event_loop().run_until_complete(startup(url))
- except KeyboardInterrupt as exc:
- logging.info('Quit.')
|