feat(mcp-deribit,mcp-bybit): add place_combo_order
Deribit: private/create_combo + place_order sul combo instrument → una sola crociata di spread invece di N (slippage atteso ridotto su strutture liquide). ACL core + leverage cap su tutti i leg. Bybit: place_batch_order su category=option (atomic multi-leg, 1 round-trip API). Reject su category != option (perp/linear non supportano batch nativo). orderLinkId auto-generato per leg. Tutti i test: deribit 48/48, bybit 123/123. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -221,6 +221,67 @@ async def test_get_dvol(httpx_mock: HTTPXMock, client: DeribitClient):
|
||||
assert result["candles"][0]["close"] == 57.0
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_place_combo_order(httpx_mock: HTTPXMock, client: DeribitClient):
|
||||
httpx_mock.add_response(
|
||||
url=re.compile(r"https://test\.deribit\.com/api/v2/public/auth"),
|
||||
json=AUTH_RESP,
|
||||
)
|
||||
httpx_mock.add_response(
|
||||
url=re.compile(r"https://test\.deribit\.com/api/v2/private/create_combo"),
|
||||
json={
|
||||
"result": {
|
||||
"id": "BTC-COMBO-1",
|
||||
"instrument_name": "BTC-COMBO-1",
|
||||
"state": "active",
|
||||
}
|
||||
},
|
||||
)
|
||||
httpx_mock.add_response(
|
||||
url=re.compile(r"https://test\.deribit\.com/api/v2/private/buy"),
|
||||
json={
|
||||
"result": {
|
||||
"order": {"order_id": "ord-1", "order_state": "open"},
|
||||
"trades": [],
|
||||
}
|
||||
},
|
||||
)
|
||||
legs = [
|
||||
{"instrument_name": "BTC-30APR26-75000-C", "direction": "buy", "ratio": 1},
|
||||
{"instrument_name": "BTC-30APR26-80000-C", "direction": "sell", "ratio": 1},
|
||||
]
|
||||
result = await client.place_combo_order(
|
||||
legs=legs,
|
||||
side="buy",
|
||||
amount=1,
|
||||
type="limit",
|
||||
price=0.05,
|
||||
label="vert-spread",
|
||||
)
|
||||
assert result["combo_instrument"] == "BTC-COMBO-1"
|
||||
assert result["order"]["order_id"] == "ord-1"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_place_combo_order_create_combo_error(httpx_mock: HTTPXMock, client: DeribitClient):
|
||||
httpx_mock.add_response(
|
||||
url=re.compile(r"https://test\.deribit\.com/api/v2/public/auth"),
|
||||
json=AUTH_RESP,
|
||||
)
|
||||
httpx_mock.add_response(
|
||||
url=re.compile(r"https://test\.deribit\.com/api/v2/private/create_combo"),
|
||||
json={"error": {"code": -32602, "message": "Invalid leg"}},
|
||||
)
|
||||
result = await client.place_combo_order(
|
||||
legs=[{"instrument_name": "BTC-X", "direction": "buy", "ratio": 1}],
|
||||
side="buy",
|
||||
amount=1,
|
||||
type="market",
|
||||
)
|
||||
assert result["state"] == "error"
|
||||
assert "Invalid leg" in str(result.get("error"))
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_cancel_order(httpx_mock: HTTPXMock, client: DeribitClient):
|
||||
httpx_mock.add_response(
|
||||
|
||||
Reference in New Issue
Block a user