bitbank-lab-mcp 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +388 -0
- package/assets/lightweight-charts.standalone.js +7 -0
- package/bin/bitbank-lab-mcp.js +20 -0
- package/lib/cache.ts +70 -0
- package/lib/candle-utils.ts +48 -0
- package/lib/candle-validate.ts +434 -0
- package/lib/conversions.ts +25 -0
- package/lib/datetime.ts +157 -0
- package/lib/depth-analysis.ts +51 -0
- package/lib/error.ts +15 -0
- package/lib/formatter.ts +296 -0
- package/lib/get-depth.ts +111 -0
- package/lib/http.ts +132 -0
- package/lib/indicator-config.ts +39 -0
- package/lib/indicator_buffer.ts +41 -0
- package/lib/indicators.ts +579 -0
- package/lib/logger.ts +120 -0
- package/lib/ma-snapshot-utils.ts +277 -0
- package/lib/math.ts +89 -0
- package/lib/pattern-diagrams.ts +562 -0
- package/lib/result.ts +104 -0
- package/lib/validate.ts +154 -0
- package/lib/volatility.ts +132 -0
- package/package.json +79 -0
- package/src/env.ts +4 -0
- package/src/handlers/analyzeCandlePatternsHandler.ts +383 -0
- package/src/handlers/analyzeFibonacciHandler.ts +54 -0
- package/src/handlers/analyzeIndicatorsHandler.ts +682 -0
- package/src/handlers/analyzeMarketSignalHandler.ts +272 -0
- package/src/handlers/analyzeMyPortfolioHandler.ts +800 -0
- package/src/handlers/detectPatternsHandler.ts +77 -0
- package/src/handlers/detectPatternsViewsHandler.ts +518 -0
- package/src/handlers/getTickersJpyHandler.ts +145 -0
- package/src/handlers/getVolatilityMetricsHandler.ts +234 -0
- package/src/handlers/portfolio/calc.ts +549 -0
- package/src/handlers/portfolio/fetch.ts +318 -0
- package/src/handlers/portfolio/types.ts +170 -0
- package/src/handlers/renderChartSvgHandler.ts +69 -0
- package/src/handlers/runBacktestHandler.ts +70 -0
- package/src/http.ts +107 -0
- package/src/private/auth.ts +104 -0
- package/src/private/client.ts +298 -0
- package/src/private/config.ts +25 -0
- package/src/private/confirmation.ts +185 -0
- package/src/private/schemas.ts +866 -0
- package/src/prompts.ts +2296 -0
- package/src/resources/app-resources.ts +79 -0
- package/src/schema/analysis.ts +942 -0
- package/src/schema/backtest.ts +100 -0
- package/src/schema/base.ts +88 -0
- package/src/schema/candle-validate.ts +135 -0
- package/src/schema/chart.ts +399 -0
- package/src/schema/index.ts +11 -0
- package/src/schema/indicators.ts +125 -0
- package/src/schema/market-data.ts +298 -0
- package/src/schema/patterns.ts +382 -0
- package/src/schema/types.ts +97 -0
- package/src/schemas.d.ts +37 -0
- package/src/schemas.ts +7 -0
- package/src/server.ts +405 -0
- package/src/tool-definition.ts +44 -0
- package/src/tool-registry.ts +174 -0
- package/src/types/express-shim.d.ts +9 -0
- package/src/types/schemas.generated.d.ts +23 -0
- package/tools/analyze_bb_snapshot.ts +385 -0
- package/tools/analyze_candle_patterns.ts +810 -0
- package/tools/analyze_currency_strength.ts +273 -0
- package/tools/analyze_ema_snapshot.ts +183 -0
- package/tools/analyze_fibonacci.ts +530 -0
- package/tools/analyze_ichimoku_snapshot.ts +606 -0
- package/tools/analyze_indicators.ts +691 -0
- package/tools/analyze_market_signal.ts +665 -0
- package/tools/analyze_mtf_fibonacci.ts +273 -0
- package/tools/analyze_mtf_sma.ts +175 -0
- package/tools/analyze_sma_snapshot.ts +146 -0
- package/tools/analyze_stoch_snapshot.ts +276 -0
- package/tools/analyze_support_resistance.ts +817 -0
- package/tools/analyze_volume_profile.ts +546 -0
- package/tools/chart/ichimoku-cloud.ts +113 -0
- package/tools/chart/render-depth.ts +139 -0
- package/tools/chart/render-sub-panels.ts +208 -0
- package/tools/chart/svg-utils.ts +102 -0
- package/tools/detect_macd_cross.ts +691 -0
- package/tools/detect_patterns.ts +424 -0
- package/tools/detect_whale_events.ts +181 -0
- package/tools/get_candles.ts +487 -0
- package/tools/get_flow_metrics.ts +596 -0
- package/tools/get_orderbook.ts +540 -0
- package/tools/get_ticker.ts +132 -0
- package/tools/get_tickers_jpy.ts +240 -0
- package/tools/get_transactions.ts +209 -0
- package/tools/get_volatility_metrics.ts +302 -0
- package/tools/patterns/aftermath.ts +212 -0
- package/tools/patterns/config.ts +151 -0
- package/tools/patterns/detect_doubles.ts +650 -0
- package/tools/patterns/detect_hs.ts +635 -0
- package/tools/patterns/detect_pennants.ts +373 -0
- package/tools/patterns/detect_triangles.ts +820 -0
- package/tools/patterns/detect_triples.ts +633 -0
- package/tools/patterns/detect_wedges.ts +1072 -0
- package/tools/patterns/helpers.ts +517 -0
- package/tools/patterns/index.ts +40 -0
- package/tools/patterns/regression.ts +153 -0
- package/tools/patterns/smoothing.ts +168 -0
- package/tools/patterns/swing.ts +91 -0
- package/tools/patterns/types.ts +193 -0
- package/tools/prepare_chart_data.ts +294 -0
- package/tools/prepare_depth_data.ts +189 -0
- package/tools/private/analyze_my_portfolio.ts +21 -0
- package/tools/private/cancel_order.ts +127 -0
- package/tools/private/cancel_orders.ts +121 -0
- package/tools/private/create_order.ts +236 -0
- package/tools/private/get_margin_positions.ts +134 -0
- package/tools/private/get_margin_status.ts +155 -0
- package/tools/private/get_margin_trade_history.ts +156 -0
- package/tools/private/get_my_assets.ts +207 -0
- package/tools/private/get_my_deposit_withdrawal.ts +500 -0
- package/tools/private/get_my_orders.ts +157 -0
- package/tools/private/get_my_trade_history.ts +229 -0
- package/tools/private/get_order.ts +95 -0
- package/tools/private/get_orders_info.ts +90 -0
- package/tools/private/preview_cancel_order.ts +172 -0
- package/tools/private/preview_cancel_orders.ts +137 -0
- package/tools/private/preview_order.ts +292 -0
- package/tools/render_candle_pattern_diagram.ts +389 -0
- package/tools/render_chart_svg.ts +799 -0
- package/tools/render_depth_svg.ts +274 -0
- package/tools/trading_process/index.ts +7 -0
- package/tools/trading_process/lib/backtest_engine.ts +252 -0
- package/tools/trading_process/lib/equity.ts +131 -0
- package/tools/trading_process/lib/fetch_candles.ts +181 -0
- package/tools/trading_process/lib/sma.ts +62 -0
- package/tools/trading_process/lib/strategies/bb_breakout.ts +141 -0
- package/tools/trading_process/lib/strategies/index.ts +52 -0
- package/tools/trading_process/lib/strategies/macd_cross.ts +256 -0
- package/tools/trading_process/lib/strategies/rsi.ts +133 -0
- package/tools/trading_process/lib/strategies/sma_cross.ts +214 -0
- package/tools/trading_process/lib/strategies/types.ts +118 -0
- package/tools/trading_process/lib/svg_to_png.ts +64 -0
- package/tools/trading_process/render_backtest_chart_generic.ts +729 -0
- package/tools/trading_process/run_backtest.ts +243 -0
- package/tools/trading_process/types.ts +85 -0
- package/tools/validate_candle_data.ts +260 -0
- package/tsconfig.json +17 -0
- package/ui/cancel-confirm/dist/cancel-confirm.html +99 -0
- package/ui/order-confirm/dist/order-confirm.html +99 -0
|
@@ -0,0 +1,866 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* プライベート API 系の Zod スキーマ。
|
|
3
|
+
* src/schemas.ts から re-export され、単一ソースの原則を維持する。
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
|
|
8
|
+
// FailResultSchema を直接定義(schemas.ts からの循環参照を避けるため)
|
|
9
|
+
const PrivateFailResultSchema = z.object({
|
|
10
|
+
ok: z.literal(false),
|
|
11
|
+
summary: z.string(),
|
|
12
|
+
data: z.object({}).passthrough(),
|
|
13
|
+
meta: z.object({ errorType: z.string() }).passthrough(),
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
// ── get_my_assets ──
|
|
17
|
+
|
|
18
|
+
export const GetMyAssetsInputSchema = z.object({
|
|
19
|
+
include_jpy_valuation: z.boolean().default(true).describe('各通貨の日本円評価額を含めるか'),
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
const AssetItemSchema = z.object({
|
|
23
|
+
asset: z.string().describe('通貨コード(例: btc, jpy)'),
|
|
24
|
+
amount: z.string().describe('総保有量'),
|
|
25
|
+
available_amount: z.string().describe('利用可能量'),
|
|
26
|
+
locked_amount: z.string().describe('ロック中の量'),
|
|
27
|
+
jpy_value: z.number().optional().describe('日本円評価額'),
|
|
28
|
+
allocation_pct: z.number().optional().describe('構成比(%)'),
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
export const GetMyAssetsDataSchema = z.object({
|
|
32
|
+
assets: z.array(AssetItemSchema),
|
|
33
|
+
total_jpy_value: z.number().optional(),
|
|
34
|
+
timestamp: z.string(),
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
export const GetMyAssetsMetaSchema = z.object({
|
|
38
|
+
fetchedAt: z.string(),
|
|
39
|
+
assetCount: z.number().int(),
|
|
40
|
+
hasJpyValuation: z.boolean(),
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
export const GetMyAssetsOutputSchema = z.union([
|
|
44
|
+
z.object({
|
|
45
|
+
ok: z.literal(true),
|
|
46
|
+
summary: z.string(),
|
|
47
|
+
data: GetMyAssetsDataSchema,
|
|
48
|
+
meta: GetMyAssetsMetaSchema,
|
|
49
|
+
}),
|
|
50
|
+
PrivateFailResultSchema,
|
|
51
|
+
]);
|
|
52
|
+
|
|
53
|
+
// ── get_my_trade_history ──
|
|
54
|
+
|
|
55
|
+
export const GetMyTradeHistoryInputSchema = z.object({
|
|
56
|
+
pair: z.string().optional().describe('通貨ペア(例: btc_jpy)。省略で全ペア'),
|
|
57
|
+
count: z.number().max(10000).default(100).describe('取得件数(最大10000、1000超は自動ページネーション)'),
|
|
58
|
+
order: z.enum(['asc', 'desc']).default('desc').describe('ソート順(asc: 古い順, desc: 新しい順)'),
|
|
59
|
+
since: z.string().optional().describe('開始日時(ISO8601、例: 2025-01-01T00:00:00+09:00)'),
|
|
60
|
+
end: z.string().optional().describe('終了日時(ISO8601、例: 2025-12-31T23:59:59+09:00)'),
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const TradeItemSchema = z.object({
|
|
64
|
+
trade_id: z.number().describe('約定ID'),
|
|
65
|
+
pair: z.string().describe('通貨ペア'),
|
|
66
|
+
order_id: z.number().describe('注文ID'),
|
|
67
|
+
side: z.string().describe('売買(buy / sell)'),
|
|
68
|
+
type: z.string().describe('注文タイプ(limit / market)'),
|
|
69
|
+
amount: z.string().describe('約定数量'),
|
|
70
|
+
price: z.string().describe('約定価格'),
|
|
71
|
+
maker_taker: z.string().describe('メイカー / テイカー'),
|
|
72
|
+
fee_amount_base: z.string().describe('手数料(基軸通貨)'),
|
|
73
|
+
fee_amount_quote: z.string().describe('手数料(決済通貨)'),
|
|
74
|
+
executed_at: z.string().describe('約定日時(ISO8601)'),
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
export const GetMyTradeHistoryDataSchema = z.object({
|
|
78
|
+
trades: z.array(TradeItemSchema),
|
|
79
|
+
timestamp: z.string(),
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
export const GetMyTradeHistoryMetaSchema = z.object({
|
|
83
|
+
fetchedAt: z.string(),
|
|
84
|
+
tradeCount: z.number().int(),
|
|
85
|
+
pair: z.string().optional(),
|
|
86
|
+
isComplete: z.boolean().optional(),
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
export const GetMyTradeHistoryOutputSchema = z.union([
|
|
90
|
+
z.object({
|
|
91
|
+
ok: z.literal(true),
|
|
92
|
+
summary: z.string(),
|
|
93
|
+
data: GetMyTradeHistoryDataSchema,
|
|
94
|
+
meta: GetMyTradeHistoryMetaSchema,
|
|
95
|
+
}),
|
|
96
|
+
PrivateFailResultSchema,
|
|
97
|
+
]);
|
|
98
|
+
|
|
99
|
+
// ── get_my_orders ──
|
|
100
|
+
|
|
101
|
+
export const GetMyOrdersInputSchema = z.object({
|
|
102
|
+
pair: z.string().optional().describe('通貨ペア(例: btc_jpy)。省略で全ペア'),
|
|
103
|
+
count: z.number().max(1000).default(100).describe('取得件数(最大1000)'),
|
|
104
|
+
since: z.string().optional().describe('開始日時(ISO8601)'),
|
|
105
|
+
end: z.string().optional().describe('終了日時(ISO8601)'),
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
const OrderItemSchema = z.object({
|
|
109
|
+
order_id: z.number().describe('注文ID'),
|
|
110
|
+
pair: z.string().describe('通貨ペア'),
|
|
111
|
+
side: z.string().describe('売買(buy / sell)'),
|
|
112
|
+
type: z.string().describe('注文タイプ(limit / market / stop 等)'),
|
|
113
|
+
start_amount: z.string().optional().describe('注文数量'),
|
|
114
|
+
remaining_amount: z.string().optional().describe('未約定数量'),
|
|
115
|
+
executed_amount: z.string().optional().describe('約定済み数量'),
|
|
116
|
+
price: z.string().optional().describe('指値価格'),
|
|
117
|
+
average_price: z.string().optional().describe('平均約定価格'),
|
|
118
|
+
status: z.string().describe('注文ステータス'),
|
|
119
|
+
ordered_at: z.string().describe('注文日時(ISO8601)'),
|
|
120
|
+
expire_at: z.string().optional().describe('有効期限(ISO8601)'),
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
export const GetMyOrdersDataSchema = z.object({
|
|
124
|
+
orders: z.array(OrderItemSchema),
|
|
125
|
+
timestamp: z.string(),
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
export const GetMyOrdersMetaSchema = z.object({
|
|
129
|
+
fetchedAt: z.string(),
|
|
130
|
+
orderCount: z.number().int(),
|
|
131
|
+
pair: z.string().optional(),
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
export const GetMyOrdersOutputSchema = z.union([
|
|
135
|
+
z.object({
|
|
136
|
+
ok: z.literal(true),
|
|
137
|
+
summary: z.string(),
|
|
138
|
+
data: GetMyOrdersDataSchema,
|
|
139
|
+
meta: GetMyOrdersMetaSchema,
|
|
140
|
+
}),
|
|
141
|
+
PrivateFailResultSchema,
|
|
142
|
+
]);
|
|
143
|
+
|
|
144
|
+
// ── analyze_my_portfolio(Phase 3) ──
|
|
145
|
+
|
|
146
|
+
export const AnalyzeMyPortfolioInputSchema = z.object({
|
|
147
|
+
include_technical: z.boolean().default(true).describe('保有銘柄のテクニカル分析を含めるか'),
|
|
148
|
+
include_pnl: z.boolean().default(true).describe('損益分析を含めるか(約定履歴から平均取得単価・損益を算出)'),
|
|
149
|
+
include_deposit_withdrawal: z
|
|
150
|
+
.boolean()
|
|
151
|
+
.default(true)
|
|
152
|
+
.describe(
|
|
153
|
+
'入出金データを含めるか(true の場合、総入金額 vs 現在評価額で口座全体のリターンを算出。ページネーション対応で最大1000件/チャネル取得)',
|
|
154
|
+
),
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
const HoldingPnlSchema = z.object({
|
|
158
|
+
asset: z.string().describe('通貨コード'),
|
|
159
|
+
pair: z.string().describe('通貨ペア(例: btc_jpy)'),
|
|
160
|
+
amount: z.string().describe('保有数量'),
|
|
161
|
+
avg_buy_price: z.number().optional().describe('平均取得単価(JPY)'),
|
|
162
|
+
current_price: z.number().optional().describe('現在価格(JPY)'),
|
|
163
|
+
jpy_value: z.number().optional().describe('現在の評価額(JPY)'),
|
|
164
|
+
cost_basis: z.number().optional().describe('取得原価合計(JPY)'),
|
|
165
|
+
unrealized_pnl: z.number().optional().describe('評価損益(JPY)'),
|
|
166
|
+
unrealized_pnl_pct: z.number().optional().describe('評価損益率(%)'),
|
|
167
|
+
realized_pnl: z.number().optional().describe('実現損益(JPY)'),
|
|
168
|
+
trade_count: z.number().optional().describe('約定件数'),
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
const HoldingPerformanceSchema = z.object({
|
|
172
|
+
asset: z.string().describe('通貨コード'),
|
|
173
|
+
pair: z.string().describe('通貨ペア(例: btc_jpy)'),
|
|
174
|
+
current_price: z.number().optional().describe('現在価格(JPY)'),
|
|
175
|
+
monthly_change_pct: z
|
|
176
|
+
.number()
|
|
177
|
+
.optional()
|
|
178
|
+
.describe('月初比騰落率(%)。月初始値 → 現在価格の変動率。月初の価格データがない場合は undefined'),
|
|
179
|
+
yearly_change_pct: z
|
|
180
|
+
.number()
|
|
181
|
+
.optional()
|
|
182
|
+
.describe('年初比騰落率(%)。年初始値 → 現在価格の変動率。年初の価格データがない場合は undefined'),
|
|
183
|
+
jpy_value: z.number().optional().describe('現在の評価額(JPY)'),
|
|
184
|
+
amount: z.string().describe('保有数量'),
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
const TechnicalSummarySchema = z.object({
|
|
188
|
+
pair: z.string().describe('通貨ペア'),
|
|
189
|
+
trend: z.string().optional().describe('トレンド判定'),
|
|
190
|
+
rsi_14: z.number().optional().describe('RSI(14)'),
|
|
191
|
+
sma_deviation_pct: z.number().optional().describe('SMA(25)乖離率(%)'),
|
|
192
|
+
signal: z.string().optional().describe('総合判定'),
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
const DepositWithdrawalSummarySchema = z
|
|
196
|
+
.object({
|
|
197
|
+
total_jpy_deposited: z.number().describe('JPY 入金合計'),
|
|
198
|
+
total_jpy_withdrawn: z.number().describe('JPY 出金合計'),
|
|
199
|
+
net_jpy_invested: z
|
|
200
|
+
.number()
|
|
201
|
+
.describe(
|
|
202
|
+
'純投入額(JPY入金 - JPY出金 + 暗号資産入庫の現在価格での仮評価)。暗号資産入庫がある場合は JPY 純入金だけでなく仮評価分も含む',
|
|
203
|
+
),
|
|
204
|
+
crypto_deposit_count: z.number().describe('暗号資産入庫件数'),
|
|
205
|
+
crypto_deposit_estimated_jpy: z
|
|
206
|
+
.number()
|
|
207
|
+
.optional()
|
|
208
|
+
.describe('暗号資産入庫の推定 JPY 評価額(現在の市場価格で仮評価。入庫時点の価格ではない)'),
|
|
209
|
+
crypto_withdrawal_count: z.number().describe('暗号資産出庫件数'),
|
|
210
|
+
account_return_pct: z.number().optional().describe('口座全体リターン率(%): (現在評価額 - 純投入額) / 純投入額'),
|
|
211
|
+
account_return_jpy: z.number().optional().describe('口座全体リターン額(JPY)'),
|
|
212
|
+
is_complete: z
|
|
213
|
+
.boolean()
|
|
214
|
+
.describe('全履歴を取得できたか(false の場合は API 件数上限により一部のみ取得。リターンは概算値)'),
|
|
215
|
+
analysis_basis: z
|
|
216
|
+
.enum(['deposit_withdrawal', 'trade_only'])
|
|
217
|
+
.describe('分析基準(deposit_withdrawal: 入出金込み, trade_only: 約定ベース)'),
|
|
218
|
+
})
|
|
219
|
+
.optional()
|
|
220
|
+
.describe(
|
|
221
|
+
'入出金ベースのリターン分析。available: 実データ(analysis_basis=deposit_withdrawal)、fallback: 常にplaceholder(analysis_basis=trade_only)、no_history/not_requested: undefined',
|
|
222
|
+
);
|
|
223
|
+
|
|
224
|
+
const PeriodDWSummarySchema = z
|
|
225
|
+
.object({
|
|
226
|
+
jpy_deposited: z.number().describe('期間中のJPY入金合計'),
|
|
227
|
+
jpy_withdrawn: z.number().describe('期間中のJPY出金合計'),
|
|
228
|
+
net_jpy: z.number().describe('純入出金(JPY入金 - JPY出金)'),
|
|
229
|
+
crypto_deposit_count: z.number().int().describe('期間中の暗号資産入庫件数'),
|
|
230
|
+
crypto_deposit_estimated_jpy: z
|
|
231
|
+
.number()
|
|
232
|
+
.optional()
|
|
233
|
+
.describe('期間中の暗号資産入庫の推定JPY評価額(現在価格で仮評価)'),
|
|
234
|
+
crypto_withdrawal_count: z.number().int().describe('期間中の暗号資産出庫件数'),
|
|
235
|
+
crypto_withdrawal_estimated_jpy: z
|
|
236
|
+
.number()
|
|
237
|
+
.optional()
|
|
238
|
+
.describe('期間中の暗号資産出庫の推定JPY評価額(現在価格で仮評価)'),
|
|
239
|
+
period_start: z.string().describe('期間の開始日時(ISO8601 JST)'),
|
|
240
|
+
period_end: z.string().describe('期間の終了日時(ISO8601 JST)'),
|
|
241
|
+
})
|
|
242
|
+
.optional()
|
|
243
|
+
.describe('期間内の入出金サマリー');
|
|
244
|
+
|
|
245
|
+
const PeriodRealizedPnlSchema = z
|
|
246
|
+
.object({
|
|
247
|
+
realized_pnl: z.number().describe('期間内の合計実現損益(JPY)'),
|
|
248
|
+
sell_count: z.number().int().describe('期間内の売却約定件数'),
|
|
249
|
+
period_start: z.string().describe('期間の開始日時(ISO8601 JST)'),
|
|
250
|
+
period_end: z.string().describe('期間の終了日時(ISO8601 JST)'),
|
|
251
|
+
})
|
|
252
|
+
.optional();
|
|
253
|
+
|
|
254
|
+
const PeriodPerformanceSchema = z
|
|
255
|
+
.object({
|
|
256
|
+
start_value_jpy: z
|
|
257
|
+
.number()
|
|
258
|
+
.describe('期初の口座評価額(JPY)。現在の保有状態から約定・入出金を逆算して復元し、期初時点の始値で評価'),
|
|
259
|
+
current_value_jpy: z.number().describe('現在の口座評価額(JPY)'),
|
|
260
|
+
change_jpy: z.number().describe('単純増減額 = current_value_jpy - start_value_jpy'),
|
|
261
|
+
change_pct: z.number().optional().describe('単純増減率(%)。start_value_jpy が 0 の場合は undefined'),
|
|
262
|
+
net_flow_jpy: z
|
|
263
|
+
.number()
|
|
264
|
+
.describe(
|
|
265
|
+
'期間中の純入出金額(JPY、元本移動のみ)。正=純入金、負=純出金。出金手数料は含まない。暗号資産の入出庫は現在価格で仮評価',
|
|
266
|
+
),
|
|
267
|
+
withdrawal_fee_jpy: z
|
|
268
|
+
.number()
|
|
269
|
+
.describe(
|
|
270
|
+
'期間中の出金手数料合計(JPY)。出金元本は外部フローとして net_flow_jpy に含め performance から除外するが、手数料はコストとして adjusted_change_jpy に残る',
|
|
271
|
+
),
|
|
272
|
+
adjusted_change_jpy: z
|
|
273
|
+
.number()
|
|
274
|
+
.describe('調整後増減額 = change_jpy - net_flow_jpy(入出金元本の影響を除いた成績。出金手数料コストは含む)'),
|
|
275
|
+
adjusted_change_pct: z.number().optional().describe('調整後増減率(%)。start_value_jpy が 0 の場合は undefined'),
|
|
276
|
+
period_start: z.string().describe('期間の開始日時(ISO8601 JST)'),
|
|
277
|
+
period_end: z.string().describe('期間の終了日時(ISO8601 JST)'),
|
|
278
|
+
note: z.string().describe('計算方法・注意事項の説明'),
|
|
279
|
+
})
|
|
280
|
+
.optional();
|
|
281
|
+
|
|
282
|
+
const EquityPointSchema = z.object({
|
|
283
|
+
timestamp: z.string().describe('時点の日時(ISO8601 JST)'),
|
|
284
|
+
value_jpy: z.number().describe('その時点のJPY建て総資産額(円)'),
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
export const AnalyzeMyPortfolioDataSchema = z.object({
|
|
288
|
+
holdings: z.array(HoldingPnlSchema).describe('保有銘柄一覧(JPY評価額降順)'),
|
|
289
|
+
total_jpy_value: z.number().optional().describe('ポートフォリオ合計評価額'),
|
|
290
|
+
total_cost_basis: z.number().optional().describe('ポートフォリオ合計取得原価'),
|
|
291
|
+
total_unrealized_pnl: z.number().optional().describe('合計評価損益'),
|
|
292
|
+
total_unrealized_pnl_pct: z.number().optional().describe('合計評価損益率(%)'),
|
|
293
|
+
total_realized_pnl: z.number().optional().describe('合計実現損益(全履歴ベース)'),
|
|
294
|
+
daily_performance: PeriodPerformanceSchema.describe('前日比パフォーマンス(当日0:00 JST〜現在の口座評価額増減)'),
|
|
295
|
+
yearly_performance: PeriodPerformanceSchema.describe(
|
|
296
|
+
'年初比パフォーマンス(当年1/1 00:00 JST〜現在の口座評価額増減)',
|
|
297
|
+
),
|
|
298
|
+
monthly_performance: PeriodPerformanceSchema.describe(
|
|
299
|
+
'月初比パフォーマンス(当月1日 00:00 JST〜現在の口座評価額増減)',
|
|
300
|
+
),
|
|
301
|
+
monthly_equity_series: z
|
|
302
|
+
.array(EquityPointSchema)
|
|
303
|
+
.optional()
|
|
304
|
+
.describe(
|
|
305
|
+
'当月1日 00:00 JSTから現在までの日次JPY建て総資産推移。各点はその日00:00 JST時点の復元評価額。最終点は現在のリアルタイム評価額',
|
|
306
|
+
),
|
|
307
|
+
yearly_equity_series: z
|
|
308
|
+
.array(EquityPointSchema)
|
|
309
|
+
.optional()
|
|
310
|
+
.describe(
|
|
311
|
+
'当年1/1 00:00 JSTから現在までの月次JPY建て総資産推移。各点はその月1日 00:00 JST時点の復元評価額。最終点は現在のリアルタイム評価額',
|
|
312
|
+
),
|
|
313
|
+
yearly_realized_pnl: PeriodRealizedPnlSchema.describe('年初来実現損益(補助指標)'),
|
|
314
|
+
monthly_realized_pnl: PeriodRealizedPnlSchema.describe('月初来実現損益(補助指標)'),
|
|
315
|
+
deposit_withdrawal_summary: DepositWithdrawalSummarySchema,
|
|
316
|
+
yearly_dw_summary: PeriodDWSummarySchema.describe('年初来の入出金サマリー(当年1/1 00:00 JST〜現在)'),
|
|
317
|
+
monthly_dw_summary: PeriodDWSummarySchema.describe('月初来の入出金サマリー(当月1日 00:00 JST〜現在)'),
|
|
318
|
+
holdings_performance: z
|
|
319
|
+
.array(HoldingPerformanceSchema)
|
|
320
|
+
.optional()
|
|
321
|
+
.describe('保有銘柄の月初比・年初比の価格騰落率(暗号資産のみ。JPY評価額降順)'),
|
|
322
|
+
technical: z.array(TechnicalSummarySchema).optional().describe('テクニカル分析サマリー'),
|
|
323
|
+
timestamp: z.string(),
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
export const AnalyzeMyPortfolioMetaSchema = z.object({
|
|
327
|
+
fetchedAt: z.string(),
|
|
328
|
+
holdingCount: z.number().int(),
|
|
329
|
+
hasPnl: z.boolean(),
|
|
330
|
+
hasTechnical: z.boolean(),
|
|
331
|
+
depositWithdrawalStatus: z
|
|
332
|
+
.enum(['available', 'fallback', 'no_history', 'not_requested'])
|
|
333
|
+
.describe(
|
|
334
|
+
'入出金分析の状態: available=入出金データ取得成功で分析実行(deposit_withdrawal_summaryあり), fallback=API取得失敗またはpartial failureにより約定ベースにフォールバック(deposit_withdrawal_summaryはtrade_only placeholder), no_history=API取得成功・警告なし・履歴0件(deposit_withdrawal_summaryはundefined), not_requested=未リクエスト(deposit_withdrawal_summaryはundefined)',
|
|
335
|
+
),
|
|
336
|
+
periodBasis: z.enum(['jst']).default('jst').describe('年次・月次の期間基準タイムゾーン(jst = Asia/Tokyo)'),
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
export const AnalyzeMyPortfolioOutputSchema = z.union([
|
|
340
|
+
z.object({
|
|
341
|
+
ok: z.literal(true),
|
|
342
|
+
summary: z.string(),
|
|
343
|
+
data: AnalyzeMyPortfolioDataSchema,
|
|
344
|
+
meta: AnalyzeMyPortfolioMetaSchema,
|
|
345
|
+
}),
|
|
346
|
+
PrivateFailResultSchema,
|
|
347
|
+
]);
|
|
348
|
+
|
|
349
|
+
// ── get_my_deposit_withdrawal(Phase 4) ──
|
|
350
|
+
|
|
351
|
+
export const GetMyDepositWithdrawalInputSchema = z.object({
|
|
352
|
+
asset: z
|
|
353
|
+
.string()
|
|
354
|
+
.optional()
|
|
355
|
+
.describe('通貨コード(例: btc, jpy)。省略で全通貨。JPY入出金を取得するには "jpy" を指定'),
|
|
356
|
+
type: z
|
|
357
|
+
.enum(['deposit', 'withdrawal', 'all'])
|
|
358
|
+
.default('all')
|
|
359
|
+
.describe('取得タイプ(deposit: 入金/入庫のみ, withdrawal: 出金/出庫のみ, all: 両方)'),
|
|
360
|
+
count: z.number().max(100).default(25).describe('各履歴の取得件数(最大100)'),
|
|
361
|
+
since: z.string().optional().describe('開始日時(ISO8601、例: 2025-01-01T00:00:00+09:00)'),
|
|
362
|
+
end: z.string().optional().describe('終了日時(ISO8601、例: 2025-12-31T23:59:59+09:00)'),
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
const DepositItemSchema = z.object({
|
|
366
|
+
uuid: z.string().describe('入金/入庫ID'),
|
|
367
|
+
asset: z.string().describe('通貨コード'),
|
|
368
|
+
amount: z.string().describe('金額/数量'),
|
|
369
|
+
network: z.string().optional().describe('ネットワーク(暗号資産のみ)'),
|
|
370
|
+
txid: z.string().optional().describe('トランザクションID(暗号資産のみ)'),
|
|
371
|
+
status: z.string().describe('ステータス(FOUND / CONFIRMED / DONE)'),
|
|
372
|
+
found_at: z.string().optional().describe('検出日時(ISO8601)'),
|
|
373
|
+
confirmed_at: z.string().optional().describe('確認日時(ISO8601)'),
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
const WithdrawalItemSchema = z.object({
|
|
377
|
+
uuid: z.string().describe('出金/出庫ID'),
|
|
378
|
+
asset: z.string().describe('通貨コード'),
|
|
379
|
+
amount: z.string().describe('金額/数量'),
|
|
380
|
+
fee: z.string().optional().describe('手数料'),
|
|
381
|
+
network: z.string().optional().describe('ネットワーク(暗号資産のみ)'),
|
|
382
|
+
txid: z.string().optional().describe('トランザクションID(暗号資産のみ)'),
|
|
383
|
+
label: z.string().optional().describe('ラベル'),
|
|
384
|
+
address: z.string().optional().describe('送金先アドレス(暗号資産のみ)'),
|
|
385
|
+
bank_name: z.string().optional().describe('銀行名(JPY出金のみ)'),
|
|
386
|
+
status: z.string().describe('ステータス(CONFIRMING / EXAMINING / SENDING / DONE / REJECTED / CANCELED)'),
|
|
387
|
+
requested_at: z.string().optional().describe('リクエスト日時(ISO8601)'),
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
export const GetMyDepositWithdrawalDataSchema = z.object({
|
|
391
|
+
deposits: z.array(DepositItemSchema),
|
|
392
|
+
withdrawals: z.array(WithdrawalItemSchema),
|
|
393
|
+
timestamp: z.string(),
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
export const GetMyDepositWithdrawalMetaSchema = z.object({
|
|
397
|
+
fetchedAt: z.string(),
|
|
398
|
+
depositCount: z.number().int(),
|
|
399
|
+
withdrawalCount: z.number().int(),
|
|
400
|
+
asset: z.string().optional(),
|
|
401
|
+
isComplete: z.boolean().describe('全履歴を取得できたか(false の場合は API 件数上限に達し一部のみ取得)'),
|
|
402
|
+
hasWarnings: z.boolean().describe('一部の API リクエストが失敗した警告があるか'),
|
|
403
|
+
warnings: z.array(z.string()).describe('警告メッセージ一覧(partial failure 時の詳細。空配列 = 警告なし)'),
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
export const GetMyDepositWithdrawalOutputSchema = z.union([
|
|
407
|
+
z.object({
|
|
408
|
+
ok: z.literal(true),
|
|
409
|
+
summary: z.string(),
|
|
410
|
+
data: GetMyDepositWithdrawalDataSchema,
|
|
411
|
+
meta: GetMyDepositWithdrawalMetaSchema,
|
|
412
|
+
}),
|
|
413
|
+
PrivateFailResultSchema,
|
|
414
|
+
]);
|
|
415
|
+
|
|
416
|
+
// ── get_margin_status ──
|
|
417
|
+
|
|
418
|
+
export const GetMarginStatusInputSchema = z.object({});
|
|
419
|
+
|
|
420
|
+
const MarginAccountStatus = z.enum(['NORMAL', 'LOSSCUT', 'CALL', 'DEBT', 'SETTLED']);
|
|
421
|
+
|
|
422
|
+
export const GetMarginStatusDataSchema = z.object({
|
|
423
|
+
status: MarginAccountStatus,
|
|
424
|
+
total_margin_balance: z.string().describe('保証金合計額'),
|
|
425
|
+
total_margin_balance_percentage: z.string().nullable().describe('保証金率(%、建玉なし時は null)'),
|
|
426
|
+
margin_position_profit_loss: z.string().describe('建玉含み損益'),
|
|
427
|
+
unrealized_cost: z.string().describe('未実現コスト(未収手数料・未収利息)'),
|
|
428
|
+
total_margin_position_product: z.string().describe('建玉総評価額'),
|
|
429
|
+
open_margin_position_product: z.string().describe('保有建玉評価額'),
|
|
430
|
+
open_margin_order_product: z.string().describe('注文中建玉評価額'),
|
|
431
|
+
total_position_maintenance_margin: z.string().describe('維持保証金合計'),
|
|
432
|
+
total_long_position_maintenance_margin: z.string().describe('ロング維持保証金'),
|
|
433
|
+
total_short_position_maintenance_margin: z.string().describe('ショート維持保証金'),
|
|
434
|
+
total_open_order_maintenance_margin: z.string().describe('注文維持保証金'),
|
|
435
|
+
total_long_open_order_maintenance_margin: z.string().describe('ロング注文維持保証金'),
|
|
436
|
+
total_short_open_order_maintenance_margin: z.string().describe('ショート注文維持保証金'),
|
|
437
|
+
losscut_rate: z.string().nullable().describe('強制決済率(%、建玉なし時は null)'),
|
|
438
|
+
available_long_margin: z.string().describe('ロング新規建てご利用可能額'),
|
|
439
|
+
available_short_margin: z.string().describe('ショート新規建てご利用可能額'),
|
|
440
|
+
timestamp: z.string(),
|
|
441
|
+
});
|
|
442
|
+
|
|
443
|
+
export const GetMarginStatusMetaSchema = z.object({
|
|
444
|
+
fetchedAt: z.string(),
|
|
445
|
+
hasWarning: z.boolean(),
|
|
446
|
+
});
|
|
447
|
+
|
|
448
|
+
export const GetMarginStatusOutputSchema = z.union([
|
|
449
|
+
z.object({
|
|
450
|
+
ok: z.literal(true),
|
|
451
|
+
summary: z.string(),
|
|
452
|
+
data: GetMarginStatusDataSchema,
|
|
453
|
+
meta: GetMarginStatusMetaSchema,
|
|
454
|
+
}),
|
|
455
|
+
PrivateFailResultSchema,
|
|
456
|
+
]);
|
|
457
|
+
|
|
458
|
+
// ── get_margin_positions ──
|
|
459
|
+
|
|
460
|
+
export const GetMarginPositionsInputSchema = z.object({
|
|
461
|
+
pair: z.string().optional().describe('通貨ペア(例: btc_jpy)。省略で全ペア'),
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
const MarginPositionSchema = z.object({
|
|
465
|
+
pair: z.string().describe('通貨ペア'),
|
|
466
|
+
position_side: z.enum(['long', 'short']).describe('ロング / ショート'),
|
|
467
|
+
open_amount: z.string().describe('建玉数量'),
|
|
468
|
+
product: z.string().describe('建玉評価額'),
|
|
469
|
+
average_price: z.string().describe('平均取得価格'),
|
|
470
|
+
unrealized_fee_amount: z.string().describe('未収手数料'),
|
|
471
|
+
unrealized_interest_amount: z.string().describe('未収利息'),
|
|
472
|
+
});
|
|
473
|
+
|
|
474
|
+
const MarginNoticeSchema = z
|
|
475
|
+
.object({
|
|
476
|
+
what: z.string().describe('追証・不足金の種別'),
|
|
477
|
+
occurred_at: z.number().describe('発生日時(unix ms)'),
|
|
478
|
+
amount: z.string().describe('追証・不足金額'),
|
|
479
|
+
due_date_at: z.number().describe('期日(unix ms)'),
|
|
480
|
+
})
|
|
481
|
+
.nullable();
|
|
482
|
+
|
|
483
|
+
export const GetMarginPositionsDataSchema = z.object({
|
|
484
|
+
positions: z.array(MarginPositionSchema),
|
|
485
|
+
notice: MarginNoticeSchema.describe('追証・不足金情報(なければ null)'),
|
|
486
|
+
payables: z.object({ amount: z.string() }).describe('不足金額'),
|
|
487
|
+
losscut_threshold: z.object({
|
|
488
|
+
individual: z.string().describe('個人強制決済閾値'),
|
|
489
|
+
company: z.string().describe('法人強制決済閾値'),
|
|
490
|
+
}),
|
|
491
|
+
timestamp: z.string(),
|
|
492
|
+
});
|
|
493
|
+
|
|
494
|
+
export const GetMarginPositionsMetaSchema = z.object({
|
|
495
|
+
fetchedAt: z.string(),
|
|
496
|
+
positionCount: z.number().int(),
|
|
497
|
+
pair: z.string().optional(),
|
|
498
|
+
hasNotice: z.boolean(),
|
|
499
|
+
});
|
|
500
|
+
|
|
501
|
+
export const GetMarginPositionsOutputSchema = z.union([
|
|
502
|
+
z.object({
|
|
503
|
+
ok: z.literal(true),
|
|
504
|
+
summary: z.string(),
|
|
505
|
+
data: GetMarginPositionsDataSchema,
|
|
506
|
+
meta: GetMarginPositionsMetaSchema,
|
|
507
|
+
}),
|
|
508
|
+
PrivateFailResultSchema,
|
|
509
|
+
]);
|
|
510
|
+
|
|
511
|
+
// ── get_margin_trade_history ──
|
|
512
|
+
|
|
513
|
+
export const GetMarginTradeHistoryInputSchema = z.object({
|
|
514
|
+
pair: z.string().optional().describe('通貨ペア(例: btc_jpy)。省略で全ペア'),
|
|
515
|
+
count: z.number().max(100).default(20).describe('取得件数(最大100)'),
|
|
516
|
+
order: z.enum(['asc', 'desc']).default('desc').describe('ソート順(asc: 古い順, desc: 新しい順)'),
|
|
517
|
+
since: z.string().optional().describe('開始日時(ISO8601、例: 2025-01-01T00:00:00+09:00)'),
|
|
518
|
+
end: z.string().optional().describe('終了日時(ISO8601、例: 2025-12-31T23:59:59+09:00)'),
|
|
519
|
+
});
|
|
520
|
+
|
|
521
|
+
const MarginTradeItemSchema = z.object({
|
|
522
|
+
trade_id: z.number().describe('約定ID'),
|
|
523
|
+
pair: z.string().describe('通貨ペア'),
|
|
524
|
+
order_id: z.number().describe('注文ID'),
|
|
525
|
+
side: z.string().describe('売買(buy / sell)'),
|
|
526
|
+
position_side: z.string().optional().describe('建玉方向(long / short)'),
|
|
527
|
+
type: z.string().describe('注文タイプ'),
|
|
528
|
+
amount: z.string().describe('約定数量'),
|
|
529
|
+
price: z.string().describe('約定価格'),
|
|
530
|
+
maker_taker: z.string().describe('メイカー / テイカー'),
|
|
531
|
+
fee_amount_base: z.string().describe('手数料(基軸通貨)'),
|
|
532
|
+
fee_amount_quote: z.string().describe('手数料(決済通貨)'),
|
|
533
|
+
profit_loss: z.string().optional().describe('実現損益(決済時のみ)'),
|
|
534
|
+
interest: z.string().optional().describe('利息(決済時のみ)'),
|
|
535
|
+
executed_at: z.string().describe('約定日時(ISO8601)'),
|
|
536
|
+
});
|
|
537
|
+
|
|
538
|
+
export const GetMarginTradeHistoryDataSchema = z.object({
|
|
539
|
+
trades: z.array(MarginTradeItemSchema),
|
|
540
|
+
timestamp: z.string(),
|
|
541
|
+
});
|
|
542
|
+
|
|
543
|
+
export const GetMarginTradeHistoryMetaSchema = z.object({
|
|
544
|
+
fetchedAt: z.string(),
|
|
545
|
+
tradeCount: z.number().int(),
|
|
546
|
+
pair: z.string().optional(),
|
|
547
|
+
});
|
|
548
|
+
|
|
549
|
+
export const GetMarginTradeHistoryOutputSchema = z.union([
|
|
550
|
+
z.object({
|
|
551
|
+
ok: z.literal(true),
|
|
552
|
+
summary: z.string(),
|
|
553
|
+
data: GetMarginTradeHistoryDataSchema,
|
|
554
|
+
meta: GetMarginTradeHistoryMetaSchema,
|
|
555
|
+
}),
|
|
556
|
+
PrivateFailResultSchema,
|
|
557
|
+
]);
|
|
558
|
+
|
|
559
|
+
// ── Trading: 注文レスポンス共通スキーマ ──
|
|
560
|
+
|
|
561
|
+
/** bitbank 注文ステータス */
|
|
562
|
+
export const OrderStatusEnum = z.enum([
|
|
563
|
+
'INACTIVE',
|
|
564
|
+
'UNFILLED',
|
|
565
|
+
'PARTIALLY_FILLED',
|
|
566
|
+
'FULLY_FILLED',
|
|
567
|
+
'CANCELED_UNFILLED',
|
|
568
|
+
'CANCELED_PARTIALLY_FILLED',
|
|
569
|
+
]);
|
|
570
|
+
|
|
571
|
+
/** 注文タイプ(現物・信用共通) */
|
|
572
|
+
export const SpotOrderTypeEnum = z.enum(['limit', 'market', 'stop', 'stop_limit']);
|
|
573
|
+
|
|
574
|
+
/** 信用取引の建玉方向 */
|
|
575
|
+
export const PositionSideEnum = z.enum(['long', 'short']);
|
|
576
|
+
|
|
577
|
+
/** 注文レスポンス(単一) — bitbank API が返す注文オブジェクト */
|
|
578
|
+
const OrderResponseSchema = z.object({
|
|
579
|
+
order_id: z.number().describe('注文ID'),
|
|
580
|
+
pair: z.string().describe('通貨ペア'),
|
|
581
|
+
side: z.enum(['buy', 'sell']).describe('売買方向'),
|
|
582
|
+
type: z.string().describe('注文タイプ'),
|
|
583
|
+
start_amount: z.string().nullable().describe('注文数量'),
|
|
584
|
+
remaining_amount: z.string().nullable().describe('未約定数量'),
|
|
585
|
+
executed_amount: z.string().describe('約定済み数量'),
|
|
586
|
+
price: z.string().optional().describe('指値価格'),
|
|
587
|
+
post_only: z.boolean().optional().describe('Post Only フラグ'),
|
|
588
|
+
user_cancelable: z.boolean().optional().describe('キャンセル可能か'),
|
|
589
|
+
average_price: z.string().describe('平均約定価格'),
|
|
590
|
+
ordered_at: z.number().describe('注文日時(unix ms)'),
|
|
591
|
+
expire_at: z.number().nullable().optional().describe('有効期限(unix ms)'),
|
|
592
|
+
triggered_at: z.union([z.number(), z.string()]).optional().describe('トリガー発動日時(unix ms or ISO 8601)'),
|
|
593
|
+
trigger_price: z.string().optional().describe('トリガー価格'),
|
|
594
|
+
canceled_at: z.number().optional().describe('キャンセル日時(unix ms)'),
|
|
595
|
+
status: z.string().describe('注文ステータス'),
|
|
596
|
+
});
|
|
597
|
+
|
|
598
|
+
export type OrderResponse = z.infer<typeof OrderResponseSchema>;
|
|
599
|
+
|
|
600
|
+
// ── preview_order(注文プレビュー・確認トークン発行) ──
|
|
601
|
+
|
|
602
|
+
export const PreviewOrderInputSchema = z
|
|
603
|
+
.object({
|
|
604
|
+
pair: z.string().describe('通貨ペア(例: btc_jpy)'),
|
|
605
|
+
amount: z.string().describe('注文数量'),
|
|
606
|
+
price: z.string().optional().describe('指値価格。limit / stop_limit で必須'),
|
|
607
|
+
side: z.enum(['buy', 'sell']).describe('売買方向'),
|
|
608
|
+
type: SpotOrderTypeEnum.describe('注文タイプ(limit / market / stop / stop_limit)'),
|
|
609
|
+
post_only: z.boolean().optional().describe('Post Only(limit のみ有効。Maker 手数料を確保)'),
|
|
610
|
+
trigger_price: z.string().optional().describe('トリガー価格。stop / stop_limit で必須'),
|
|
611
|
+
position_side: PositionSideEnum.optional().describe(
|
|
612
|
+
'信用取引の建玉方向。指定時は信用注文として扱う。' +
|
|
613
|
+
'ロング新規=buy+long, ロング決済=sell+long, ショート新規=sell+short, ショート決済=buy+short。' +
|
|
614
|
+
'⚠️ 信用取引です。損失が保証金を超える可能性があります',
|
|
615
|
+
),
|
|
616
|
+
})
|
|
617
|
+
.describe('注文内容をプレビューし、確認トークンを発行する。実際の発注は行わない');
|
|
618
|
+
|
|
619
|
+
export const PreviewOrderDataSchema = z.object({
|
|
620
|
+
confirmation_token: z.string().describe('create_order に渡す確認トークン'),
|
|
621
|
+
expires_at: z.number().describe('トークン有効期限(unix ms)'),
|
|
622
|
+
preview: z.object({
|
|
623
|
+
pair: z.string(),
|
|
624
|
+
amount: z.string(),
|
|
625
|
+
side: z.enum(['buy', 'sell']),
|
|
626
|
+
type: z.string(),
|
|
627
|
+
price: z.string().optional(),
|
|
628
|
+
trigger_price: z.string().optional(),
|
|
629
|
+
post_only: z.boolean().optional(),
|
|
630
|
+
position_side: PositionSideEnum.optional(),
|
|
631
|
+
}),
|
|
632
|
+
});
|
|
633
|
+
|
|
634
|
+
export const PreviewOrderMetaSchema = z.object({
|
|
635
|
+
action: z.literal('create_order'),
|
|
636
|
+
});
|
|
637
|
+
|
|
638
|
+
export const PreviewOrderOutputSchema = z.union([
|
|
639
|
+
z.object({
|
|
640
|
+
ok: z.literal(true),
|
|
641
|
+
summary: z.string(),
|
|
642
|
+
data: PreviewOrderDataSchema,
|
|
643
|
+
meta: PreviewOrderMetaSchema,
|
|
644
|
+
}),
|
|
645
|
+
PrivateFailResultSchema,
|
|
646
|
+
]);
|
|
647
|
+
|
|
648
|
+
// ── create_order(注文発注) ──
|
|
649
|
+
|
|
650
|
+
export const CreateOrderInputSchema = z
|
|
651
|
+
.object({
|
|
652
|
+
pair: z.string().describe('通貨ペア(例: btc_jpy)'),
|
|
653
|
+
amount: z.string().describe('注文数量'),
|
|
654
|
+
price: z.string().optional().describe('指値価格。limit / stop_limit で必須'),
|
|
655
|
+
side: z.enum(['buy', 'sell']).describe('売買方向'),
|
|
656
|
+
type: SpotOrderTypeEnum.describe('注文タイプ(limit / market / stop / stop_limit)'),
|
|
657
|
+
post_only: z.boolean().optional().describe('Post Only(limit のみ有効。Maker 手数料を確保)'),
|
|
658
|
+
trigger_price: z.string().optional().describe('トリガー価格。stop / stop_limit で必須'),
|
|
659
|
+
position_side: PositionSideEnum.optional().describe('信用取引の建玉方向。preview_order で指定した値をそのまま渡す'),
|
|
660
|
+
confirmation_token: z.string().describe('preview_order が発行した確認トークン'),
|
|
661
|
+
token_expires_at: z
|
|
662
|
+
.number()
|
|
663
|
+
.describe('確認トークンの有効期限(unix ms)。preview_order の expires_at をそのまま渡す'),
|
|
664
|
+
})
|
|
665
|
+
.describe('注文を発注する(現物または信用)。事前に preview_order で確認トークンを取得すること');
|
|
666
|
+
|
|
667
|
+
export const CreateOrderDataSchema = z.object({
|
|
668
|
+
order: OrderResponseSchema,
|
|
669
|
+
timestamp: z.string(),
|
|
670
|
+
});
|
|
671
|
+
|
|
672
|
+
export const CreateOrderMetaSchema = z.object({
|
|
673
|
+
fetchedAt: z.string(),
|
|
674
|
+
orderId: z.number(),
|
|
675
|
+
pair: z.string(),
|
|
676
|
+
side: z.enum(['buy', 'sell']),
|
|
677
|
+
type: z.string(),
|
|
678
|
+
});
|
|
679
|
+
|
|
680
|
+
export const CreateOrderOutputSchema = z.union([
|
|
681
|
+
z.object({
|
|
682
|
+
ok: z.literal(true),
|
|
683
|
+
summary: z.string(),
|
|
684
|
+
data: CreateOrderDataSchema,
|
|
685
|
+
meta: CreateOrderMetaSchema,
|
|
686
|
+
}),
|
|
687
|
+
PrivateFailResultSchema,
|
|
688
|
+
]);
|
|
689
|
+
|
|
690
|
+
// ── preview_cancel_order(キャンセルプレビュー・確認トークン発行) ──
|
|
691
|
+
|
|
692
|
+
export const PreviewCancelOrderInputSchema = z.object({
|
|
693
|
+
pair: z.string().describe('通貨ペア(例: btc_jpy)'),
|
|
694
|
+
order_id: z.number().describe('キャンセルする注文ID'),
|
|
695
|
+
});
|
|
696
|
+
|
|
697
|
+
export const PreviewCancelOrderDataSchema = z.object({
|
|
698
|
+
confirmation_token: z.string().describe('cancel_order に渡す確認トークン'),
|
|
699
|
+
expires_at: z.number().describe('トークン有効期限(unix ms)'),
|
|
700
|
+
preview: z.object({
|
|
701
|
+
pair: z.string(),
|
|
702
|
+
order_id: z.number(),
|
|
703
|
+
}),
|
|
704
|
+
/** 注文詳細(get_order で取得できた場合のみ)。UI / サマリ表示用で、トークン検証には使わない */
|
|
705
|
+
order: OrderResponseSchema.optional(),
|
|
706
|
+
});
|
|
707
|
+
|
|
708
|
+
export const PreviewCancelOrderMetaSchema = z.object({
|
|
709
|
+
action: z.literal('cancel_order'),
|
|
710
|
+
});
|
|
711
|
+
|
|
712
|
+
export const PreviewCancelOrderOutputSchema = z.union([
|
|
713
|
+
z.object({
|
|
714
|
+
ok: z.literal(true),
|
|
715
|
+
summary: z.string(),
|
|
716
|
+
data: PreviewCancelOrderDataSchema,
|
|
717
|
+
meta: PreviewCancelOrderMetaSchema,
|
|
718
|
+
}),
|
|
719
|
+
PrivateFailResultSchema,
|
|
720
|
+
]);
|
|
721
|
+
|
|
722
|
+
// ── cancel_order(注文キャンセル・単一) ──
|
|
723
|
+
|
|
724
|
+
export const CancelOrderInputSchema = z.object({
|
|
725
|
+
pair: z.string().describe('通貨ペア(例: btc_jpy)'),
|
|
726
|
+
order_id: z.number().describe('キャンセルする注文ID'),
|
|
727
|
+
confirmation_token: z.string().describe('preview_cancel_order が発行した確認トークン'),
|
|
728
|
+
token_expires_at: z.number().describe('確認トークンの有効期限(unix ms)'),
|
|
729
|
+
});
|
|
730
|
+
|
|
731
|
+
export const CancelOrderDataSchema = z.object({
|
|
732
|
+
order: OrderResponseSchema,
|
|
733
|
+
timestamp: z.string(),
|
|
734
|
+
});
|
|
735
|
+
|
|
736
|
+
export const CancelOrderMetaSchema = z.object({
|
|
737
|
+
fetchedAt: z.string(),
|
|
738
|
+
orderId: z.number(),
|
|
739
|
+
pair: z.string(),
|
|
740
|
+
});
|
|
741
|
+
|
|
742
|
+
export const CancelOrderOutputSchema = z.union([
|
|
743
|
+
z.object({
|
|
744
|
+
ok: z.literal(true),
|
|
745
|
+
summary: z.string(),
|
|
746
|
+
data: CancelOrderDataSchema,
|
|
747
|
+
meta: CancelOrderMetaSchema,
|
|
748
|
+
}),
|
|
749
|
+
PrivateFailResultSchema,
|
|
750
|
+
]);
|
|
751
|
+
|
|
752
|
+
// ── preview_cancel_orders(一括キャンセルプレビュー・確認トークン発行) ──
|
|
753
|
+
|
|
754
|
+
export const PreviewCancelOrdersInputSchema = z.object({
|
|
755
|
+
pair: z.string().describe('通貨ペア(例: btc_jpy)'),
|
|
756
|
+
order_ids: z.array(z.number()).min(1).max(30).describe('キャンセルする注文IDの配列(最大30件)'),
|
|
757
|
+
});
|
|
758
|
+
|
|
759
|
+
export const PreviewCancelOrdersDataSchema = z.object({
|
|
760
|
+
confirmation_token: z.string().describe('cancel_orders に渡す確認トークン'),
|
|
761
|
+
expires_at: z.number().describe('トークン有効期限(unix ms)'),
|
|
762
|
+
preview: z.object({
|
|
763
|
+
pair: z.string(),
|
|
764
|
+
order_ids: z.array(z.number()),
|
|
765
|
+
}),
|
|
766
|
+
});
|
|
767
|
+
|
|
768
|
+
export const PreviewCancelOrdersMetaSchema = z.object({
|
|
769
|
+
action: z.literal('cancel_orders'),
|
|
770
|
+
});
|
|
771
|
+
|
|
772
|
+
export const PreviewCancelOrdersOutputSchema = z.union([
|
|
773
|
+
z.object({
|
|
774
|
+
ok: z.literal(true),
|
|
775
|
+
summary: z.string(),
|
|
776
|
+
data: PreviewCancelOrdersDataSchema,
|
|
777
|
+
meta: PreviewCancelOrdersMetaSchema,
|
|
778
|
+
}),
|
|
779
|
+
PrivateFailResultSchema,
|
|
780
|
+
]);
|
|
781
|
+
|
|
782
|
+
// ── cancel_orders(注文キャンセル・複数) ──
|
|
783
|
+
|
|
784
|
+
export const CancelOrdersInputSchema = z.object({
|
|
785
|
+
pair: z.string().describe('通貨ペア(例: btc_jpy)'),
|
|
786
|
+
order_ids: z.array(z.number()).min(1).max(30).describe('キャンセルする注文IDの配列(最大30件)'),
|
|
787
|
+
confirmation_token: z.string().describe('preview_cancel_orders が発行した確認トークン'),
|
|
788
|
+
token_expires_at: z.number().describe('確認トークンの有効期限(unix ms)'),
|
|
789
|
+
});
|
|
790
|
+
|
|
791
|
+
export const CancelOrdersDataSchema = z.object({
|
|
792
|
+
orders: z.array(OrderResponseSchema),
|
|
793
|
+
timestamp: z.string(),
|
|
794
|
+
});
|
|
795
|
+
|
|
796
|
+
export const CancelOrdersMetaSchema = z.object({
|
|
797
|
+
fetchedAt: z.string(),
|
|
798
|
+
canceledCount: z.number().int(),
|
|
799
|
+
pair: z.string(),
|
|
800
|
+
});
|
|
801
|
+
|
|
802
|
+
export const CancelOrdersOutputSchema = z.union([
|
|
803
|
+
z.object({
|
|
804
|
+
ok: z.literal(true),
|
|
805
|
+
summary: z.string(),
|
|
806
|
+
data: CancelOrdersDataSchema,
|
|
807
|
+
meta: CancelOrdersMetaSchema,
|
|
808
|
+
}),
|
|
809
|
+
PrivateFailResultSchema,
|
|
810
|
+
]);
|
|
811
|
+
|
|
812
|
+
// ── get_order(注文照会・単一) ──
|
|
813
|
+
|
|
814
|
+
export const GetOrderInputSchema = z.object({
|
|
815
|
+
pair: z.string().describe('通貨ペア(例: btc_jpy)'),
|
|
816
|
+
order_id: z.number().describe('照会する注文ID'),
|
|
817
|
+
});
|
|
818
|
+
|
|
819
|
+
export const GetOrderDataSchema = z.object({
|
|
820
|
+
order: OrderResponseSchema,
|
|
821
|
+
timestamp: z.string(),
|
|
822
|
+
});
|
|
823
|
+
|
|
824
|
+
export const GetOrderMetaSchema = z.object({
|
|
825
|
+
fetchedAt: z.string(),
|
|
826
|
+
orderId: z.number(),
|
|
827
|
+
pair: z.string(),
|
|
828
|
+
});
|
|
829
|
+
|
|
830
|
+
export const GetOrderOutputSchema = z.union([
|
|
831
|
+
z.object({
|
|
832
|
+
ok: z.literal(true),
|
|
833
|
+
summary: z.string(),
|
|
834
|
+
data: GetOrderDataSchema,
|
|
835
|
+
meta: GetOrderMetaSchema,
|
|
836
|
+
}),
|
|
837
|
+
PrivateFailResultSchema,
|
|
838
|
+
]);
|
|
839
|
+
|
|
840
|
+
// ── get_orders_info(注文照会・複数) ──
|
|
841
|
+
|
|
842
|
+
export const GetOrdersInfoInputSchema = z.object({
|
|
843
|
+
pair: z.string().describe('通貨ペア(例: btc_jpy)'),
|
|
844
|
+
order_ids: z.array(z.number()).min(1).describe('照会する注文IDの配列'),
|
|
845
|
+
});
|
|
846
|
+
|
|
847
|
+
export const GetOrdersInfoDataSchema = z.object({
|
|
848
|
+
orders: z.array(OrderResponseSchema),
|
|
849
|
+
timestamp: z.string(),
|
|
850
|
+
});
|
|
851
|
+
|
|
852
|
+
export const GetOrdersInfoMetaSchema = z.object({
|
|
853
|
+
fetchedAt: z.string(),
|
|
854
|
+
orderCount: z.number().int(),
|
|
855
|
+
pair: z.string(),
|
|
856
|
+
});
|
|
857
|
+
|
|
858
|
+
export const GetOrdersInfoOutputSchema = z.union([
|
|
859
|
+
z.object({
|
|
860
|
+
ok: z.literal(true),
|
|
861
|
+
summary: z.string(),
|
|
862
|
+
data: GetOrdersInfoDataSchema,
|
|
863
|
+
meta: GetOrdersInfoMetaSchema,
|
|
864
|
+
}),
|
|
865
|
+
PrivateFailResultSchema,
|
|
866
|
+
]);
|