@ostium/builder-sdk 0.1.0 → 0.2.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 +73 -3
- package/dist/cli.js +526 -139
- package/dist/index.cjs +517 -130
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +173 -106
- package/dist/index.d.ts +173 -106
- package/dist/index.js +517 -131
- package/dist/index.js.map +1 -1
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -113,6 +113,55 @@ const client = await OstiumClient.createDelegatedAndGasless({
|
|
|
113
113
|
});
|
|
114
114
|
```
|
|
115
115
|
|
|
116
|
+
### Build Unsigned Transactions
|
|
117
|
+
|
|
118
|
+
Every write method now has a `get*Tx()` counterpart that returns transaction
|
|
119
|
+
data without signing or submitting it.
|
|
120
|
+
|
|
121
|
+
```ts
|
|
122
|
+
const client = await OstiumClient.createSelfAndSelf({
|
|
123
|
+
traderAddress: '0xTraderAddress',
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
const tx = client.getOpenTradeTx({
|
|
127
|
+
pairId: 0,
|
|
128
|
+
buy: true,
|
|
129
|
+
price: '65000',
|
|
130
|
+
collateral: '100',
|
|
131
|
+
leverage: '5',
|
|
132
|
+
type: OrderType.Market,
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
if (tx.kind === 'eoa') {
|
|
136
|
+
await window.ethereum.request({
|
|
137
|
+
method: 'eth_sendTransaction',
|
|
138
|
+
params: [{
|
|
139
|
+
from: tx.from,
|
|
140
|
+
to: tx.to,
|
|
141
|
+
data: tx.data,
|
|
142
|
+
value: `0x${tx.value.toString(16)}`,
|
|
143
|
+
}],
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Gasless build-only clients return a Safe-style request instead:
|
|
149
|
+
|
|
150
|
+
```ts
|
|
151
|
+
const gaslessClient = await OstiumClient.createSelfAndGasless({
|
|
152
|
+
traderAddress: '0xTraderAddress',
|
|
153
|
+
safeAddress: '0xSafeAddress',
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
const safeTx = gaslessClient.getOpenTradeTx({ ... });
|
|
157
|
+
// safeTx.kind === 'safe'
|
|
158
|
+
// safeTx.safeAddress identifies the Safe that should execute safeTx.calls[0]
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
The existing write methods (`openTrade`, `closeTrade`, `approveUsdc`, etc.)
|
|
162
|
+
still work the same way, but they now submit the transaction built by the
|
|
163
|
+
corresponding `get*Tx()` method.
|
|
164
|
+
|
|
116
165
|
### Read-only (no private key)
|
|
117
166
|
|
|
118
167
|
Use `createReadOnly` to access market data without a signer. All read methods are available; write methods throw `INVALID_CONFIG`.
|
|
@@ -124,6 +173,27 @@ const positions = await reader.getOpenPositions({ user: '0xTrader...' });
|
|
|
124
173
|
const balances = await reader.getBalances('0xTrader...');
|
|
125
174
|
```
|
|
126
175
|
|
|
176
|
+
### Stream Position Updates
|
|
177
|
+
|
|
178
|
+
If you already have an `OpenPositionsResponse`, you can stream live price-driven
|
|
179
|
+
updates for those positions without re-fetching the full position set.
|
|
180
|
+
|
|
181
|
+
```ts
|
|
182
|
+
const positions = await client.getOpenPositions();
|
|
183
|
+
const stream = client.streamPositionUpdates(positions);
|
|
184
|
+
|
|
185
|
+
stream.onUpdate(next => {
|
|
186
|
+
console.log(next.marginSummary.totalRawPnlUsd);
|
|
187
|
+
console.log(next.pairPositions[0]?.position.unrealizedPnl);
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
stream.onError(err => console.error(err));
|
|
191
|
+
stream.close();
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
The SDK subscribes once per unique `pairId` in the response, then updates the
|
|
195
|
+
full `OpenPositionsResponse` as prices change.
|
|
196
|
+
|
|
127
197
|
### Common Options
|
|
128
198
|
|
|
129
199
|
All constructors (including `createReadOnly`) accept these optional overrides:
|
|
@@ -279,7 +349,7 @@ Use `getOrders({ initiatedTxHashes: [result.txHash] })` to poll by submission ha
|
|
|
279
349
|
|
|
280
350
|
```ts
|
|
281
351
|
const result = await client.openTrade({
|
|
282
|
-
|
|
352
|
+
pairId: 0, // trading pair (use getPairs() to list all)
|
|
283
353
|
buy: true, // true = long, false = short
|
|
284
354
|
price: '65000', // entry price
|
|
285
355
|
collateral: '100', // USD (min $5)
|
|
@@ -408,7 +478,7 @@ const { prices } = await client.getAllPrices();
|
|
|
408
478
|
Open positions, margin summary, and per-position live PnL. Block number is fetched automatically on `OstiumClient`.
|
|
409
479
|
|
|
410
480
|
```ts
|
|
411
|
-
const { pairPositions, marginSummary,
|
|
481
|
+
const { pairPositions, marginSummary, time } =
|
|
412
482
|
await client.getOpenPositions();
|
|
413
483
|
|
|
414
484
|
// Each position:
|
|
@@ -418,7 +488,7 @@ const { pairId, pid, idx, side, szi, entryPx, leverage, ntl,
|
|
|
418
488
|
openTimestamp, isDayTrade } = pairPositions[0].position;
|
|
419
489
|
|
|
420
490
|
// marginSummary: accountValue, totalCollateralUsed, totalNtlPos, totalRawPnlUsd
|
|
421
|
-
//
|
|
491
|
+
// marginSummary.totalWithdrawable: max collateral removable across all positions
|
|
422
492
|
// time: server time (Unix ms)
|
|
423
493
|
```
|
|
424
494
|
|