I don't understand the difference between websocket (websocket client) and websockets. I would like to understand the difference to know which one uses to be optimal.
I have a code that seems to do the same thing.
import websockets
import asyncio
import json
async def capture_data():
uri = "wss://www.bitmex.com/realtime?subscribe=instrument:XBTUSD"
#uri = "wss://www.bitmex.com/realtime"
async with websockets.connect(uri) as websocket:
while True:
data = await websocket.recv()
data = json.loads(data)
try :
#print('\n', data['data'][0]["lastPrice"])
print('\n', data)
except KeyError:
continue
asyncio.get_event_loop().run_until_complete(capture_data())
Run Code Online (Sandbox Code Playgroud)
import websocket
import json …Run Code Online (Sandbox Code Playgroud) 我有一个编译器错误:
g++ main.cpp -o exec -Wall -std=c++17 -Wextra -pedantic -O2 -Wshadow -fsanitize=undefined
main.cpp: In instantiation of ‘std::__cxx11::string to_string(A) [with A = int; std::__cxx11::string = std::__cxx11::basic_string<char>]’:
main.cpp:68:25: required from ‘void debug_out(Head, Tail ...) [with Head = int; Tail = {}]’
main.cpp:79:3: required from here
main.cpp:43:3: error: ‘begin’ was not declared in this scope
for (const auto &x : v) {
^~~
main.cpp:43:3: note: suggested alternative:
In file included from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:95:0,
from main.cpp:1:
/usr/include/c++/7/valarray:1211:5: note: ‘std::begin’
begin(const valarray<_Tp>& __va)
^~~~~
main.cpp:43:3: error: …Run Code Online (Sandbox Code Playgroud)