@nadohq/otc-client 0.50.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/README.md +91 -0
- package/dist/OtcClient-qUPYb1BP.cjs +88 -0
- package/dist/OtcClient-qUPYb1BP.cjs.map +1 -0
- package/dist/OtcClient.cjs +3 -0
- package/dist/OtcClient.d.cts +44 -0
- package/dist/OtcClient.d.cts.map +1 -0
- package/dist/OtcClient.d.ts +44 -0
- package/dist/OtcClient.d.ts.map +1 -0
- package/dist/OtcClient.js +60 -0
- package/dist/OtcClient.js.map +1 -0
- package/dist/clientTypes-B7w3RxqK.d.cts +57 -0
- package/dist/clientTypes-B7w3RxqK.d.cts.map +1 -0
- package/dist/clientTypes-DVAoYtGx.d.ts +57 -0
- package/dist/clientTypes-DVAoYtGx.d.ts.map +1 -0
- package/dist/endpoints.cjs +24 -0
- package/dist/endpoints.cjs.map +1 -0
- package/dist/endpoints.d.cts +15 -0
- package/dist/endpoints.d.cts.map +1 -0
- package/dist/endpoints.d.ts +15 -0
- package/dist/endpoints.d.ts.map +1 -0
- package/dist/endpoints.js +22 -0
- package/dist/endpoints.js.map +1 -0
- package/dist/index.cjs +9 -0
- package/dist/index.d.cts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +5 -0
- package/dist/rfqSubscription.cjs +28 -0
- package/dist/rfqSubscription.cjs.map +1 -0
- package/dist/rfqSubscription.d.cts +14 -0
- package/dist/rfqSubscription.d.cts.map +1 -0
- package/dist/rfqSubscription.d.ts +14 -0
- package/dist/rfqSubscription.d.ts.map +1 -0
- package/dist/rfqSubscription.js +27 -0
- package/dist/rfqSubscription.js.map +1 -0
- package/dist/serverTypes-CZOJ78c_.d.cts +93 -0
- package/dist/serverTypes-CZOJ78c_.d.cts.map +1 -0
- package/dist/serverTypes-CZOJ78c_.d.ts +93 -0
- package/dist/serverTypes-CZOJ78c_.d.ts.map +1 -0
- package/dist/types/clientTypes.cjs +0 -0
- package/dist/types/clientTypes.d.cts +2 -0
- package/dist/types/clientTypes.d.ts +2 -0
- package/dist/types/clientTypes.js +1 -0
- package/dist/types/index.cjs +0 -0
- package/dist/types/index.d.cts +3 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.js +1 -0
- package/dist/types/serverTypes.cjs +0 -0
- package/dist/types/serverTypes.d.cts +2 -0
- package/dist/types/serverTypes.d.ts +2 -0
- package/dist/types/serverTypes.js +1 -0
- package/package.json +52 -0
- package/src/OtcClient.ts +90 -0
- package/src/endpoints.ts +20 -0
- package/src/index.ts +4 -0
- package/src/rfqSubscription.test.ts +50 -0
- package/src/rfqSubscription.ts +36 -0
- package/src/types/clientTypes.ts +66 -0
- package/src/types/index.ts +2 -0
- package/src/types/serverTypes.ts +111 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rfqSubscription.cjs","names":[],"sources":["../src/rfqSubscription.ts"],"sourcesContent":["import { OtcQuoteStream, OtcRfqSubscriptionParams } from './types/clientTypes';\nimport {\n OtcServerQuoteStream,\n OtcServerRfqSubscriptionRequest,\n} from './types/serverTypes';\n\nfunction toServerStream(stream: OtcQuoteStream): OtcServerQuoteStream {\n return {\n type: 'quote',\n product_id: stream.productId,\n wallet: stream.wallet,\n size: stream.size,\n size_unit: stream.sizeUnit,\n ...(stream.pricerId ? { pricer_id: stream.pricerId } : {}),\n };\n}\n\n/**\n * Builds a subscribe or unsubscribe message for the RFQ socket.\n * `unsubscribe` uses the same stream fields as the original `subscribe`.\n */\nexport function buildOtcRfqSubscriptionMessage<\n TMethod extends OtcServerRfqSubscriptionRequest['method'],\n>(\n method: TMethod,\n params: OtcRfqSubscriptionParams,\n): Extract<OtcServerRfqSubscriptionRequest, { method: TMethod }> {\n const body =\n 'stream' in params\n ? { stream: toServerStream(params.stream) }\n : { streams: params.streams.map(toServerStream) };\n return { method, id: params.id, ...body } as Extract<\n OtcServerRfqSubscriptionRequest,\n { method: TMethod }\n >;\n}\n"],"mappings":";;AAMA,SAAS,eAAe,QAA8C;CACpE,OAAO;EACL,MAAM;EACN,YAAY,OAAO;EACnB,QAAQ,OAAO;EACf,MAAM,OAAO;EACb,WAAW,OAAO;EAClB,GAAI,OAAO,WAAW,EAAE,WAAW,OAAO,SAAS,IAAI,CAAC;CAC1D;AACF;;;;;AAMA,SAAgB,+BAGd,QACA,QAC+D;CAC/D,MAAM,OACJ,YAAY,SACR,EAAE,QAAQ,eAAe,OAAO,MAAM,EAAE,IACxC,EAAE,SAAS,OAAO,QAAQ,IAAI,cAAc,EAAE;CACpD,OAAO;EAAE;EAAQ,IAAI,OAAO;EAAI,GAAG;CAAK;AAI1C"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { p as OtcServerRfqSubscriptionRequest } from "./serverTypes-CZOJ78c_.cjs";
|
|
2
|
+
import { o as OtcRfqSubscriptionParams } from "./clientTypes-B7w3RxqK.cjs";
|
|
3
|
+
|
|
4
|
+
//#region src/rfqSubscription.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Builds a subscribe or unsubscribe message for the RFQ socket.
|
|
7
|
+
* `unsubscribe` uses the same stream fields as the original `subscribe`.
|
|
8
|
+
*/
|
|
9
|
+
declare function buildOtcRfqSubscriptionMessage<TMethod extends OtcServerRfqSubscriptionRequest['method']>(method: TMethod, params: OtcRfqSubscriptionParams): Extract<OtcServerRfqSubscriptionRequest, {
|
|
10
|
+
method: TMethod;
|
|
11
|
+
}>;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { buildOtcRfqSubscriptionMessage };
|
|
14
|
+
//# sourceMappingURL=rfqSubscription.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rfqSubscription.d.cts","names":[],"sources":["../src/src/rfqSubscription.ts"],"mappings":";;;;;;AAqBA;;iBAAgB,8BAAA,iBACE,+BAAA,WAAA,CAEhB,MAAA,EAAQ,OAAA,EACR,MAAA,EAAQ,wBAAA,GACP,OAAA,CAAQ,+BAAA;EAAmC,MAAA,EAAQ,OAAA;AAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { p as OtcServerRfqSubscriptionRequest } from "./serverTypes-CZOJ78c_.js";
|
|
2
|
+
import { o as OtcRfqSubscriptionParams } from "./clientTypes-DVAoYtGx.js";
|
|
3
|
+
|
|
4
|
+
//#region src/rfqSubscription.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Builds a subscribe or unsubscribe message for the RFQ socket.
|
|
7
|
+
* `unsubscribe` uses the same stream fields as the original `subscribe`.
|
|
8
|
+
*/
|
|
9
|
+
declare function buildOtcRfqSubscriptionMessage<TMethod extends OtcServerRfqSubscriptionRequest['method']>(method: TMethod, params: OtcRfqSubscriptionParams): Extract<OtcServerRfqSubscriptionRequest, {
|
|
10
|
+
method: TMethod;
|
|
11
|
+
}>;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { buildOtcRfqSubscriptionMessage };
|
|
14
|
+
//# sourceMappingURL=rfqSubscription.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rfqSubscription.d.ts","names":[],"sources":["../src/src/rfqSubscription.ts"],"mappings":";;;;;;AAqBA;;iBAAgB,8BAAA,iBACE,+BAAA,WAAA,CAEhB,MAAA,EAAQ,OAAA,EACR,MAAA,EAAQ,wBAAA,GACP,OAAA,CAAQ,+BAAA;EAAmC,MAAA,EAAQ,OAAA;AAAA"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
//#region src/rfqSubscription.ts
|
|
2
|
+
function toServerStream(stream) {
|
|
3
|
+
return {
|
|
4
|
+
type: "quote",
|
|
5
|
+
product_id: stream.productId,
|
|
6
|
+
wallet: stream.wallet,
|
|
7
|
+
size: stream.size,
|
|
8
|
+
size_unit: stream.sizeUnit,
|
|
9
|
+
...stream.pricerId ? { pricer_id: stream.pricerId } : {}
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Builds a subscribe or unsubscribe message for the RFQ socket.
|
|
14
|
+
* `unsubscribe` uses the same stream fields as the original `subscribe`.
|
|
15
|
+
*/
|
|
16
|
+
function buildOtcRfqSubscriptionMessage(method, params) {
|
|
17
|
+
const body = "stream" in params ? { stream: toServerStream(params.stream) } : { streams: params.streams.map(toServerStream) };
|
|
18
|
+
return {
|
|
19
|
+
method,
|
|
20
|
+
id: params.id,
|
|
21
|
+
...body
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
export { buildOtcRfqSubscriptionMessage };
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=rfqSubscription.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rfqSubscription.js","names":[],"sources":["../src/rfqSubscription.ts"],"sourcesContent":["import { OtcQuoteStream, OtcRfqSubscriptionParams } from './types/clientTypes';\nimport {\n OtcServerQuoteStream,\n OtcServerRfqSubscriptionRequest,\n} from './types/serverTypes';\n\nfunction toServerStream(stream: OtcQuoteStream): OtcServerQuoteStream {\n return {\n type: 'quote',\n product_id: stream.productId,\n wallet: stream.wallet,\n size: stream.size,\n size_unit: stream.sizeUnit,\n ...(stream.pricerId ? { pricer_id: stream.pricerId } : {}),\n };\n}\n\n/**\n * Builds a subscribe or unsubscribe message for the RFQ socket.\n * `unsubscribe` uses the same stream fields as the original `subscribe`.\n */\nexport function buildOtcRfqSubscriptionMessage<\n TMethod extends OtcServerRfqSubscriptionRequest['method'],\n>(\n method: TMethod,\n params: OtcRfqSubscriptionParams,\n): Extract<OtcServerRfqSubscriptionRequest, { method: TMethod }> {\n const body =\n 'stream' in params\n ? { stream: toServerStream(params.stream) }\n : { streams: params.streams.map(toServerStream) };\n return { method, id: params.id, ...body } as Extract<\n OtcServerRfqSubscriptionRequest,\n { method: TMethod }\n >;\n}\n"],"mappings":";AAMA,SAAS,eAAe,QAA8C;CACpE,OAAO;EACL,MAAM;EACN,YAAY,OAAO;EACnB,QAAQ,OAAO;EACf,MAAM,OAAO;EACb,WAAW,OAAO;EAClB,GAAI,OAAO,WAAW,EAAE,WAAW,OAAO,SAAS,IAAI,CAAC;CAC1D;AACF;;;;;AAMA,SAAgB,+BAGd,QACA,QAC+D;CAC/D,MAAM,OACJ,YAAY,SACR,EAAE,QAAQ,eAAe,OAAO,MAAM,EAAE,IACxC,EAAE,SAAS,OAAO,QAAQ,IAAI,cAAc,EAAE;CACpD,OAAO;EAAE;EAAQ,IAAI,OAAO;EAAI,GAAG;CAAK;AAI1C"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
//#region src/types/serverTypes.d.ts
|
|
2
|
+
type OtcQuoteSizeUnit = 'base' | 'quote';
|
|
3
|
+
interface OtcServerExecutionDiagnostics {
|
|
4
|
+
failure_source?: string;
|
|
5
|
+
failure_stage?: string;
|
|
6
|
+
upstream_error_code?: number;
|
|
7
|
+
retryable?: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Documented values are `retry_same_request`, `sign_new_order`, `reconcile`, `wait`, and
|
|
10
|
+
* `none`. Anything else is returned as-is and does not authorize a resend.
|
|
11
|
+
*/
|
|
12
|
+
recovery_action?: string;
|
|
13
|
+
retry_after_ms?: number;
|
|
14
|
+
}
|
|
15
|
+
interface OtcServerExecutionSuccess {
|
|
16
|
+
status: 'success';
|
|
17
|
+
deal_id: string;
|
|
18
|
+
taker_digest: string;
|
|
19
|
+
settlement_id?: string;
|
|
20
|
+
}
|
|
21
|
+
interface OtcServerExecutionFailure extends OtcServerExecutionDiagnostics {
|
|
22
|
+
status: 'failure';
|
|
23
|
+
error: string;
|
|
24
|
+
error_code: number;
|
|
25
|
+
deal_id?: string;
|
|
26
|
+
taker_digest?: string;
|
|
27
|
+
}
|
|
28
|
+
interface OtcServerExecutionPendingResolution extends OtcServerExecutionDiagnostics {
|
|
29
|
+
status: 'pending_resolution';
|
|
30
|
+
deal_id: string;
|
|
31
|
+
taker_digest: string;
|
|
32
|
+
error?: string;
|
|
33
|
+
error_code?: number;
|
|
34
|
+
}
|
|
35
|
+
/** JSON body from `POST /v1/executor` and `POST /v1/executor/status`, including non-200 responses. */
|
|
36
|
+
type OtcServerExecutionResponse = OtcServerExecutionSuccess | OtcServerExecutionFailure | OtcServerExecutionPendingResolution;
|
|
37
|
+
interface OtcServerQuoteStream {
|
|
38
|
+
type: 'quote';
|
|
39
|
+
product_id: number;
|
|
40
|
+
wallet: string;
|
|
41
|
+
size: string;
|
|
42
|
+
size_unit: OtcQuoteSizeUnit;
|
|
43
|
+
pricer_id?: string;
|
|
44
|
+
}
|
|
45
|
+
interface OtcServerRfqSubscribeStreamRequest {
|
|
46
|
+
method: 'subscribe';
|
|
47
|
+
id: number;
|
|
48
|
+
stream: OtcServerQuoteStream;
|
|
49
|
+
}
|
|
50
|
+
interface OtcServerRfqSubscribeStreamsRequest {
|
|
51
|
+
method: 'subscribe';
|
|
52
|
+
id: number;
|
|
53
|
+
streams: OtcServerQuoteStream[];
|
|
54
|
+
}
|
|
55
|
+
interface OtcServerRfqUnsubscribeStreamRequest {
|
|
56
|
+
method: 'unsubscribe';
|
|
57
|
+
id: number;
|
|
58
|
+
stream: OtcServerQuoteStream;
|
|
59
|
+
}
|
|
60
|
+
interface OtcServerRfqUnsubscribeStreamsRequest {
|
|
61
|
+
method: 'unsubscribe';
|
|
62
|
+
id: number;
|
|
63
|
+
streams: OtcServerQuoteStream[];
|
|
64
|
+
}
|
|
65
|
+
type OtcServerRfqSubscriptionRequest = OtcServerRfqSubscribeStreamRequest | OtcServerRfqSubscribeStreamsRequest | OtcServerRfqUnsubscribeStreamRequest | OtcServerRfqUnsubscribeStreamsRequest;
|
|
66
|
+
/** One quote inside a `quote_batch`. `available` includes price fields; `unavailable` omits them. */
|
|
67
|
+
interface OtcServerQuote {
|
|
68
|
+
product_id: number;
|
|
69
|
+
type: 'quote';
|
|
70
|
+
size_unit: OtcQuoteSizeUnit;
|
|
71
|
+
size: string;
|
|
72
|
+
wallet: string;
|
|
73
|
+
pricer_id: string;
|
|
74
|
+
status: string;
|
|
75
|
+
price_x18?: string;
|
|
76
|
+
valid_until_ms?: string;
|
|
77
|
+
base_size?: string;
|
|
78
|
+
}
|
|
79
|
+
interface OtcServerQuoteBatch {
|
|
80
|
+
type: 'quote_batch';
|
|
81
|
+
time: string;
|
|
82
|
+
quotes: OtcServerQuote[];
|
|
83
|
+
}
|
|
84
|
+
interface OtcServerRfqAck {
|
|
85
|
+
result: null;
|
|
86
|
+
id: number;
|
|
87
|
+
/** Set when the server rejected the request. Absent on success. */
|
|
88
|
+
error?: string;
|
|
89
|
+
}
|
|
90
|
+
type OtcServerRfqMessage = OtcServerRfqAck | OtcServerQuoteBatch;
|
|
91
|
+
//#endregion
|
|
92
|
+
export { OtcServerExecutionSuccess as a, OtcServerQuoteStream as c, OtcServerRfqSubscribeStreamRequest as d, OtcServerRfqSubscribeStreamsRequest as f, OtcServerRfqUnsubscribeStreamsRequest as h, OtcServerExecutionResponse as i, OtcServerRfqAck as l, OtcServerRfqUnsubscribeStreamRequest as m, OtcServerExecutionFailure as n, OtcServerQuote as o, OtcServerRfqSubscriptionRequest as p, OtcServerExecutionPendingResolution as r, OtcServerQuoteBatch as s, OtcQuoteSizeUnit as t, OtcServerRfqMessage as u };
|
|
93
|
+
//# sourceMappingURL=serverTypes-CZOJ78c_.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serverTypes-CZOJ78c_.d.cts","names":[],"sources":["../src/types/src/types/serverTypes.ts"],"mappings":";KAAY,gBAAA;AAAA,UAEF,6BAAA;EACR,cAAA;EACA,aAAA;EACA,mBAAA;EACA,SAAA;EAJQ;;;;EASR,eAAA;EACA,cAAA;AAAA;AAAA,UAGe,yBAAA;EACf,MAAA;EACA,OAAA;EACA,YAAA;EACA,aAAA;AAAA;AAAA,UAGe,yBAAA,SAAkC,6BAA6B;EAC9E,MAAA;EACA,KAAA;EACA,UAAA;EACA,OAAA;EACA,YAAA;AAAA;AAAA,UAGe,mCAAA,SAA4C,6BAA6B;EACxF,MAAA;EACA,OAAA;EACA,YAAA;EACA,KAAA;EACA,UAAA;AAAA;;KAIU,0BAAA,GACR,yBAAA,GACA,yBAAA,GACA,mCAAA;AAAA,UAEa,oBAAA;EACf,IAAA;EACA,UAAA;EACA,MAAA;EACA,IAAA;EACA,SAAA,EAAW,gBAAgB;EAC3B,SAAA;AAAA;AAAA,UAGe,kCAAA;EACf,MAAA;EACA,EAAA;EACA,MAAA,EAAQ,oBAAoB;AAAA;AAAA,UAGb,mCAAA;EACf,MAAA;EACA,EAAA;EACA,OAAA,EAAS,oBAAoB;AAAA;AAAA,UAGd,oCAAA;EACf,MAAA;EACA,EAAA;EACA,MAAA,EAAQ,oBAAoB;AAAA;AAAA,UAGb,qCAAA;EACf,MAAA;EACA,EAAA;EACA,OAAA,EAAS,oBAAoB;AAAA;AAAA,KAGnB,+BAAA,GACR,kCAAA,GACA,mCAAA,GACA,oCAAA,GACA,qCAAA;AAvCmC;AAAA,UA0CtB,cAAA;EACf,UAAA;EACA,IAAA;EACA,SAAA,EAAW,gBAAgB;EAC3B,IAAA;EACA,MAAA;EACA,SAAA;EACA,MAAA;EACA,SAAA;EACA,cAAA;EACA,SAAA;AAAA;AAAA,UAGe,mBAAA;EACf,IAAA;EACA,IAAA;EACA,MAAA,EAAQ,cAAc;AAAA;AAAA,UAGP,eAAA;EACf,MAAA;EACA,EAAA;EAjDQ;EAmDR,KAAA;AAAA;AAAA,KAGU,mBAAA,GAAsB,eAAA,GAAkB,mBAAmB"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
//#region src/types/serverTypes.d.ts
|
|
2
|
+
type OtcQuoteSizeUnit = 'base' | 'quote';
|
|
3
|
+
interface OtcServerExecutionDiagnostics {
|
|
4
|
+
failure_source?: string;
|
|
5
|
+
failure_stage?: string;
|
|
6
|
+
upstream_error_code?: number;
|
|
7
|
+
retryable?: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Documented values are `retry_same_request`, `sign_new_order`, `reconcile`, `wait`, and
|
|
10
|
+
* `none`. Anything else is returned as-is and does not authorize a resend.
|
|
11
|
+
*/
|
|
12
|
+
recovery_action?: string;
|
|
13
|
+
retry_after_ms?: number;
|
|
14
|
+
}
|
|
15
|
+
interface OtcServerExecutionSuccess {
|
|
16
|
+
status: 'success';
|
|
17
|
+
deal_id: string;
|
|
18
|
+
taker_digest: string;
|
|
19
|
+
settlement_id?: string;
|
|
20
|
+
}
|
|
21
|
+
interface OtcServerExecutionFailure extends OtcServerExecutionDiagnostics {
|
|
22
|
+
status: 'failure';
|
|
23
|
+
error: string;
|
|
24
|
+
error_code: number;
|
|
25
|
+
deal_id?: string;
|
|
26
|
+
taker_digest?: string;
|
|
27
|
+
}
|
|
28
|
+
interface OtcServerExecutionPendingResolution extends OtcServerExecutionDiagnostics {
|
|
29
|
+
status: 'pending_resolution';
|
|
30
|
+
deal_id: string;
|
|
31
|
+
taker_digest: string;
|
|
32
|
+
error?: string;
|
|
33
|
+
error_code?: number;
|
|
34
|
+
}
|
|
35
|
+
/** JSON body from `POST /v1/executor` and `POST /v1/executor/status`, including non-200 responses. */
|
|
36
|
+
type OtcServerExecutionResponse = OtcServerExecutionSuccess | OtcServerExecutionFailure | OtcServerExecutionPendingResolution;
|
|
37
|
+
interface OtcServerQuoteStream {
|
|
38
|
+
type: 'quote';
|
|
39
|
+
product_id: number;
|
|
40
|
+
wallet: string;
|
|
41
|
+
size: string;
|
|
42
|
+
size_unit: OtcQuoteSizeUnit;
|
|
43
|
+
pricer_id?: string;
|
|
44
|
+
}
|
|
45
|
+
interface OtcServerRfqSubscribeStreamRequest {
|
|
46
|
+
method: 'subscribe';
|
|
47
|
+
id: number;
|
|
48
|
+
stream: OtcServerQuoteStream;
|
|
49
|
+
}
|
|
50
|
+
interface OtcServerRfqSubscribeStreamsRequest {
|
|
51
|
+
method: 'subscribe';
|
|
52
|
+
id: number;
|
|
53
|
+
streams: OtcServerQuoteStream[];
|
|
54
|
+
}
|
|
55
|
+
interface OtcServerRfqUnsubscribeStreamRequest {
|
|
56
|
+
method: 'unsubscribe';
|
|
57
|
+
id: number;
|
|
58
|
+
stream: OtcServerQuoteStream;
|
|
59
|
+
}
|
|
60
|
+
interface OtcServerRfqUnsubscribeStreamsRequest {
|
|
61
|
+
method: 'unsubscribe';
|
|
62
|
+
id: number;
|
|
63
|
+
streams: OtcServerQuoteStream[];
|
|
64
|
+
}
|
|
65
|
+
type OtcServerRfqSubscriptionRequest = OtcServerRfqSubscribeStreamRequest | OtcServerRfqSubscribeStreamsRequest | OtcServerRfqUnsubscribeStreamRequest | OtcServerRfqUnsubscribeStreamsRequest;
|
|
66
|
+
/** One quote inside a `quote_batch`. `available` includes price fields; `unavailable` omits them. */
|
|
67
|
+
interface OtcServerQuote {
|
|
68
|
+
product_id: number;
|
|
69
|
+
type: 'quote';
|
|
70
|
+
size_unit: OtcQuoteSizeUnit;
|
|
71
|
+
size: string;
|
|
72
|
+
wallet: string;
|
|
73
|
+
pricer_id: string;
|
|
74
|
+
status: string;
|
|
75
|
+
price_x18?: string;
|
|
76
|
+
valid_until_ms?: string;
|
|
77
|
+
base_size?: string;
|
|
78
|
+
}
|
|
79
|
+
interface OtcServerQuoteBatch {
|
|
80
|
+
type: 'quote_batch';
|
|
81
|
+
time: string;
|
|
82
|
+
quotes: OtcServerQuote[];
|
|
83
|
+
}
|
|
84
|
+
interface OtcServerRfqAck {
|
|
85
|
+
result: null;
|
|
86
|
+
id: number;
|
|
87
|
+
/** Set when the server rejected the request. Absent on success. */
|
|
88
|
+
error?: string;
|
|
89
|
+
}
|
|
90
|
+
type OtcServerRfqMessage = OtcServerRfqAck | OtcServerQuoteBatch;
|
|
91
|
+
//#endregion
|
|
92
|
+
export { OtcServerExecutionSuccess as a, OtcServerQuoteStream as c, OtcServerRfqSubscribeStreamRequest as d, OtcServerRfqSubscribeStreamsRequest as f, OtcServerRfqUnsubscribeStreamsRequest as h, OtcServerExecutionResponse as i, OtcServerRfqAck as l, OtcServerRfqUnsubscribeStreamRequest as m, OtcServerExecutionFailure as n, OtcServerQuote as o, OtcServerRfqSubscriptionRequest as p, OtcServerExecutionPendingResolution as r, OtcServerQuoteBatch as s, OtcQuoteSizeUnit as t, OtcServerRfqMessage as u };
|
|
93
|
+
//# sourceMappingURL=serverTypes-CZOJ78c_.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serverTypes-CZOJ78c_.d.ts","names":[],"sources":["../src/types/src/types/serverTypes.ts"],"mappings":";KAAY,gBAAA;AAAA,UAEF,6BAAA;EACR,cAAA;EACA,aAAA;EACA,mBAAA;EACA,SAAA;EAJQ;;;;EASR,eAAA;EACA,cAAA;AAAA;AAAA,UAGe,yBAAA;EACf,MAAA;EACA,OAAA;EACA,YAAA;EACA,aAAA;AAAA;AAAA,UAGe,yBAAA,SAAkC,6BAA6B;EAC9E,MAAA;EACA,KAAA;EACA,UAAA;EACA,OAAA;EACA,YAAA;AAAA;AAAA,UAGe,mCAAA,SAA4C,6BAA6B;EACxF,MAAA;EACA,OAAA;EACA,YAAA;EACA,KAAA;EACA,UAAA;AAAA;;KAIU,0BAAA,GACR,yBAAA,GACA,yBAAA,GACA,mCAAA;AAAA,UAEa,oBAAA;EACf,IAAA;EACA,UAAA;EACA,MAAA;EACA,IAAA;EACA,SAAA,EAAW,gBAAgB;EAC3B,SAAA;AAAA;AAAA,UAGe,kCAAA;EACf,MAAA;EACA,EAAA;EACA,MAAA,EAAQ,oBAAoB;AAAA;AAAA,UAGb,mCAAA;EACf,MAAA;EACA,EAAA;EACA,OAAA,EAAS,oBAAoB;AAAA;AAAA,UAGd,oCAAA;EACf,MAAA;EACA,EAAA;EACA,MAAA,EAAQ,oBAAoB;AAAA;AAAA,UAGb,qCAAA;EACf,MAAA;EACA,EAAA;EACA,OAAA,EAAS,oBAAoB;AAAA;AAAA,KAGnB,+BAAA,GACR,kCAAA,GACA,mCAAA,GACA,oCAAA,GACA,qCAAA;AAvCmC;AAAA,UA0CtB,cAAA;EACf,UAAA;EACA,IAAA;EACA,SAAA,EAAW,gBAAgB;EAC3B,IAAA;EACA,MAAA;EACA,SAAA;EACA,MAAA;EACA,SAAA;EACA,cAAA;EACA,SAAA;AAAA;AAAA,UAGe,mBAAA;EACf,IAAA;EACA,IAAA;EACA,MAAA,EAAQ,cAAc;AAAA;AAAA,UAGP,eAAA;EACf,MAAA;EACA,EAAA;EAjDQ;EAmDR,KAAA;AAAA;AAAA,KAGU,mBAAA,GAAsB,eAAA,GAAkB,mBAAmB"}
|
|
File without changes
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as OtcReadyResult, c as OtcRfqSubscriptionStreamsParams, i as OtcQuoteStream, l as OtcServerTakerOrderParams, n as OtcGetExecutionStatusParams, o as OtcRfqSubscriptionParams, r as OtcGetReadyParams, s as OtcRfqSubscriptionStreamParams, t as OtcExecuteParams } from "../clientTypes-B7w3RxqK.cjs";
|
|
2
|
+
export { OtcExecuteParams, OtcGetExecutionStatusParams, OtcGetReadyParams, OtcQuoteStream, OtcReadyResult, OtcRfqSubscriptionParams, OtcRfqSubscriptionStreamParams, OtcRfqSubscriptionStreamsParams, OtcServerTakerOrderParams };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as OtcReadyResult, c as OtcRfqSubscriptionStreamsParams, i as OtcQuoteStream, l as OtcServerTakerOrderParams, n as OtcGetExecutionStatusParams, o as OtcRfqSubscriptionParams, r as OtcGetReadyParams, s as OtcRfqSubscriptionStreamParams, t as OtcExecuteParams } from "../clientTypes-DVAoYtGx.js";
|
|
2
|
+
export { OtcExecuteParams, OtcGetExecutionStatusParams, OtcGetReadyParams, OtcQuoteStream, OtcReadyResult, OtcRfqSubscriptionParams, OtcRfqSubscriptionStreamParams, OtcRfqSubscriptionStreamsParams, OtcServerTakerOrderParams };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
File without changes
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { a as OtcServerExecutionSuccess, c as OtcServerQuoteStream, d as OtcServerRfqSubscribeStreamRequest, f as OtcServerRfqSubscribeStreamsRequest, h as OtcServerRfqUnsubscribeStreamsRequest, i as OtcServerExecutionResponse, l as OtcServerRfqAck, m as OtcServerRfqUnsubscribeStreamRequest, n as OtcServerExecutionFailure, o as OtcServerQuote, p as OtcServerRfqSubscriptionRequest, r as OtcServerExecutionPendingResolution, s as OtcServerQuoteBatch, t as OtcQuoteSizeUnit, u as OtcServerRfqMessage } from "../serverTypes-CZOJ78c_.cjs";
|
|
2
|
+
import { a as OtcReadyResult, c as OtcRfqSubscriptionStreamsParams, i as OtcQuoteStream, l as OtcServerTakerOrderParams, n as OtcGetExecutionStatusParams, o as OtcRfqSubscriptionParams, r as OtcGetReadyParams, s as OtcRfqSubscriptionStreamParams, t as OtcExecuteParams } from "../clientTypes-B7w3RxqK.cjs";
|
|
3
|
+
export { OtcExecuteParams, OtcGetExecutionStatusParams, OtcGetReadyParams, OtcQuoteSizeUnit, OtcQuoteStream, OtcReadyResult, OtcRfqSubscriptionParams, OtcRfqSubscriptionStreamParams, OtcRfqSubscriptionStreamsParams, OtcServerExecutionFailure, OtcServerExecutionPendingResolution, OtcServerExecutionResponse, OtcServerExecutionSuccess, OtcServerQuote, OtcServerQuoteBatch, OtcServerQuoteStream, OtcServerRfqAck, OtcServerRfqMessage, OtcServerRfqSubscribeStreamRequest, OtcServerRfqSubscribeStreamsRequest, OtcServerRfqSubscriptionRequest, OtcServerRfqUnsubscribeStreamRequest, OtcServerRfqUnsubscribeStreamsRequest, OtcServerTakerOrderParams };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { a as OtcServerExecutionSuccess, c as OtcServerQuoteStream, d as OtcServerRfqSubscribeStreamRequest, f as OtcServerRfqSubscribeStreamsRequest, h as OtcServerRfqUnsubscribeStreamsRequest, i as OtcServerExecutionResponse, l as OtcServerRfqAck, m as OtcServerRfqUnsubscribeStreamRequest, n as OtcServerExecutionFailure, o as OtcServerQuote, p as OtcServerRfqSubscriptionRequest, r as OtcServerExecutionPendingResolution, s as OtcServerQuoteBatch, t as OtcQuoteSizeUnit, u as OtcServerRfqMessage } from "../serverTypes-CZOJ78c_.js";
|
|
2
|
+
import { a as OtcReadyResult, c as OtcRfqSubscriptionStreamsParams, i as OtcQuoteStream, l as OtcServerTakerOrderParams, n as OtcGetExecutionStatusParams, o as OtcRfqSubscriptionParams, r as OtcGetReadyParams, s as OtcRfqSubscriptionStreamParams, t as OtcExecuteParams } from "../clientTypes-DVAoYtGx.js";
|
|
3
|
+
export { OtcExecuteParams, OtcGetExecutionStatusParams, OtcGetReadyParams, OtcQuoteSizeUnit, OtcQuoteStream, OtcReadyResult, OtcRfqSubscriptionParams, OtcRfqSubscriptionStreamParams, OtcRfqSubscriptionStreamsParams, OtcServerExecutionFailure, OtcServerExecutionPendingResolution, OtcServerExecutionResponse, OtcServerExecutionSuccess, OtcServerQuote, OtcServerQuoteBatch, OtcServerQuoteStream, OtcServerRfqAck, OtcServerRfqMessage, OtcServerRfqSubscribeStreamRequest, OtcServerRfqSubscribeStreamsRequest, OtcServerRfqSubscriptionRequest, OtcServerRfqUnsubscribeStreamRequest, OtcServerRfqUnsubscribeStreamsRequest, OtcServerTakerOrderParams };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
File without changes
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as OtcServerExecutionSuccess, c as OtcServerQuoteStream, d as OtcServerRfqSubscribeStreamRequest, f as OtcServerRfqSubscribeStreamsRequest, h as OtcServerRfqUnsubscribeStreamsRequest, i as OtcServerExecutionResponse, l as OtcServerRfqAck, m as OtcServerRfqUnsubscribeStreamRequest, n as OtcServerExecutionFailure, o as OtcServerQuote, p as OtcServerRfqSubscriptionRequest, r as OtcServerExecutionPendingResolution, s as OtcServerQuoteBatch, t as OtcQuoteSizeUnit, u as OtcServerRfqMessage } from "../serverTypes-CZOJ78c_.cjs";
|
|
2
|
+
export { OtcQuoteSizeUnit, OtcServerExecutionFailure, OtcServerExecutionPendingResolution, OtcServerExecutionResponse, OtcServerExecutionSuccess, OtcServerQuote, OtcServerQuoteBatch, OtcServerQuoteStream, OtcServerRfqAck, OtcServerRfqMessage, OtcServerRfqSubscribeStreamRequest, OtcServerRfqSubscribeStreamsRequest, OtcServerRfqSubscriptionRequest, OtcServerRfqUnsubscribeStreamRequest, OtcServerRfqUnsubscribeStreamsRequest };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as OtcServerExecutionSuccess, c as OtcServerQuoteStream, d as OtcServerRfqSubscribeStreamRequest, f as OtcServerRfqSubscribeStreamsRequest, h as OtcServerRfqUnsubscribeStreamsRequest, i as OtcServerExecutionResponse, l as OtcServerRfqAck, m as OtcServerRfqUnsubscribeStreamRequest, n as OtcServerExecutionFailure, o as OtcServerQuote, p as OtcServerRfqSubscriptionRequest, r as OtcServerExecutionPendingResolution, s as OtcServerQuoteBatch, t as OtcQuoteSizeUnit, u as OtcServerRfqMessage } from "../serverTypes-CZOJ78c_.js";
|
|
2
|
+
export { OtcQuoteSizeUnit, OtcServerExecutionFailure, OtcServerExecutionPendingResolution, OtcServerExecutionResponse, OtcServerExecutionSuccess, OtcServerQuote, OtcServerQuoteBatch, OtcServerQuoteStream, OtcServerRfqAck, OtcServerRfqMessage, OtcServerRfqSubscribeStreamRequest, OtcServerRfqSubscribeStreamsRequest, OtcServerRfqSubscriptionRequest, OtcServerRfqUnsubscribeStreamRequest, OtcServerRfqUnsubscribeStreamsRequest };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nadohq/otc-client",
|
|
3
|
+
"version": "0.50.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"sideEffects": false,
|
|
6
|
+
"description": "HTTP client for the Nado OTC service - execute a signed fill-or-kill order, read its status, and build RFQ quote subscriptions",
|
|
7
|
+
"author": "Frank Jia <frank@inkfnd.com>",
|
|
8
|
+
"homepage": "",
|
|
9
|
+
"license": "ISC",
|
|
10
|
+
"source": "./src/index.ts",
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public"
|
|
13
|
+
},
|
|
14
|
+
"repository": "https://github.com/nadohq/nado-typescript-sdk",
|
|
15
|
+
"scripts": {
|
|
16
|
+
"clean": "rm -rf dist && rm -f tsconfig.tsbuildinfo",
|
|
17
|
+
"build": "tsdown",
|
|
18
|
+
"dev": "tsc -w",
|
|
19
|
+
"lint": "eslint --cache './**/*.{ts,tsx}'",
|
|
20
|
+
"lint:fix": "eslint --cache --fix './**/*.{ts,tsx}'",
|
|
21
|
+
"typecheck": "tsc --noEmit"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist",
|
|
25
|
+
"src"
|
|
26
|
+
],
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"import": {
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"import": "./dist/index.js"
|
|
32
|
+
},
|
|
33
|
+
"require": {
|
|
34
|
+
"types": "./dist/index.d.cts",
|
|
35
|
+
"default": "./dist/index.cjs"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"react-native": "./dist/index.js",
|
|
40
|
+
"main": "./dist/index.cjs",
|
|
41
|
+
"module": "./dist/index.js",
|
|
42
|
+
"types": "./dist/index.d.ts",
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@nadohq/engine-client": "^0.50.0",
|
|
45
|
+
"@nadohq/shared": "^0.50.0",
|
|
46
|
+
"axios": "1.16.1"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@jest/globals": "30.4.1"
|
|
50
|
+
},
|
|
51
|
+
"gitHead": "887a17f2b449404d6556c1dc7340bd10ba4a8572"
|
|
52
|
+
}
|
package/src/OtcClient.ts
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { getNadoClientTypeHeaders } from '@nadohq/shared';
|
|
2
|
+
import axios, { AxiosInstance } from 'axios';
|
|
3
|
+
import {
|
|
4
|
+
OtcExecuteParams,
|
|
5
|
+
OtcGetExecutionStatusParams,
|
|
6
|
+
OtcGetReadyParams,
|
|
7
|
+
OtcReadyResult,
|
|
8
|
+
} from './types/clientTypes';
|
|
9
|
+
import { OtcServerExecutionResponse } from './types/serverTypes';
|
|
10
|
+
|
|
11
|
+
export interface OtcClientOpts {
|
|
12
|
+
/**
|
|
13
|
+
* OTC service origin, without a path, e.g. {@link OTC_CLIENT_ENDPOINTS}.
|
|
14
|
+
*/
|
|
15
|
+
url: string;
|
|
16
|
+
// If provided, identifies the calling client, sent as a header with every request
|
|
17
|
+
clientType?: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Client for the public OTC service.
|
|
22
|
+
*
|
|
23
|
+
* {@link OtcClient.execute} does not sign. The caller supplies an already-signed taker order.
|
|
24
|
+
* A quote is not required. {@link OtcClient.getExecutionStatus} only reads a deal; it does not
|
|
25
|
+
* start or resume one.
|
|
26
|
+
*
|
|
27
|
+
* Responses are the JSON body as returned, including non-200 admission responses. Branch on
|
|
28
|
+
* `status` and `recovery_action`.
|
|
29
|
+
*/
|
|
30
|
+
export class OtcClient {
|
|
31
|
+
readonly opts: OtcClientOpts;
|
|
32
|
+
readonly axiosInstance: AxiosInstance;
|
|
33
|
+
|
|
34
|
+
constructor(opts: OtcClientOpts) {
|
|
35
|
+
this.opts = opts;
|
|
36
|
+
this.axiosInstance = axios.create({
|
|
37
|
+
withCredentials: false,
|
|
38
|
+
validateStatus: () => true,
|
|
39
|
+
headers: getNadoClientTypeHeaders(opts.clientType),
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Submits a signed taker order. Send this body unchanged on `retry_same_request`.
|
|
45
|
+
*/
|
|
46
|
+
async execute(params: OtcExecuteParams): Promise<OtcServerExecutionResponse> {
|
|
47
|
+
return this.postExecution('/v1/executor', {
|
|
48
|
+
deal_id: params.dealId,
|
|
49
|
+
taker: params.taker,
|
|
50
|
+
...(params.pricerId ? { pricer_id: params.pricerId } : {}),
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Reads one execution. Use it after a lost response, a refresh, or `wait`.
|
|
56
|
+
*/
|
|
57
|
+
async getExecutionStatus(
|
|
58
|
+
params: OtcGetExecutionStatusParams,
|
|
59
|
+
): Promise<OtcServerExecutionResponse> {
|
|
60
|
+
return this.postExecution('/v1/executor/status', {
|
|
61
|
+
deal_id: params.dealId,
|
|
62
|
+
taker_digest: params.takerDigest,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Checks that quote and deal product scopes overlap for a route. An omitted `pricerId`
|
|
68
|
+
* asks the service default. A direct execution needs a matching deal worker, not a prior quote.
|
|
69
|
+
*/
|
|
70
|
+
async getReady(params: OtcGetReadyParams = {}): Promise<OtcReadyResult> {
|
|
71
|
+
const response = await this.axiosInstance.get(`${this.opts.url}/ready`, {
|
|
72
|
+
params: params.pricerId ? { pricer_id: params.pricerId } : undefined,
|
|
73
|
+
});
|
|
74
|
+
return {
|
|
75
|
+
httpStatus: response.status,
|
|
76
|
+
ready: response.status === 200,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
private async postExecution(
|
|
81
|
+
path: string,
|
|
82
|
+
body: unknown,
|
|
83
|
+
): Promise<OtcServerExecutionResponse> {
|
|
84
|
+
const response = await this.axiosInstance.post(
|
|
85
|
+
`${this.opts.url}${path}`,
|
|
86
|
+
body,
|
|
87
|
+
);
|
|
88
|
+
return response.data as OtcServerExecutionResponse;
|
|
89
|
+
}
|
|
90
|
+
}
|
package/src/endpoints.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ChainEnv } from '@nadohq/shared';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* OTC service origin per chain env. `local` uses the testnet service; there is no localhost
|
|
5
|
+
* deployment.
|
|
6
|
+
*/
|
|
7
|
+
export const OTC_CLIENT_ENDPOINTS: Record<ChainEnv, string> = {
|
|
8
|
+
local: 'https://otc.test.nado-backend.xyz',
|
|
9
|
+
inkTestnet: 'https://otc.test.nado-backend.xyz',
|
|
10
|
+
inkMainnet: 'https://otc.prod.nado-backend.xyz',
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Taker quote socket per chain env. The caller opens it.
|
|
15
|
+
*/
|
|
16
|
+
export const OTC_RFQ_WS_CLIENT_ENDPOINTS: Record<ChainEnv, string> = {
|
|
17
|
+
local: 'wss://otc.test.nado-backend.xyz/v1/rfqs/ws',
|
|
18
|
+
inkTestnet: 'wss://otc.test.nado-backend.xyz/v1/rfqs/ws',
|
|
19
|
+
inkMainnet: 'wss://otc.prod.nado-backend.xyz/v1/rfqs/ws',
|
|
20
|
+
};
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { describe, expect, it } from '@jest/globals';
|
|
2
|
+
import { buildOtcRfqSubscriptionMessage } from './rfqSubscription';
|
|
3
|
+
|
|
4
|
+
const stream = {
|
|
5
|
+
type: 'quote' as const,
|
|
6
|
+
productId: 2,
|
|
7
|
+
wallet: '0x2222222222222222222222222222222222222222',
|
|
8
|
+
size: '-1000000000000000000',
|
|
9
|
+
sizeUnit: 'base' as const,
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
describe('buildOtcRfqSubscriptionMessage', () => {
|
|
13
|
+
it('builds one stream and omits an empty pricer', () => {
|
|
14
|
+
expect(
|
|
15
|
+
buildOtcRfqSubscriptionMessage('subscribe', { id: 1, stream }),
|
|
16
|
+
).toEqual({
|
|
17
|
+
method: 'subscribe',
|
|
18
|
+
id: 1,
|
|
19
|
+
stream: {
|
|
20
|
+
type: 'quote',
|
|
21
|
+
product_id: 2,
|
|
22
|
+
wallet: stream.wallet,
|
|
23
|
+
size: stream.size,
|
|
24
|
+
size_unit: 'base',
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('builds several streams and keeps a pricer id', () => {
|
|
30
|
+
expect(
|
|
31
|
+
buildOtcRfqSubscriptionMessage('unsubscribe', {
|
|
32
|
+
id: 2,
|
|
33
|
+
streams: [{ ...stream, pricerId: 'awr' }],
|
|
34
|
+
}),
|
|
35
|
+
).toEqual({
|
|
36
|
+
method: 'unsubscribe',
|
|
37
|
+
id: 2,
|
|
38
|
+
streams: [
|
|
39
|
+
{
|
|
40
|
+
type: 'quote',
|
|
41
|
+
product_id: 2,
|
|
42
|
+
wallet: stream.wallet,
|
|
43
|
+
size: stream.size,
|
|
44
|
+
size_unit: 'base',
|
|
45
|
+
pricer_id: 'awr',
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { OtcQuoteStream, OtcRfqSubscriptionParams } from './types/clientTypes';
|
|
2
|
+
import {
|
|
3
|
+
OtcServerQuoteStream,
|
|
4
|
+
OtcServerRfqSubscriptionRequest,
|
|
5
|
+
} from './types/serverTypes';
|
|
6
|
+
|
|
7
|
+
function toServerStream(stream: OtcQuoteStream): OtcServerQuoteStream {
|
|
8
|
+
return {
|
|
9
|
+
type: 'quote',
|
|
10
|
+
product_id: stream.productId,
|
|
11
|
+
wallet: stream.wallet,
|
|
12
|
+
size: stream.size,
|
|
13
|
+
size_unit: stream.sizeUnit,
|
|
14
|
+
...(stream.pricerId ? { pricer_id: stream.pricerId } : {}),
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Builds a subscribe or unsubscribe message for the RFQ socket.
|
|
20
|
+
* `unsubscribe` uses the same stream fields as the original `subscribe`.
|
|
21
|
+
*/
|
|
22
|
+
export function buildOtcRfqSubscriptionMessage<
|
|
23
|
+
TMethod extends OtcServerRfqSubscriptionRequest['method'],
|
|
24
|
+
>(
|
|
25
|
+
method: TMethod,
|
|
26
|
+
params: OtcRfqSubscriptionParams,
|
|
27
|
+
): Extract<OtcServerRfqSubscriptionRequest, { method: TMethod }> {
|
|
28
|
+
const body =
|
|
29
|
+
'stream' in params
|
|
30
|
+
? { stream: toServerStream(params.stream) }
|
|
31
|
+
: { streams: params.streams.map(toServerStream) };
|
|
32
|
+
return { method, id: params.id, ...body } as Extract<
|
|
33
|
+
OtcServerRfqSubscriptionRequest,
|
|
34
|
+
{ method: TMethod }
|
|
35
|
+
>;
|
|
36
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { EngineServerPlaceOrderParams } from '@nadohq/engine-client';
|
|
2
|
+
import { OtcQuoteSizeUnit } from './serverTypes';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Signed Nado order the OTC service settles. An engine `place_order` payload without
|
|
6
|
+
* `id`, `spot_leverage`, and `borrow_margin`.
|
|
7
|
+
*/
|
|
8
|
+
export type OtcServerTakerOrderParams = Omit<
|
|
9
|
+
EngineServerPlaceOrderParams,
|
|
10
|
+
'id' | 'spot_leverage' | 'borrow_margin'
|
|
11
|
+
>;
|
|
12
|
+
|
|
13
|
+
export interface OtcExecuteParams {
|
|
14
|
+
/** Client-generated idempotency key, 1–128 bytes. Kept across retries of this intent. */
|
|
15
|
+
dealId: string;
|
|
16
|
+
taker: OtcServerTakerOrderParams;
|
|
17
|
+
/** Execution route. Omitted selects the service default (`awr`). */
|
|
18
|
+
pricerId?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface OtcGetExecutionStatusParams {
|
|
22
|
+
dealId: string;
|
|
23
|
+
takerDigest: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface OtcGetReadyParams {
|
|
27
|
+
pricerId?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Route coverage. HTTP 200 is ready; 400 and 503 are not. This does not guarantee liquidity
|
|
32
|
+
* or that an order will be accepted.
|
|
33
|
+
*/
|
|
34
|
+
export interface OtcReadyResult {
|
|
35
|
+
httpStatus: number;
|
|
36
|
+
ready: boolean;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* One quote subscription. `wallet` is a 20-byte address, not a 32-byte subaccount.
|
|
41
|
+
* `size` is a non-zero signed x18 integer string.
|
|
42
|
+
*/
|
|
43
|
+
export interface OtcQuoteStream {
|
|
44
|
+
type: 'quote';
|
|
45
|
+
productId: number;
|
|
46
|
+
wallet: string;
|
|
47
|
+
size: string;
|
|
48
|
+
sizeUnit: OtcQuoteSizeUnit;
|
|
49
|
+
/** Execution route. Omitted selects the service default (`awr`). */
|
|
50
|
+
pricerId?: string;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface OtcRfqSubscriptionStreamParams {
|
|
54
|
+
id: number;
|
|
55
|
+
stream: OtcQuoteStream;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface OtcRfqSubscriptionStreamsParams {
|
|
59
|
+
id: number;
|
|
60
|
+
streams: OtcQuoteStream[];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Subscribe or unsubscribe target. Pass one stream, or several. */
|
|
64
|
+
export type OtcRfqSubscriptionParams =
|
|
65
|
+
| OtcRfqSubscriptionStreamParams
|
|
66
|
+
| OtcRfqSubscriptionStreamsParams;
|