python-kabusapi Created Python wrapper for kabu station API is REST Only API was supported, and websocket distribution by PUSH API was not supported.
Therefore, it was necessary to write a code such as "Receive Websocket of kabu station ® API in Python", but for beginners asyncio Since the concept such as: //docs.python.org/ja/3.8/library/asyncio.html) is complicated, the library has been updated so that it can be eliminated.
import kabusapi
url = "localhost"
port = "18081" #For verification,18080 for production
#Initial setting: No token password required for PUSH distribution
api = kabusapi.Context(url, port,)
#Receiving function This is called every time information is received
@api.websocket
def recieve(msg):
#The msg processed here is in dict format.
print("{} {} {}".format(
msg['Symbol'],
msg['SymbolName'],
msg['CurrentPrice'],
))
#Start receiving
api.websocket.run()
Recommended Posts