11# wrappy
22
3- ` wrappy ` is an async helper library for crypto trading bots.
3+ ` wrappy ` は、暗号資産 bot を作るときに毎回書きがちな処理をまとめた非同期 Python ライブラリです。
44
5- The repository currently supports:
5+ たとえば次のような用途を想定しています。
66
7- - Common bot infrastructure: ` Log ` , ` Notify ` , ` BotBase `
8- - Exchange wrappers: ` GMO ` , ` BitBank ` , ` BitFlyer ` , ` CoinCheck `
9- - Optional Lighter integration: ` wrappy.lighter `
10- - Optional analytics helpers in ` wrappy.util `
7+ - bot 共通のログ出力
8+ - Discord / LINE への通知
9+ - GMO / BitBank / BitFlyer / CoinCheck の API ラッパー
10+ - Lighter 向けの補助機能
11+ - bot 開発時に使う一部の分析ユーティリティ
1112
12- This README is intentionally narrow: it documents only the APIs that exist in this repository today.
13+ ## まず最初に読む場所
1314
14- For machine-oriented repository context, see [ LLM_REPO_GUIDE.md] ( LLM_REPO_GUIDE.md ) .
15- For agent operating rules, see [ AGENTS.md] ( AGENTS.md ) .
15+ 人間向けの概要と使い方:
1616
17- ## Installation
17+ - この ` README.md `
1818
19- Core package:
19+ LLM に読ませるためのリポジトリ要約:
20+
21+ - [ LLM_REPO_GUIDE.md] ( LLM_REPO_GUIDE.md )
22+
23+ AI コーディングエージェント向けの運用ルール:
24+
25+ - [ AGENTS.md] ( AGENTS.md )
26+
27+ AI エージェントにこのリポジトリを触らせる場合は、少なくとも ` LLM_REPO_GUIDE.md ` と ` AGENTS.md ` を先に読ませるのが安全です。
28+
29+ ## このリポジトリで現在サポートしているもの
30+
31+ - 共通基盤: ` Log ` , ` Notify ` , ` BotBase `
32+ - 取引所ラッパー: ` GMO ` , ` BitBank ` , ` BitFlyer ` , ` CoinCheck `
33+ - オプション機能:
34+ - ` wrappy.lighter `
35+ - ` wrappy.util ` の分析用関数
36+
37+ この README では、実際にこのリポジトリに存在する API だけを説明します。
38+
39+ ## インストール
40+
41+ コア機能だけ使う場合:
2042
2143``` bash
2244pip install -U git+https://github.com/lawnn/wrappy.git
2345```
2446
25- With Lighter support :
47+ Lighter も使う場合 :
2648
2749``` bash
2850pip install -U " wrappy[lighter] @ git+https://github.com/lawnn/wrappy.git"
2951```
3052
31- With analytics helpers :
53+ 分析ユーティリティも使う場合 :
3254
3355``` bash
3456pip install -U " wrappy[analytics] @ git+https://github.com/lawnn/wrappy.git"
3557```
3658
37- ## Agent-Friendly Import Rules
59+ ## import の考え方
60+
61+ ` wrappy ` は、オプション依存が入っていなくてもトップレベル import が壊れないようにしてあります。
62+
63+ 基本的には次の使い分けで考えると分かりやすいです。
3864
39- The package is designed so that ` import wrappy ` works even if optional dependencies are not installed.
65+ - 取引所ラッパーを使う:
66+ - ` from wrappy import GMO, BitBank, BitFlyer, CoinCheck `
67+ - Lighter を使う:
68+ - ` from wrappy.lighter import LighterDealer, DealerConfig, WsInfo `
69+ - 分析関数を使う:
70+ - ` from wrappy import simple_regression, trades_to_historical `
71+ - ただし ` analytics ` extra が必要
4072
41- - Use ` from wrappy import GMO, BitBank, BitFlyer, CoinCheck ` for exchange wrappers
42- - Use ` from wrappy.lighter import LighterDealer, DealerConfig, WsInfo ` for Lighter
43- - Use ` from wrappy import simple_regression, trades_to_historical ` only if the analytics extra is installed
73+ もしオプション依存が足りない状態で該当 API を触ると、` wrappy ` は「何を install すべきか」を含んだエラーメッセージを返します。
4474
45- If an optional dependency is missing, ` wrappy ` raises an explicit install hint instead of failing during the top-level import.
75+ ## 設定ファイル
4676
47- ## Config File
77+ まず ` config.json ` を用意します。
4878
49- Create a JSON file such as ` config.json ` .
79+ 最小構成の例:
80+
81+ ``` json
82+ {
83+ "exchange_name" : " demo" ,
84+ "bot_name" : " sample-bot" ,
85+ "log_level" : " INFO" ,
86+ "log_dir" : " log"
87+ }
88+ ```
89+
90+ 実運用に近い例:
5091
5192``` json
5293{
@@ -65,15 +106,44 @@ Create a JSON file such as `config.json`.
65106}
66107```
67108
68- Notes:
109+ 各キーの意味:
110+
111+ - ` exchange_name `
112+ - ログファイル名などに使う識別子です。
113+ - ` bot_name `
114+ - bot 名です。ログ出力やファイル名に使われます。
115+ - ` log_level `
116+ - ` DEBUG ` , ` INFO ` などの標準的なログレベルです。
117+ - ` log_dir `
118+ - ログファイルの出力先ディレクトリです。
119+ - ` line_notify_token ` , ` discordWebhook `
120+ - 通知先です。どちらも未設定なら通知は送られず、warning ログだけ出ます。
121+ - ` gmocoin `
122+ - ` GMO ` を使うときに必要です。
123+ - ` bitbank ` または ` bitbank_keys `
124+ - ` BitBank ` を使うときに必要です。` bitbank_keys ` は複数 key をローテーションしたいときに使います。
125+ - ` bitflyer `
126+ - ` BitFlyer ` を使うときに必要です。
127+
128+ ## 何が便利なのか
69129
70- - ` line_notify_token ` and ` discordWebhook ` are optional
71- - ` statusNotify() ` will log a warning and skip notification if neither is configured
72- - ` bitbank_keys ` is optional and only needed for key rotation
130+ このライブラリは「bot ごとに毎回ゼロから API ラッパーや通知まわりを書く」手間を減らすためのものです。
73131
74- ## Quick Start
132+ たとえば、普通なら次のような作業を bot ごとに書くことになります。
75133
76- ### Logging and notifications
134+ - 設定ファイルを読み込む
135+ - logger を初期化する
136+ - Discord や LINE に稼働通知を送る
137+ - 各取引所ごとに違う REST API のエンドポイントを叩く
138+ - 失敗時の例外処理を書く
139+
140+ ` wrappy ` を使うと、このあたりを共通化した状態から bot ロジックだけに集中できます。
141+
142+ ## 使い方の例
143+
144+ ### 1. ログと通知だけ使う
145+
146+ これは「取引はまだしないが、bot の起動・停止・例外通知だけ欲しい」というケースです。
77147
78148``` python
79149import asyncio
@@ -90,7 +160,14 @@ if __name__ == "__main__":
90160 asyncio.run(main())
91161```
92162
93- ### GMO limit order
163+ この例で分かること:
164+
165+ - ` BotBase ` だけでも logger を使えます。
166+ - 通知先が未設定でもクラッシュせず、warning だけ出して継続します。
167+
168+ ### 2. GMO で指値注文する
169+
170+ たとえば「BTC_JPY に 0.01 の指値売買を出したい」という最小例です。
94171
95172``` python
96173import asyncio
@@ -107,7 +184,34 @@ if __name__ == "__main__":
107184 asyncio.run(main())
108185```
109186
110- ### Lighter
187+ この例で分かること:
188+
189+ - ` GMO("config.json", "BTC_JPY") ` のように、設定ファイルと銘柄を渡して使います。
190+ - 高レベルメソッドは内部で GMO の対応エンドポイントに変換されます。
191+
192+ ### 3. BitFlyer で成行注文する
193+
194+ ``` python
195+ import asyncio
196+ from wrappy import BitFlyer
197+
198+
199+ async def main ():
200+ bot = BitFlyer(" config.json" , " FX_BTC_JPY" )
201+ result = await bot.market_order(" BUY" , 0.01 )
202+ bot.log_info(result)
203+
204+
205+ if __name__ == " __main__" :
206+ asyncio.run(main())
207+ ```
208+
209+ この例でのポイント:
210+
211+ - 新しいコードでは ` BitFlyer ` を使うのを推奨します。
212+ - 旧来互換として ` wrappy.bitflyer ` も残していますが、README では ` BitFlyer ` を正規名として扱います。
213+
214+ ### 4. Lighter を使う
111215
112216``` python
113217import asyncio
@@ -129,39 +233,69 @@ if __name__ == "__main__":
129233 asyncio.run(main())
130234```
131235
132- Lighter-specific details live in [ wrappy/Lighter/README.md] ( wrappy/Lighter/README.md ) .
236+ この例でのポイント:
237+
238+ - Lighter は optional 機能です。` lighter-sdk ` が必要です。
239+ - 新しいコードでは ` wrappy.lighter ` から import してください。
240+ - Lighter の詳しい説明は [ wrappy/Lighter/README.md] ( wrappy/Lighter/README.md ) を参照してください。
133241
134- ## Public API
242+ ## 公開 API
135243
136- Stable exports from ` wrappy ` :
244+ ` wrappy ` から直接使う公開 API :
137245
138246- ` Log ` , ` Notify ` , ` BotBase `
139247- ` GMO ` , ` BitBank ` , ` BitFlyer ` , ` CoinCheck `
140248- ` APIException ` , ` RequestException `
141249- ` now_jst ` , ` now_jst_str ` , ` now_utc ` , ` now_utc_str ` , ` now_gmt ` , ` now_gmt_str ` , ` fromISOformat `
142250- ` simple_regression ` , ` plot_corrcoef ` , ` np_shift ` , ` np_stack ` , ` resample_ohlc ` , ` df_list ` , ` trades_to_historical ` , ` Objective `
143251
144- Stable exports from ` wrappy.lighter ` :
252+ ` wrappy.lighter ` から使う公開 API :
145253
146254- ` LighterDealer ` , ` DealerConfig ` , ` WsInfo `
147255- ` wrappy.lighter.markets `
148256
149- ## Validation
257+ ## 検証方法
150258
151- The repository includes smoke tests aimed at package usability:
259+ AI エージェント運用も含めた基本検証は、次の 1 コマンドで回せます。
152260
153261``` bash
154262python scripts/verify_agent_ready.py
155263```
156264
157- Convenience alias:
265+ このコマンドでは次を確認します。
266+
267+ - ` wrappy ` と ` tests/agent ` の bytecode compile
268+ - ` tests/agent ` 配下の回帰テスト
269+ - 一時ディレクトリへのローカル install
270+ - install 後の ` import wrappy ` と ` from wrappy import * `
271+
272+ 短い別名コマンドもあります。
158273
159274``` bash
160275make agent-check
161276```
162277
163- ## Known Limits
278+ ## 人間向けの読み方
279+
280+ このリポジトリを初めて読むなら、次の順番が分かりやすいです。
281+
282+ 1 . ` README.md `
283+ 2 . ` config.json ` の実例を作る
284+ 3 . 自分が使いたい取引所クラスを 1 つ選ぶ
285+ 4 . まずは「ログだけ」「通知だけ」「ticker 取得だけ」など小さい例から試す
286+ 5 . 問題なければ注文系メソッドに進む
287+
288+ たとえば GMO を使うなら、いきなり複雑な bot ロジックを書くよりも、まずは次の順で確認すると安全です。
289+
290+ 1 . ` GMO("config.json", "BTC_JPY") ` が作れる
291+ 2 . ` bot.log_info("hello") ` が出る
292+ 3 . ` await bot.statusNotify("hello") ` が動く
293+ 4 . ` await bot.fetch_my_position() ` のような読み取り系を試す
294+ 5 . その後で ` market_order() ` や ` limit_order() ` に進む
295+
296+ ## 制約と注意点
164297
165- - Exchange APIs are third-party systems and can still change underneath this package
166- - Lighter support requires ` lighter-sdk `
167- - Analytics helpers require their extra dependencies
298+ - 取引所 API は外部サービスなので、将来仕様変更される可能性があります。
299+ - Lighter を使うには ` lighter-sdk ` が必要です。
300+ - 分析関数を使うには ` analytics ` extra が必要です。
301+ - README にある例は「入口としての最小例」です。実運用では例外処理、レート制限、ポジション管理を別途検討してください。
0 commit comments