@nadohq/otc-client
v0.54.0
Published
HTTP client for the Nado OTC service - execute a signed fill-or-kill order, read its status, and build RFQ quote subscriptions
Readme
@nadohq/otc-client
HTTP client for the Nado OTC service. Submits an already-signed fill-or-kill taker order, reads that execution back, and builds quote subscriptions. No bearer token and no wallet client.
The caller opens the quote WebSocket. A quote can prefill a form; execute does not
require one.
Usage
import { OtcClient, OTC_CLIENT_ENDPOINTS } from '@nadohq/otc-client';
const otc = new OtcClient({ url: OTC_CLIENT_ENDPOINTS.inkMainnet });
const result = await otc.execute({
dealId: crypto.randomUUID(),
taker,
});
if (result.deal_id && result.taker_digest) {
const status = await otc.getExecutionStatus({
dealId: result.deal_id,
takerDigest: result.taker_digest,
});
}A failure from admission has no digest, so there is nothing to poll. Poll an in-progress
failure once it includes taker_digest.
It is also available on a NadoClient context.
const result = await nadoClient.context.otcClient.execute({ dealId, taker });Quotes
subscribe and unsubscribe are the only RFQ methods. Pass streams, 1–100 entries applied
atomically; the service rejects a singular stream. unsubscribe repeats the same stream
fields. wallet is a 20-byte address.
Socket messages use the server types directly.
import {
buildOtcRfqSubscriptionMessage,
OTC_RFQ_WS_CLIENT_ENDPOINTS,
OtcServerRfqMessage,
} from '@nadohq/otc-client';
const ws = new WebSocket(OTC_RFQ_WS_CLIENT_ENDPOINTS.inkMainnet);
ws.onopen = () => {
ws.send(
JSON.stringify(
buildOtcRfqSubscriptionMessage('subscribe', {
id: 1,
streams: [
{
type: 'quote',
productId: 2,
wallet,
size: '-1000000000000000000',
sizeUnit: 'base',
},
],
}),
),
);
};
ws.onmessage = (event) => {
const message = JSON.parse(String(event.data)) as OtcServerRfqMessage;
if ('type' in message && message.type === 'quote_batch') {
for (const quote of message.quotes) {
if (quote.status === 'available' && quote.price_x18) {
// quote.price_x18, quote.valid_until_ms, quote.base_size
}
}
}
};An ack has result: null and sets error when the server rejected that request. A
quote_batch follows a successful subscribe. status: 'available' carries price_x18,
valid_until_ms, and base_size. status: 'unavailable' does not.
execute and getExecutionStatus return the JSON body for success, failure, and
pending_resolution, including non-200 admission responses. Branch on status and
recovery_action, not the HTTP code. getReady reports whether a route's quote and deal
coverage overlap.
