@silvana-one/orderbook 1.1.31 → 1.1.32
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 +150 -54
- package/dist/node/index.cjs +630 -41
- package/dist/node/index.d.ts +1 -0
- package/dist/node/index.js +1 -0
- package/dist/node/index.js.map +1 -1
- package/dist/node/ledger.d.ts +95 -0
- package/dist/node/ledger.js +170 -0
- package/dist/node/ledger.js.map +1 -0
- package/dist/node/orderbook.d.ts +58 -2
- package/dist/node/orderbook.js +74 -2
- package/dist/node/orderbook.js.map +1 -1
- package/dist/node/proto/silvana/ledger/v1/ledger_pb.d.ts +2171 -0
- package/dist/node/proto/silvana/ledger/v1/ledger_pb.js +559 -0
- package/dist/node/proto/silvana/ledger/v1/ledger_pb.js.map +1 -0
- package/dist/node/proto/silvana/orderbook/v1/orderbook_pb.d.ts +513 -3
- package/dist/node/proto/silvana/orderbook/v1/orderbook_pb.js +95 -1
- package/dist/node/proto/silvana/orderbook/v1/orderbook_pb.js.map +1 -1
- package/dist/node/proto/silvana/settlement/v1/settlement_pb.d.ts +307 -3
- package/dist/node/proto/silvana/settlement/v1/settlement_pb.js +131 -44
- package/dist/node/proto/silvana/settlement/v1/settlement_pb.js.map +1 -1
- package/dist/node/settlement.d.ts +1 -1
- package/dist/node/settlement.js +1 -1
- package/dist/node/settlement.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/tsconfig.web.tsbuildinfo +1 -1
- package/dist/web/index.d.ts +1 -0
- package/dist/web/index.js +1 -0
- package/dist/web/index.js.map +1 -1
- package/dist/web/ledger.d.ts +95 -0
- package/dist/web/ledger.js +170 -0
- package/dist/web/ledger.js.map +1 -0
- package/dist/web/orderbook.d.ts +58 -2
- package/dist/web/orderbook.js +74 -2
- package/dist/web/orderbook.js.map +1 -1
- package/dist/web/proto/silvana/ledger/v1/ledger_pb.d.ts +2171 -0
- package/dist/web/proto/silvana/ledger/v1/ledger_pb.js +559 -0
- package/dist/web/proto/silvana/ledger/v1/ledger_pb.js.map +1 -0
- package/dist/web/proto/silvana/orderbook/v1/orderbook_pb.d.ts +513 -3
- package/dist/web/proto/silvana/orderbook/v1/orderbook_pb.js +95 -1
- package/dist/web/proto/silvana/orderbook/v1/orderbook_pb.js.map +1 -1
- package/dist/web/proto/silvana/settlement/v1/settlement_pb.d.ts +307 -3
- package/dist/web/proto/silvana/settlement/v1/settlement_pb.js +131 -44
- package/dist/web/proto/silvana/settlement/v1/settlement_pb.js.map +1 -1
- package/dist/web/settlement.d.ts +1 -1
- package/dist/web/settlement.js +1 -1
- package/dist/web/settlement.js.map +1 -1
- package/package.json +7 -6
- package/src/index.ts +1 -0
- package/src/ledger.ts +267 -0
- package/src/orderbook.ts +123 -1
- package/src/proto/silvana/ledger/v1/ledger_pb.ts +2531 -0
- package/src/proto/silvana/orderbook/v1/orderbook_pb.ts +611 -4
- package/src/proto/silvana/settlement/v1/settlement_pb.ts +402 -46
- package/src/settlement.ts +12 -0
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @silvana-one/orderbook
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
TypeScript client library for the Silvana orderbook. Works in Node.js and Browser environments. Wraps 5 gRPC services via [Connect RPC](https://connectrpc.com/).
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -9,11 +9,13 @@ npm install @silvana-one/orderbook
|
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
For Node.js:
|
|
12
|
+
|
|
12
13
|
```bash
|
|
13
14
|
npm install @connectrpc/connect-node
|
|
14
15
|
```
|
|
15
16
|
|
|
16
17
|
For Browser:
|
|
18
|
+
|
|
17
19
|
```bash
|
|
18
20
|
npm install @connectrpc/connect-web
|
|
19
21
|
```
|
|
@@ -24,10 +26,14 @@ npm install @connectrpc/connect-web
|
|
|
24
26
|
|
|
25
27
|
```typescript
|
|
26
28
|
import { createGrpcTransport } from "@connectrpc/connect-node";
|
|
27
|
-
import {
|
|
29
|
+
import {
|
|
30
|
+
OrderbookClient,
|
|
31
|
+
OrderType,
|
|
32
|
+
TimeInForce,
|
|
33
|
+
} from "@silvana-one/orderbook";
|
|
28
34
|
|
|
29
35
|
const transport = createGrpcTransport({
|
|
30
|
-
baseUrl: "https://
|
|
36
|
+
baseUrl: "https://your-orderbook-server:port",
|
|
31
37
|
});
|
|
32
38
|
|
|
33
39
|
const client = new OrderbookClient({
|
|
@@ -53,10 +59,14 @@ const order = await client.submitOrder({
|
|
|
53
59
|
|
|
54
60
|
```typescript
|
|
55
61
|
import { createGrpcWebTransport } from "@connectrpc/connect-web";
|
|
56
|
-
import {
|
|
62
|
+
import {
|
|
63
|
+
OrderbookClient,
|
|
64
|
+
OrderType,
|
|
65
|
+
TimeInForce,
|
|
66
|
+
} from "@silvana-one/orderbook";
|
|
57
67
|
|
|
58
68
|
const transport = createGrpcWebTransport({
|
|
59
|
-
baseUrl: "https://
|
|
69
|
+
baseUrl: "https://your-orderbook-server:port",
|
|
60
70
|
});
|
|
61
71
|
|
|
62
72
|
const client = new OrderbookClient({
|
|
@@ -72,7 +82,7 @@ const markets = await client.getMarkets();
|
|
|
72
82
|
|
|
73
83
|
### OrderbookClient
|
|
74
84
|
|
|
75
|
-
|
|
85
|
+
Trading operations, order management, market data, and RFQ. Requires JWT authentication.
|
|
76
86
|
|
|
77
87
|
```typescript
|
|
78
88
|
import { OrderbookClient } from "@silvana-one/orderbook";
|
|
@@ -80,92 +90,173 @@ import { OrderbookClient } from "@silvana-one/orderbook";
|
|
|
80
90
|
const client = new OrderbookClient({ transport, token });
|
|
81
91
|
|
|
82
92
|
// Trading
|
|
83
|
-
await client.getMarkets();
|
|
84
|
-
await client.getOrders({ marketId: "BTC-USD" });
|
|
85
93
|
await client.submitOrder({ ... });
|
|
86
94
|
await client.cancelOrder({ orderId: 123n });
|
|
95
|
+
await client.getOrders({ marketId: "BTC-USD" });
|
|
87
96
|
|
|
88
97
|
// Market data
|
|
89
98
|
await client.getOrderbookDepth({ marketId: "BTC-USD", depth: 10 });
|
|
90
99
|
await client.getMarketData({ marketIds: ["BTC-USD"] });
|
|
91
100
|
|
|
101
|
+
// RFQ
|
|
102
|
+
const quotes = await client.requestQuotes({ marketId: "BTC-USD", direction: "buy", quantity: "0.5" });
|
|
103
|
+
await client.acceptQuote({ rfqId: quotes.rfqId, quoteId: quotes.quotes[0].quoteId });
|
|
104
|
+
|
|
92
105
|
// Streaming
|
|
93
106
|
for await (const update of client.subscribeOrderbook({ marketId: "BTC-USD" })) {
|
|
94
107
|
console.log(update);
|
|
95
108
|
}
|
|
96
109
|
```
|
|
97
110
|
|
|
98
|
-
###
|
|
111
|
+
### SettlementClient
|
|
99
112
|
|
|
100
|
-
|
|
113
|
+
DVP settlement orchestration and RFQ handling. Requires JWT authentication.
|
|
101
114
|
|
|
102
115
|
```typescript
|
|
103
|
-
import {
|
|
116
|
+
import { SettlementClient } from "@silvana-one/orderbook";
|
|
104
117
|
|
|
105
|
-
const client = new
|
|
118
|
+
const client = new SettlementClient({ transport, token });
|
|
106
119
|
|
|
107
|
-
await client.
|
|
108
|
-
await client.
|
|
109
|
-
await client.getKlines({ marketId: "BTC-USD", interval: "1h", limit: 100 });
|
|
120
|
+
await client.getPendingProposals({ partyId: "party-1" });
|
|
121
|
+
await client.getSettlementStatus({ settlementId: "settlement-1" });
|
|
110
122
|
|
|
111
|
-
//
|
|
112
|
-
|
|
113
|
-
console.log(update);
|
|
114
|
-
}
|
|
123
|
+
// Bidirectional streaming for settlement flow and RFQ
|
|
124
|
+
const stream = client.settlementStream(messages);
|
|
115
125
|
```
|
|
116
126
|
|
|
117
|
-
###
|
|
127
|
+
### LedgerClient
|
|
118
128
|
|
|
119
|
-
|
|
129
|
+
Two-phase transaction signing, balance/contract queries, and cloud agent onboarding. JWT authentication for most RPCs; onboarding RPCs use message-level Ed25519 signing.
|
|
120
130
|
|
|
121
131
|
```typescript
|
|
122
|
-
import {
|
|
132
|
+
import { LedgerClient } from "@silvana-one/orderbook";
|
|
133
|
+
|
|
134
|
+
const client = new LedgerClient({ transport, token });
|
|
123
135
|
|
|
124
|
-
|
|
136
|
+
// Queries
|
|
137
|
+
await client.getBalances();
|
|
138
|
+
await client.getDsoRates();
|
|
139
|
+
await client.getServiceInfo();
|
|
125
140
|
|
|
126
|
-
|
|
141
|
+
// Two-phase transaction
|
|
142
|
+
const prepared = await client.prepareTransaction({ operation, params });
|
|
143
|
+
// ... sign hash locally ...
|
|
144
|
+
await client.executeTransaction({
|
|
145
|
+
transactionId: prepared.transactionId,
|
|
146
|
+
signature,
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
// Onboarding (no JWT needed)
|
|
150
|
+
const unauthClient = new LedgerClient({ transport });
|
|
151
|
+
await unauthClient.getAgentConfig();
|
|
152
|
+
await unauthClient.registerAgent({ publicKey, requestSignature });
|
|
127
153
|
|
|
128
154
|
// Streaming
|
|
129
|
-
for await (const
|
|
130
|
-
|
|
155
|
+
for await (const contract of client.getActiveContracts({
|
|
156
|
+
templateFilters: ["..."],
|
|
157
|
+
})) {
|
|
158
|
+
console.log(contract);
|
|
131
159
|
}
|
|
132
160
|
```
|
|
133
161
|
|
|
134
|
-
###
|
|
162
|
+
### PricingClient
|
|
135
163
|
|
|
136
|
-
|
|
164
|
+
External price feeds (Binance, ByBit, CoinGecko). No authentication needed.
|
|
137
165
|
|
|
138
166
|
```typescript
|
|
139
|
-
import {
|
|
140
|
-
|
|
141
|
-
const client = new SettlementClient({ transport });
|
|
142
|
-
|
|
143
|
-
await client.getPendingProposals({ auth, partyId: "party-1" });
|
|
144
|
-
await client.getSettlementStatus({ auth, settlementId: "settlement-1" });
|
|
145
|
-
```
|
|
146
|
-
|
|
147
|
-
## API Methods
|
|
167
|
+
import { PricingClient } from "@silvana-one/orderbook";
|
|
148
168
|
|
|
149
|
-
|
|
150
|
-
- `submitOrder()` - Submit a new order
|
|
151
|
-
- `cancelOrder()` - Cancel an existing order
|
|
152
|
-
- `getOrders()` - Get your orders
|
|
153
|
-
- `getOrderHistory()` - Get historical orders
|
|
169
|
+
const client = new PricingClient({ transport });
|
|
154
170
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
- `getInstruments()` - Get tradable instruments
|
|
158
|
-
- `getOrderbookDepth()` - Get orderbook depth
|
|
159
|
-
- `getMarketData()` - Get market statistics
|
|
171
|
+
await client.getPrice({ marketId: "BTC-USD" });
|
|
172
|
+
await client.getKlines({ marketId: "BTC-USD", interval: "1h", limit: 100 });
|
|
160
173
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
174
|
+
// Streaming
|
|
175
|
+
for await (const update of client.streamPrices({ marketIds: ["BTC-USD"] })) {
|
|
176
|
+
console.log(update);
|
|
177
|
+
}
|
|
178
|
+
```
|
|
164
179
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
180
|
+
## gRPC Services
|
|
181
|
+
|
|
182
|
+
The library wraps 5 gRPC services:
|
|
183
|
+
|
|
184
|
+
| Service | Client | Auth | Streaming |
|
|
185
|
+
| ------------------- | ------------------ | --------------------- | ---------------------------------------------------------------------------------- |
|
|
186
|
+
| OrderbookService | `OrderbookClient` | JWT | Server-streaming (`subscribeOrderbook`, `subscribeOrders`, `subscribeSettlements`) |
|
|
187
|
+
| SettlementService | `SettlementClient` | JWT | Bidirectional (`settlementStream`) |
|
|
188
|
+
| DAppProviderService | `LedgerClient` | JWT / Message signing | Server-streaming (`getActiveContracts`, `getUpdates`) |
|
|
189
|
+
| PricingService | `PricingClient` | None | Server-streaming (`streamPrices`) |
|
|
190
|
+
|
|
191
|
+
### Two-Phase Transaction Flow
|
|
192
|
+
|
|
193
|
+
All ledger-mutating operations use a two-phase signing protocol via `LedgerClient`:
|
|
194
|
+
|
|
195
|
+
1. Call `prepareTransaction` with an operation type and parameters
|
|
196
|
+
2. Server returns the full `prepared_transaction` bytes and a hash
|
|
197
|
+
3. Verify the transaction matches the requested operation (correct template, parties, amounts)
|
|
198
|
+
4. Sign the hash locally with Ed25519 private key
|
|
199
|
+
5. Call `executeTransaction` with the signature
|
|
200
|
+
6. Server submits the signed transaction to the Canton ledger
|
|
201
|
+
|
|
202
|
+
Operation types:
|
|
203
|
+
|
|
204
|
+
| Operation | Description |
|
|
205
|
+
| ------------------------------ | ---------------------------------- |
|
|
206
|
+
| `TRANSFER_CC` | Send Canton Coin |
|
|
207
|
+
| `TRANSFER_CIP56` | Send CIP-56 token |
|
|
208
|
+
| `ACCEPT_CIP56` | Accept incoming CIP-56 transfer |
|
|
209
|
+
| `PAY_DVP_FEE` | Pay DVP processing fee |
|
|
210
|
+
| `PROPOSE_DVP` | Create DVP proposal |
|
|
211
|
+
| `ACCEPT_DVP` | Accept DVP proposal |
|
|
212
|
+
| `PAY_ALLOC_FEE` | Pay allocation processing fee |
|
|
213
|
+
| `ALLOCATE` | Allocate tokens to DVP |
|
|
214
|
+
| `REQUEST_PREAPPROVAL` | Request TransferPreapproval |
|
|
215
|
+
| `REQUEST_RECURRING_PREPAID` | Request prepaid subscription |
|
|
216
|
+
| `REQUEST_RECURRING_PAYASYOUGO` | Request pay-as-you-go subscription |
|
|
217
|
+
| `REQUEST_USER_SERVICE` | Request UserService (onboarding) |
|
|
218
|
+
|
|
219
|
+
### Settlement Stream (Bidirectional)
|
|
220
|
+
|
|
221
|
+
`SettlementClient.settlementStream()` opens a long-lived bidirectional gRPC stream for RFQ handling and settlement lifecycle coordination.
|
|
222
|
+
|
|
223
|
+
**Client sends:** handshake, heartbeats, preconfirmation decisions, DVP lifecycle events, RFQ quotes/rejections
|
|
224
|
+
|
|
225
|
+
**Server sends:** handshake acknowledgement, heartbeats, settlement proposals, preconfirmation requests, RFQ requests
|
|
226
|
+
|
|
227
|
+
### Key Query RPCs
|
|
228
|
+
|
|
229
|
+
| Method | Client | Returns |
|
|
230
|
+
| -------------------------- | ---------- | ------------------------------------------------------ |
|
|
231
|
+
| `getBalances()` | Ledger | Token balances (total, locked, unlocked) |
|
|
232
|
+
| `getActiveContracts()` | Ledger | Stream of active contracts by template filter |
|
|
233
|
+
| `getUpdates()` | Ledger | Stream of ledger transactions from a given offset |
|
|
234
|
+
| `getPrice()` | Pricing | Bid, ask, last price for a market |
|
|
235
|
+
| `getKlines()` | Pricing | OHLCV candlestick data (1m to 1w intervals) |
|
|
236
|
+
| `getOrders()` | Orderbook | Orders with status and type filters |
|
|
237
|
+
| `getOrderbookDepth()` | Orderbook | Aggregated bid/offer price levels |
|
|
238
|
+
| `getSettlementProposals()` | Orderbook | Settlement proposals with status filter |
|
|
239
|
+
| `getSettlementStatus()` | Settlement | Step-by-step DVP status with buyer/seller next actions |
|
|
240
|
+
| `getMarkets()` | Orderbook | Available markets and their configuration |
|
|
241
|
+
| `getMarketData()` | Orderbook | Best bid/ask, last price, 24h volume |
|
|
242
|
+
| `requestQuotes()` | Orderbook | RFQ quotes from connected liquidity providers |
|
|
243
|
+
| `acceptQuote()` | Orderbook | Accept an LP quote, creating a settlement proposal |
|
|
244
|
+
|
|
245
|
+
### Server-Streaming Subscriptions
|
|
246
|
+
|
|
247
|
+
| Method | Client | Payload |
|
|
248
|
+
| ------------------------ | --------- | ------------------------------------------------------------ |
|
|
249
|
+
| `getActiveContracts()` | Ledger | Active contracts matching template filter |
|
|
250
|
+
| `getUpdates()` | Ledger | Ledger transaction stream from a given offset |
|
|
251
|
+
| `subscribeOrderbook()` | Orderbook | Orderbook snapshots and deltas |
|
|
252
|
+
| `subscribeOrders()` | Orderbook | Order lifecycle events (created, filled, cancelled) |
|
|
253
|
+
| `subscribeSettlements()` | Orderbook | Settlement status change events |
|
|
254
|
+
| `streamPrices()` | Pricing | Real-time price ticks with optional orderbook and trade data |
|
|
255
|
+
|
|
256
|
+
### Authentication
|
|
257
|
+
|
|
258
|
+
- **JWT** — Self-describing Ed25519 JWT (RFC 8037) with automatic refresh. Used for Orderbook, Pricing, and Settlement RPCs. The token embeds the Ed25519 public key; the server verifies it matches the registered party.
|
|
259
|
+
- **Message signing** — Per-request Ed25519 signature on the canonical request payload, used for Ledger two-phase transactions. Server responses are also signed and should be verified using the ledger service public key.
|
|
169
260
|
|
|
170
261
|
## Types
|
|
171
262
|
|
|
@@ -181,6 +272,11 @@ import {
|
|
|
181
272
|
SettlementStatus,
|
|
182
273
|
Market,
|
|
183
274
|
Instrument,
|
|
275
|
+
TransactionOperation,
|
|
276
|
+
TransactionStatus,
|
|
277
|
+
RfqAuditEventType,
|
|
278
|
+
RfqDirection,
|
|
279
|
+
RfqRejectionReason,
|
|
184
280
|
} from "@silvana-one/orderbook";
|
|
185
281
|
```
|
|
186
282
|
|