@silvana-one/orderbook 1.1.14 → 1.1.16
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 +103 -105
- package/dist/node/index.cjs +71 -65
- package/dist/node/news.d.ts +3 -2
- package/dist/node/news.js +1 -5
- package/dist/node/news.js.map +1 -1
- package/dist/node/orderbook.d.ts +3 -2
- package/dist/node/orderbook.js +1 -5
- package/dist/node/orderbook.js.map +1 -1
- package/dist/node/pricing.d.ts +3 -2
- package/dist/node/pricing.js +1 -5
- package/dist/node/pricing.js.map +1 -1
- package/dist/node/proto/silvana/orderbook/v1/orderbook_pb.d.ts +69 -1
- package/dist/node/proto/silvana/orderbook/v1/orderbook_pb.js +60 -44
- package/dist/node/proto/silvana/orderbook/v1/orderbook_pb.js.map +1 -1
- package/dist/node/proto/silvana/settlement/v1/settlement_pb.d.ts +124 -0
- package/dist/node/proto/silvana/settlement/v1/settlement_pb.js +11 -1
- package/dist/node/proto/silvana/settlement/v1/settlement_pb.js.map +1 -1
- package/dist/node/settlement.d.ts +26 -3
- package/dist/node/settlement.js +11 -6
- package/dist/node/settlement.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/tsconfig.web.tsbuildinfo +1 -1
- package/dist/web/news.d.ts +3 -2
- package/dist/web/news.js +1 -5
- package/dist/web/news.js.map +1 -1
- package/dist/web/orderbook.d.ts +3 -2
- package/dist/web/orderbook.js +1 -5
- package/dist/web/orderbook.js.map +1 -1
- package/dist/web/pricing.d.ts +3 -2
- package/dist/web/pricing.js +1 -5
- package/dist/web/pricing.js.map +1 -1
- package/dist/web/proto/silvana/orderbook/v1/orderbook_pb.d.ts +69 -1
- package/dist/web/proto/silvana/orderbook/v1/orderbook_pb.js +60 -44
- package/dist/web/proto/silvana/orderbook/v1/orderbook_pb.js.map +1 -1
- package/dist/web/proto/silvana/settlement/v1/settlement_pb.d.ts +124 -0
- package/dist/web/proto/silvana/settlement/v1/settlement_pb.js +11 -1
- package/dist/web/proto/silvana/settlement/v1/settlement_pb.js.map +1 -1
- package/dist/web/settlement.d.ts +26 -3
- package/dist/web/settlement.js +11 -6
- package/dist/web/settlement.js.map +1 -1
- package/package.json +14 -3
- package/src/news.ts +4 -8
- package/src/orderbook.ts +4 -8
- package/src/pricing.ts +4 -8
- package/src/proto/silvana/orderbook/v1/orderbook_pb.ts +124 -44
- package/src/proto/silvana/settlement/v1/settlement_pb.ts +150 -1
- package/src/settlement.ts +35 -8
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @silvana-one/orderbook
|
|
2
2
|
|
|
3
|
-
Silvana Orderbook Client
|
|
3
|
+
Silvana Orderbook Client for Node.js and Browser environments.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -8,111 +8,142 @@ Silvana Orderbook Client - A TypeScript/JavaScript client library for interactin
|
|
|
8
8
|
npm install @silvana-one/orderbook
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
+
For Node.js:
|
|
12
|
+
```bash
|
|
13
|
+
npm install @connectrpc/connect-node
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
For Browser:
|
|
17
|
+
```bash
|
|
18
|
+
npm install @connectrpc/connect-web
|
|
19
|
+
```
|
|
20
|
+
|
|
11
21
|
## Usage
|
|
12
22
|
|
|
13
|
-
###
|
|
23
|
+
### Node.js
|
|
14
24
|
|
|
15
25
|
```typescript
|
|
16
|
-
import {
|
|
26
|
+
import { createGrpcTransport } from "@connectrpc/connect-node";
|
|
27
|
+
import { OrderbookClient, OrderType, TimeInForce } from "@silvana-one/orderbook";
|
|
28
|
+
|
|
29
|
+
const transport = createGrpcTransport({
|
|
30
|
+
baseUrl: "https://api.silvana.one",
|
|
31
|
+
});
|
|
17
32
|
|
|
18
|
-
// Initialize the client
|
|
19
33
|
const client = new OrderbookClient({
|
|
20
|
-
|
|
21
|
-
token:
|
|
34
|
+
transport,
|
|
35
|
+
token: "your-jwt-token",
|
|
22
36
|
});
|
|
23
|
-
```
|
|
24
37
|
|
|
25
|
-
|
|
38
|
+
// Get markets
|
|
39
|
+
const markets = await client.getMarkets();
|
|
40
|
+
console.log(markets.markets);
|
|
26
41
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
marketId: 'BTC-USD',
|
|
42
|
+
// Submit an order
|
|
43
|
+
const order = await client.submitOrder({
|
|
44
|
+
marketId: "BTC-USD",
|
|
31
45
|
orderType: OrderType.BID,
|
|
32
|
-
price:
|
|
33
|
-
quantity:
|
|
46
|
+
price: "50000.00",
|
|
47
|
+
quantity: "0.1",
|
|
34
48
|
timeInForce: TimeInForce.GTC,
|
|
35
|
-
expiresAt: new Date('2024-12-31'),
|
|
36
|
-
traderOrderRef: 'my-order-123'
|
|
37
49
|
});
|
|
38
|
-
|
|
39
|
-
if (response.success) {
|
|
40
|
-
console.log('Order submitted:', response.order);
|
|
41
|
-
}
|
|
42
50
|
```
|
|
43
51
|
|
|
44
|
-
###
|
|
52
|
+
### Browser
|
|
45
53
|
|
|
46
54
|
```typescript
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
55
|
+
import { createGrpcWebTransport } from "@connectrpc/connect-web";
|
|
56
|
+
import { OrderbookClient, OrderType, TimeInForce } from "@silvana-one/orderbook";
|
|
57
|
+
|
|
58
|
+
const transport = createGrpcWebTransport({
|
|
59
|
+
baseUrl: "https://api.silvana.one",
|
|
52
60
|
});
|
|
53
61
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
fromTime: new Date('2024-01-01'),
|
|
58
|
-
toTime: new Date(),
|
|
59
|
-
limit: 100
|
|
62
|
+
const client = new OrderbookClient({
|
|
63
|
+
transport,
|
|
64
|
+
token: "your-jwt-token",
|
|
60
65
|
});
|
|
66
|
+
|
|
67
|
+
// Same API as Node.js
|
|
68
|
+
const markets = await client.getMarkets();
|
|
61
69
|
```
|
|
62
70
|
|
|
63
|
-
|
|
71
|
+
## Clients
|
|
72
|
+
|
|
73
|
+
### OrderbookClient
|
|
74
|
+
|
|
75
|
+
Main client for trading operations.
|
|
64
76
|
|
|
65
77
|
```typescript
|
|
66
|
-
|
|
67
|
-
const depth = await client.getOrderbookDepth({
|
|
68
|
-
marketId: 'BTC-USD',
|
|
69
|
-
depth: 20
|
|
70
|
-
});
|
|
78
|
+
import { OrderbookClient } from "@silvana-one/orderbook";
|
|
71
79
|
|
|
72
|
-
|
|
73
|
-
console.log('Offers:', depth.orderbook?.offers);
|
|
80
|
+
const client = new OrderbookClient({ transport, token });
|
|
74
81
|
|
|
75
|
-
//
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
});
|
|
82
|
+
// Trading
|
|
83
|
+
await client.getMarkets();
|
|
84
|
+
await client.getOrders({ marketId: "BTC-USD" });
|
|
85
|
+
await client.submitOrder({ ... });
|
|
86
|
+
await client.cancelOrder({ orderId: 123n });
|
|
87
|
+
|
|
88
|
+
// Market data
|
|
89
|
+
await client.getOrderbookDepth({ marketId: "BTC-USD", depth: 10 });
|
|
90
|
+
await client.getMarketData({ marketIds: ["BTC-USD"] });
|
|
91
|
+
|
|
92
|
+
// Streaming
|
|
93
|
+
for await (const update of client.subscribeOrderbook({ marketId: "BTC-USD" })) {
|
|
94
|
+
console.log(update);
|
|
95
|
+
}
|
|
79
96
|
```
|
|
80
97
|
|
|
81
|
-
###
|
|
98
|
+
### PricingClient
|
|
99
|
+
|
|
100
|
+
Client for price data and market feeds.
|
|
82
101
|
|
|
83
102
|
```typescript
|
|
84
|
-
|
|
85
|
-
const orderbookStream = client.subscribeOrderbook({
|
|
86
|
-
marketId: 'BTC-USD',
|
|
87
|
-
depth: 10
|
|
88
|
-
});
|
|
103
|
+
import { PricingClient } from "@silvana-one/orderbook";
|
|
89
104
|
|
|
90
|
-
|
|
91
|
-
console.log('Orderbook update:', update);
|
|
92
|
-
}
|
|
105
|
+
const client = new PricingClient({ transport });
|
|
93
106
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
});
|
|
107
|
+
await client.getPrice({ marketId: "BTC-USD" });
|
|
108
|
+
await client.getPrices({ marketIds: ["BTC-USD", "ETH-USD"] });
|
|
109
|
+
await client.getKlines({ marketId: "BTC-USD", interval: "1h", limit: 100 });
|
|
98
110
|
|
|
99
|
-
|
|
100
|
-
|
|
111
|
+
// Streaming
|
|
112
|
+
for await (const update of client.streamPrices({ marketIds: ["BTC-USD"] })) {
|
|
113
|
+
console.log(update);
|
|
101
114
|
}
|
|
102
115
|
```
|
|
103
116
|
|
|
104
|
-
###
|
|
117
|
+
### NewsClient
|
|
118
|
+
|
|
119
|
+
Client for news and market updates.
|
|
105
120
|
|
|
106
121
|
```typescript
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
});
|
|
122
|
+
import { NewsClient } from "@silvana-one/orderbook";
|
|
123
|
+
|
|
124
|
+
const client = new NewsClient({ transport });
|
|
125
|
+
|
|
126
|
+
await client.getNews({ tokens: ["BTC", "ETH"], limit: 10 });
|
|
110
127
|
|
|
111
|
-
|
|
112
|
-
|
|
128
|
+
// Streaming
|
|
129
|
+
for await (const news of client.streamNews({ tokens: ["BTC"] })) {
|
|
130
|
+
console.log(news);
|
|
113
131
|
}
|
|
114
132
|
```
|
|
115
133
|
|
|
134
|
+
### SettlementClient
|
|
135
|
+
|
|
136
|
+
Client for settlement operations (Canton node integration).
|
|
137
|
+
|
|
138
|
+
```typescript
|
|
139
|
+
import { SettlementClient } from "@silvana-one/orderbook";
|
|
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
|
+
|
|
116
147
|
## API Methods
|
|
117
148
|
|
|
118
149
|
### Order Management
|
|
@@ -136,56 +167,23 @@ if (cancelResponse.success) {
|
|
|
136
167
|
- `subscribeOrders()` - Stream order updates
|
|
137
168
|
- `subscribeSettlements()` - Stream settlement updates
|
|
138
169
|
|
|
139
|
-
## Types
|
|
170
|
+
## Types
|
|
140
171
|
|
|
141
|
-
|
|
172
|
+
All protobuf types are exported from the package:
|
|
142
173
|
|
|
143
174
|
```typescript
|
|
144
175
|
import {
|
|
176
|
+
Order,
|
|
145
177
|
OrderType,
|
|
146
178
|
OrderStatus,
|
|
147
179
|
TimeInForce,
|
|
148
180
|
MarketType,
|
|
149
181
|
SettlementStatus,
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
type Settlement,
|
|
154
|
-
type OrderbookDepth
|
|
155
|
-
} from '@silvana-one/orderbook';
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
## JWT Authentication
|
|
159
|
-
|
|
160
|
-
All methods require JWT authentication. The token should be signed with an Ed25519 private key and include the necessary claims for accessing the orderbook service.
|
|
161
|
-
|
|
162
|
-
```typescript
|
|
163
|
-
const token = generateJWT({
|
|
164
|
-
sub: 'trader-id',
|
|
165
|
-
exp: Date.now() + 3600000,
|
|
166
|
-
// ... other required claims
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
const client = new OrderbookClient({
|
|
170
|
-
baseUrl: 'http://orderbook-service:50052',
|
|
171
|
-
token
|
|
172
|
-
});
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
## Error Handling
|
|
176
|
-
|
|
177
|
-
All async methods may throw errors. It's recommended to wrap calls in try-catch blocks:
|
|
178
|
-
|
|
179
|
-
```typescript
|
|
180
|
-
try {
|
|
181
|
-
const response = await client.submitOrder({
|
|
182
|
-
// ... order parameters
|
|
183
|
-
});
|
|
184
|
-
} catch (error) {
|
|
185
|
-
console.error('Failed to submit order:', error);
|
|
186
|
-
}
|
|
182
|
+
Market,
|
|
183
|
+
Instrument,
|
|
184
|
+
} from "@silvana-one/orderbook";
|
|
187
185
|
```
|
|
188
186
|
|
|
189
187
|
## License
|
|
190
188
|
|
|
191
|
-
Apache-2.0
|
|
189
|
+
Apache-2.0
|