Skip to content

Commit c42264f

Browse files
committed
docs: cover sdk wallet position helpers
1 parent d8d9289 commit c42264f

4 files changed

Lines changed: 133 additions & 3 deletions

File tree

docs/sdk/examples.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,39 @@ async fn main() -> Result<()> {
5858

5959
**What it demonstrates:** [Client setup](client.md) in read-only mode, [indexer queries](indexer.md), on-chain market reads.
6060

61+
## redeem_backlog_check — Find Redeemable Positions Before Redemption
62+
63+
This is the concise discovery flow for redemption bots:
64+
65+
1. query the indexer backlog with `get_redeemable_positions(address)`
66+
2. pull the factory market ID from each normalized entry
67+
3. pass that factory market ID into on-chain redemption
68+
69+
```rust
70+
use strike_sdk::prelude::*;
71+
72+
let address = "0x...";
73+
let redeemable = client.indexer().get_redeemable_positions(address).await?;
74+
75+
for pos in redeemable {
76+
let Some(factory_market_id) = pos.factory_market_id() else {
77+
continue;
78+
};
79+
80+
println!(
81+
"redeem backlog | factory {} | lots {:?} | redeemable {:?}",
82+
factory_market_id,
83+
pos.lots_hint(),
84+
pos.redeemable()
85+
);
86+
87+
// Example on-chain call path once you choose an amount:
88+
// client.redeem().redeem(factory_market_id, amount).await?;
89+
}
90+
```
91+
92+
The SDK normalizes legacy and v1 redeemable payload variants here, so `factory_market_id()` and related accessors remain the stable interface.
93+
6194
## place_orders — Full Trading Lifecycle
6295

6396
Connects with a wallet, approves USDT, finds an active market, places a bid and ask, then cancels both.

docs/sdk/indexer.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ All indexer endpoints are available under the `/v1/` prefix. The legacy unprefix
88

99
Responses use a standard envelope: `{ data: [...], meta: { total, limit, offset } }`. The SDK handles this transparently — callers receive plain `Vec<Market>`, `Vec<IndexerOrder>`, etc. with no change to existing code.
1010

11+
For wallet position endpoints, the SDK also normalizes known schema drift across legacy and v1 payloads. Filled and redeemable entries preserve the raw JSON but expose stable accessors like `factory_market_id()`, `orderbook_market_id()`, `redeemable()`, `resolved()`, and `lots_hint()`.
12+
1113
## Canonical OpenAPI Reference
1214

1315
The generated OpenAPI spec is the source of truth for the public indexer API:
@@ -143,6 +145,60 @@ The v1 response from `/v1/positions/:address` is paginated:
143145

144146
The SDK handles both the v1 paginated and legacy flat-array formats automatically — `get_open_orders` always returns `Vec<IndexerOrder>`.
145147

148+
## Get Wallet Positions
149+
150+
Fetch the full wallet snapshot from `/positions/:address`:
151+
152+
```rust
153+
let address = "0x...";
154+
let positions = client.indexer().get_positions(address).await?;
155+
156+
println!("open orders: {}", positions.open_orders.len());
157+
println!("filled positions: {}", positions.filled_positions.len());
158+
159+
for pos in &positions.filled_positions {
160+
println!(
161+
"factory {:?} | orderbook {:?} | lots {:?} | redeemable {:?}",
162+
pos.factory_market_id(),
163+
pos.orderbook_market_id(),
164+
pos.lots_hint(),
165+
pos.redeemable()
166+
);
167+
}
168+
```
169+
170+
`get_positions()` returns:
171+
172+
```rust
173+
pub struct IndexerPositions {
174+
pub open_orders: Vec<IndexerOrder>,
175+
pub filled_positions: Vec<IndexerFilledPosition>,
176+
}
177+
```
178+
179+
Use the accessor methods on `IndexerFilledPosition` instead of relying on a specific upstream JSON shape.
180+
181+
## Get Redeemable Positions
182+
183+
Fetch the wallet's redeem backlog from `/positions/:address/redeemable`:
184+
185+
```rust
186+
let address = "0x...";
187+
let redeemable = client.indexer().get_redeemable_positions(address).await?;
188+
189+
for pos in &redeemable {
190+
if let Some(factory_market_id) = pos.factory_market_id() {
191+
println!(
192+
"redeem backlog | factory {} | lots {:?}",
193+
factory_market_id,
194+
pos.lots_hint()
195+
);
196+
}
197+
}
198+
```
199+
200+
This is the right discovery path before calling on-chain redemption. The SDK normalizes both paginated and legacy redeemable payloads, including nested and casing-drifted field names.
201+
146202
### IndexerOrder Type
147203

148204
```rust

docs/sdk/overview.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ The Strike SDK is a Rust crate for programmatic trading on Strike prediction mar
44

55
## Design Philosophy
66

7-
The SDK is **on-chain first**. All trading operations go directly to BNB Chain via RPC. Live data (events, balances, market state) comes from a WSS subscription or RPC reads. The [indexer](indexer.md) is available for startup snapshots (fetching all markets, orderbook state), but is never in the critical trading path.
7+
The SDK is **on-chain first**. All trading operations go directly to BNB Chain via RPC. Live data (events, balances, market state) comes from a WSS subscription or RPC reads. The [indexer](indexer.md) is available for startup snapshots (fetching all markets, orderbook state, wallet positions, redeem backlog), but is never in the critical trading path.
88

99
## Features
1010

@@ -13,9 +13,12 @@ The SDK is **on-chain first**. All trading operations go directly to BNB Chain v
1313
| Order management | Place, cancel, and replace orders in batch transactions |
1414
| Event streaming | Real-time WSS subscriptions with auto-reconnect |
1515
| Vault & tokens | USDT approval, balance queries, outcome token / position operations |
16-
| Indexer client | REST client for market snapshots and orderbook state |
16+
| On-chain market reads | Market counts/IDs plus `market_meta(factory_market_id)` for factory-to-orderbook metadata |
17+
| Indexer client | REST client for market snapshots, wallet positions, redeem backlog, and orderbook state |
1718
| Nonce manager | Optional `nonce-manager` feature flag for bots sending rapid transactions |
1819

20+
Wallet position helpers normalize known schema drift in filled-position and redeemable payloads, so integrations can use stable accessors instead of decoding multiple indexer variants themselves.
21+
1922
## Preset Configs
2023

2124
Use `StrikeConfig::bsc_mainnet()` for BSC mainnet with default RPC, WSS, and indexer endpoints. See [Client Configuration](client.md) for custom setups.

sdk/rust/README.md

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@ async fn main() -> Result<()> {
3434
let count = client.markets().active_market_count().await?;
3535
println!("{count} active markets on-chain");
3636

37+
if let Some(first) = markets.first() {
38+
let meta = client
39+
.markets()
40+
.market_meta(first.factory_market_id as u64)
41+
.await?;
42+
println!(
43+
"factory {} -> orderbook {} | internal positions: {}",
44+
meta.factory_market_id, meta.orderbook_market_id, meta.use_internal_positions
45+
);
46+
}
47+
3748
Ok(())
3849
}
3950
```
@@ -181,12 +192,39 @@ strike-sdk = { version = "0.2", default-features = false }
181192
| `chain::vault` | USDT approval, balance queries |
182193
| `chain::redeem` | Outcome token redemption |
183194
| `chain::tokens` | ERC-1155 outcome token helpers |
184-
| `chain::markets` | On-chain market state reads |
195+
| `chain::markets` | On-chain market state reads, including `market_meta(factory_market_id)` |
185196
| `events::subscribe` | WSS event stream with auto-reconnect |
186197
| `events::scan` | Historical event scanning (chunked getLogs) |
187198
| `indexer` | REST client: markets, positions, trades, stats (API v1) |
188199
| `nonce` | `NonceSender` for sequential TX sends |
189200

201+
## Wallet Positions
202+
203+
Use the indexer for wallet snapshots and redeem backlog discovery:
204+
205+
```rust
206+
let wallet = "0x...";
207+
208+
let positions = client.indexer().get_positions(wallet).await?;
209+
println!(
210+
"open orders: {} | filled positions: {}",
211+
positions.open_orders.len(),
212+
positions.filled_positions.len()
213+
);
214+
215+
let redeemable = client.indexer().get_redeemable_positions(wallet).await?;
216+
for entry in &redeemable {
217+
println!(
218+
"factory {:?} | lots {:?} | redeemable {:?}",
219+
entry.factory_market_id(),
220+
entry.lots_hint(),
221+
entry.redeemable()
222+
);
223+
}
224+
```
225+
226+
The SDK normalizes evolving `/positions/:address` and `/positions/:address/redeemable` payloads into accessor-based position types, so callers do not need to chase field-name drift across indexer versions.
227+
190228
## AI Markets
191229

192230
Markets with `is_ai_market: true` are resolved by the Flap AI Oracle instead of Pyth price feeds. The `Market` struct includes:

0 commit comments

Comments
 (0)