or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Syncing
xxxxxxxxxx
fin-pyコードリーディング会#3
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →概要
fin-pyについて
https://github.com/fin-py/guideline
次回のイベント
https://fin-py.connpass.com/event/224843/
Slack
https://docs.google.com/forms/d/e/1FAIpQLSd9oVlrCMHEuD3PN0x3QcMgeQGy6Sj90d6uP1CQXQnArX9YqQ/viewform
参加方法
重要
Zoomに参加したら、出欠確認にチェックを入れてください
前回の様子
タイムテーブル
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →コードリーディング
読むコード
pybotters.ws.py
発表者のかたは、コードを読んだ際のメモ書きなどを下記に記載してください
ほかの形式でまとめたかたは要点(もし可能であれば資料のリンク)を記載してください
参考情報
自己紹介・コメント・メモ
どりらん
しんせいたろう
やろころ
KanSAKAMOTO
MeshiKutteNeru
発表者
しんせいたろう
初めて使う標準ライブラリ
dataclass
__init__()
や__repr__()
のような special method を生成し、ユーザー定義のクラスに自動的に追加するデコレータや関数を提供します。__名前__()
の形のメソッドで、Pythonが暗黙的に呼び出すメソッド__init__()
を自動生成してくれるため、クラスの定義がシンプルに@dataclass
を使うと__init__
を使わなくても良い(コードがスッキリ)slots=True
ws.py
137行目bitflyer
の AUTHのための nonce と signiture のために使われている初めて使うサードパーティライブラリ
WSMessage
クラスにメソッドとして定義されている。他に見当たらない。aiohttp/http_websocket.py
の5行目のimport json
?json
?yarl
のURL
のどちらかという型定義コードリーディング
ws_run_forever
を中心にws_run_forever
が使われているところclient.py
のClient
クラスのws_connect
メソッドWebSocket API
を利用するためにws_connect
を呼び出すClient
はws_response_class=ClientWebSocketResponse,
WsJsonHandler
Callable[[引数の型], [返り値の型]]
Optional[]
: None もしくは指定の型WsStrHandler
は 関数(Callable)で、引数はstr
とClientWebSocketResponse
で、返り値は、None
もしくはCoroutineオブジェクト
[Coroutine[Any, Any, None]
: typing.Coroutineに説明があるけど、サッパリわからないの説明にある「受信したメッセージを処理するハンドラ関数の指定」の
実装部分
await cooldown
へevent.set()
の event はws_connect
を初期化した時に生成されるasyncio.Event()
.set()
メソッドで True フラグ、.clear()
メソッドで False を内部的にたてて.wait()
メソッドはTrueフラグがたつまで待たせるclient.py
のws_connect
で、await event.wait()
しているのでTrueになるまでまってる状態event.set()
でTrueを立てて処理開始'_authtask'
は、ClientWebSocketResponse
で定義AuthHosts
はpybotters/typedefs.py
でItem = Dict[str, Any]
という定義がありました。ここではdataclass
を使って定義したのはどういう意図でしょうか?)self.__dict__['_authtask']
に、この辞書を使って各取引所認証メソッドを格納await ws.__dict__['_authtask']
で待機させているself._lock = asyncio.Lock()
hdlr_str
は None もしくはWsStrHandler
(Coroutine) なので、else 文にはどういう時に入る?どりらん
WebSocket API (WebSockets)
インターフェイス
WebSocketに対応しているPythonパッケージ
HTTPXはWebSocketに対応していない
asyncio.Event
https://docs.python.org/ja/3/library/asyncio-sync.html#asyncio.Event
set
メソッド ->True
clear
メソッド ->False
True
になるまでブロックされる(イニシャライズ時はFalse
)True
を返すTrue
を返すサンプルコード: フラグが
True
のときだけsleeper_task
が再開されるasyncio.iscoroutinefunction
https://docs.python.org/ja/3/library/asyncio-task.html#asyncio.iscoroutinefunction
inspect.iscoroutinefunction
はasyc def
で定義されているコルーチンに対してTrue
を返すasyncio.iscoroutinefunction
は上記に加え、ジェネレータベースのコルーチンもTrue
を返すインスタンスがコルーチンであるかを確認する関数
True
を返すasync def
で定義されたコルーチンのみTrue
を返すasyncio.Lock
https://docs.python.org/ja/3/library/asyncio-sync.html#asyncio.Lock
コードサンプル:
RequestLimit.gmocoin
でロックをしているのは、GMOコインが多重アクセスを禁止しているからでしょうか?aiohttp.ClientSession.ws_connect
https://docs.aiohttp.org/en/stable/client_reference.html?highlight=ws_connect#aiohttp.ClientSession.ws_connect
ClientWebSocketResponse
https://docs.aiohttp.org/en/stable/client_reference.html?highlight=ClientWebSocketResponse#aiohttp.ClientWebSocketResponse
receive
が呼ばれるaiohttp.WSMessage
https://docs.aiohttp.org/en/stable/websocket_utilities.html?highlight=WSMsgType#aiohttp.WSMessage
receive()
が呼ばれたときのWebSocketメッセージaiohttp.WSMsgType
https://docs.aiohttp.org/en/stable/websocket_utilities.html?highlight=WSMsgType#aiohttp.WSMsgType
気になった点
http_websocket.pyでは標準ライブラリの
json
をimportしているので、import json
でよいのではないかと思いました同じモジュールの
Auth
クラスとの衝突を避けるなら、from . import auth
として、auth.Auth
で呼び出せばよいのではないかと思いましたhdlr_str
とhdlr_json
はCallableの型ヒントつけられないかなと思いましたhasattr(ws, "_authtask")
でよいのではないかと思いましたやろころ
読み方
概要
class RequestLimitHosts # ホスト名からRequestLimitの staticmethodを引く
出席確認
次回
__init__.py
auth.py
client.py
request.py
store.py
typedefs.py
ws.py
tests
docs
(ドキュメント関連)pyproject.toml
(パッケージ関連)pytest.yml
(CI, GitHub Actions)次回は
store.py
10/13(水) 19:00-21:00