Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 1 addition & 19 deletions derive_client/data_types/channel_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
CancelReason,
Direction,
LegPricedSchema,
LegUnpricedSchema,
LiquidityRole,
MarginType,
OrderResponseSchema,
Expand All @@ -23,6 +22,7 @@
PublicGetInstrumentParamsSchema,
PublicGetOptionSettlementPricesParamsSchema,
PublicMarginWatchResultSchema,
RFQResultPublicSchema,
RPCErrorFormatSchema,
Status,
TickerSlimSchema,
Expand Down Expand Up @@ -314,24 +314,6 @@ class TradesInstrumentTypeCurrencyTxStatusNotificationParamsSchema(Struct):
data: List[TradeSettledPublicResponseSchema]


class RFQResultPublicSchema(Struct):
cancel_reason: CancelReason
creation_timestamp: int
filled_direction: Direction
filled_pct: Decimal
last_update_timestamp: int
legs: List[LegUnpricedSchema]
partial_fill_step: Decimal
rfq_id: str
status: Status
subaccount_id: int
valid_until: int
wallet: str
fill_rate: Optional[Decimal] = None
recent_fill_rate: Optional[Decimal] = None
total_cost: Optional[Decimal] = None


class AuctionsWatchNotificationParamsSchema(Struct):
channel: str
data: List[AuctionResultSchema]
Expand Down
63 changes: 34 additions & 29 deletions examples/rfqs/poll_rfq.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""

import asyncio
from time import sleep
from typing import Sequence

from config import ADMIN_TEST_WALLET as TEST_WALLET
from config import SESSION_KEY_PRIVATE_KEY
Expand All @@ -12,11 +12,10 @@
from derive_client import WebSocketClient
from derive_client._clients.utils import DeriveJSONRPCError
from derive_client.data_types import Environment
from derive_client.data_types.channel_models import RFQResultPublicSchema
from derive_client.data_types.generated_models import (
Direction,
LegPricedSchema,
RFQResultPublicSchema,
Status,
)
from derive_client.data_types.utils import D

Expand Down Expand Up @@ -57,36 +56,42 @@ async def main():
env=Environment.TEST,
subaccount_id=SUBACCOUNT_ID,
)
await client.connect()

async def on_rfq(rfq: RFQResultPublicSchema):
async def on_rfq(rfqs: Sequence[RFQResultPublicSchema]):
# here we get a price for the rfq.
# we first get the index price for the instrument
print(f"Received RFQ: {rfq}")
priced_legs = await create_priced_legs(client, rfq)
print(f"Total legs price: {sum([leg.price * leg.amount for leg in priced_legs])}")
try:
await client.rfq.send_quote(rfq_id=rfq.rfq_id, legs=priced_legs, direction=Direction.sell)
except DeriveJSONRPCError as e:
print(f"Error creating quote for RFQ {rfq.rfq_id}: {e}")
return

await client.connect()
print(f"Received {len(rfqs)} RFQs")
for rfq in rfqs:
priced_legs = await create_priced_legs(client, rfq)
print(f"Total legs price: {sum([leg.price * leg.amount for leg in priced_legs])}")
try:
await client.rfq.send_quote(rfq_id=rfq.rfq_id, legs=priced_legs, direction=Direction.sell)
except DeriveJSONRPCError as e:
print(f"Error creating quote for RFQ {rfq.rfq_id}: {e}")

await client.private_channels.rfqs_by_wallet(
wallet=TEST_WALLET,
callback=on_rfq,
)

rfqs = []
from_timestamp = 0
while True:
new_rfqs = await client.rfq.poll_rfqs(from_timestamp=from_timestamp)
for rfq in new_rfqs.rfqs:
if rfq.last_update_timestamp > from_timestamp:
from_timestamp = rfq.last_update_timestamp + 1
if rfq.status is Status.open:
task = asyncio.create_task(on_rfq(rfq))
rfqs.append(task)
for task in rfqs:
if task.done():
rfqs.remove(task)

sleep(SLEEP_TIME)
await asyncio.Event().wait()

# rfqs = []
# from_timestamp = 0
# while True:
# new_rfqs = await client.rfq.poll_rfqs(from_timestamp=from_timestamp)
# for rfq in new_rfqs.rfqs:
# if rfq.last_update_timestamp > from_timestamp:
# from_timestamp = rfq.last_update_timestamp + 1
# if rfq.status is Status.open:
# task = asyncio.create_task(on_rfq(rfq))
# rfqs.append(task)
# for task in rfqs:
# if task.done():
# rfqs.remove(task)

# sleep(SLEEP_TIME)


if __name__ == "__main__":
Expand Down
1 change: 1 addition & 0 deletions specs/channels/channel.wallet.rfqs.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
"buy",
"sell"
],
"nullable": true,
"description": "Direction at which the RFQ was filled (only if filled)"
},
"filled_pct": {
Expand Down
1 change: 1 addition & 0 deletions specs/websocket-channels.json
Original file line number Diff line number Diff line change
Expand Up @@ -2931,6 +2931,7 @@
"buy",
"sell"
],
"nullable": true,
"description": "Direction at which the RFQ was filled (only if filled)"
},
"filled_pct": {
Expand Down
Loading