BitMex WebSocket API
bitmex-websocket的Python项目详细描述
安装
$ pip install bitmex-websocket
用法
- 首先,您应该设置bitmex_api_key和bitmex_api_secret。它可以 操作如下:
$ cp .env.example .env # edit .env to reflect your API key and secret $ source .env
- 然后在您的项目中,您可以使用仪器,如下所示:
importwebsocketfrombitmex_websocketimportInstrumentfrombitmex_websocket.constantsimportInstrumentChannelswebsocket.enableTrace(True)channels=[InstrumentChannels.quote,InstrumentChannels.trade,InstrumentChannels.orderBookL2]XBTUSD=Instrument(symbol='XBTUSD',channels=channels)XBTUSD.on('action',lambdamsg:print(message))XBTUSD.run_forever()
示例
运行示例脚本:
$ RUN_ENV=development python -m ./examples/example-2.py
测试
使用pytest<;http://pytest.org>;设置测试,并处理覆盖率 使用pytest cov插件。
使用根目录中的pytest运行测试。
覆盖率默认运行,并在pytest.ini文件中设置。 要查看覆盖率的HTML输出,请在运行测试后打开htmlcov/index.html。