Skip to content

Instantly share code, notes, and snippets.

@MtkN1
Created December 6, 2022 02:59
Show Gist options
  • Select an option

  • Save MtkN1/4a9e4dbd5c3c1efceb98b81c4d1fc418 to your computer and use it in GitHub Desktop.

Select an option

Save MtkN1/4a9e4dbd5c3c1efceb98b81c4d1fc418 to your computer and use it in GitHub Desktop.
みんかぶ WebSocket Sample
import socketio
sio = socketio.Client()
usdjpy = {}
@sio.event
def connect():
sio.emit("subscribe", "USDJPY")
@sio.event
def USDJPY(data):
usdjpy.update(data)
print(usdjpy)
"""stdout
{
'pair': 'USDJPY',
'time': 1670295120000,
'range': '1m',
'open_bid': 136.96,
'open_ask': 136.968,
'open_time': 1670295123032,
'high_bid': 136.963,
'high_ask': 136.97,
'low_bid': 136.958,
'low_ask': 136.963,
'close_bid': 136.963,
'close_ask': 136.97,
'close_time': 1670295124432
}
"""
if __name__ == "__main__":
try:
sio.connect('wss://fx.minkabu.jp', transports=['websocket']) # バックグラウンドで接続される
sio.wait() # プログラムの終了をブロック
except KeyboardInterrupt:
pass
@MtkN1
Copy link
Copy Markdown
Author

MtkN1 commented Dec 6, 2022

Requirements

pip install "python-socketio[client]"

Web

https://fx.minkabu.jp/pair/USDJPY

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment