@structbuild/sdk 0.2.10 → 0.3.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 CHANGED
@@ -45,44 +45,50 @@ const client = new StructClient({
45
45
 
46
46
  ```typescript
47
47
  const markets = await client.markets.getMarkets({ limit: 10 });
48
- const market = await client.markets.getMarket({ condition_id: "0x..." });
49
- const marketBySlug = await client.markets.getMarketBySlug({ slug: "will-x-happen" });
50
- const trades = await client.markets.getTrades({ condition_id: "0x..." });
51
- const candles = await client.markets.getCandlestick({ condition_id: "0x...", timeframe: "1d", interval: "1h" });
48
+ const market = await client.markets.getMarket({ conditionId: "0x..." });
49
+ const marketBySlug = await client.markets.getMarketBySlug({ marketSlug: "will-x-happen" });
50
+ const trades = await client.markets.getTrades({ condition_ids: "0x..." });
51
+ const candles = await client.markets.getCandlestick({ condition_id: "0x...", resolution: "1h" });
52
+ const chart = await client.markets.getMarketChart({ condition_id: "0x..." });
52
53
  const metrics = await client.markets.getMarketMetrics({ condition_id: "0x..." });
53
54
  const volumeChart = await client.markets.getMarketVolumeChart({ condition_id: "0x..." });
55
+ const priceJumps = await client.markets.getPriceJumps();
54
56
  ```
55
57
 
56
58
  ### Events
57
59
 
58
60
  ```typescript
59
61
  const events = await client.events.getEvents({ limit: 10 });
60
- const event = await client.events.getEvent({ id: "123" });
62
+ const event = await client.events.getEvent({ identifier: "123" });
61
63
  const eventBySlug = await client.events.getEventBySlug({ slug: "us-election" });
62
- const eventMetrics = await client.events.getEventMetrics({ event_id: "123" });
64
+ const eventMetrics = await client.events.getEventMetrics({ event_slug: "us-election", timeframe: "24h" });
65
+ const outcomes = await client.events.getEventOutcomes({ event_slug: "us-election" });
66
+ const chart = await client.events.getEventChart({ event_slug: "us-election" });
63
67
  ```
64
68
 
65
69
  ### Trader / Portfolio
66
70
 
67
71
  ```typescript
68
- const portfolio = await client.trader.getPortfolio({ address: "0x..." });
69
- const positions = await client.trader.getPortfolioPositions({ address: "0x..." });
70
72
  const trades = await client.trader.getTraderTrades({ address: "0x..." });
71
73
  const profile = await client.trader.getTraderProfile({ address: "0x..." });
74
+ const profiles = await client.trader.getTraderProfilesBatch({ addresses: "0x...,0x..." });
72
75
  const pnl = await client.trader.getTraderPnl({ address: "0x..." });
73
76
  const pnlByMarket = await client.trader.getTraderMarketPnl({ address: "0x..." });
74
77
  const pnlByEvent = await client.trader.getTraderEventPnl({ address: "0x..." });
75
78
  const pnlCandles = await client.trader.getTraderPnlCandles({ address: "0x..." });
79
+ const calendar = await client.trader.getTraderPnlCalendar({ address: "0x..." });
80
+ const positionPnl = await client.trader.getTraderOutcomePnl({ address: "0x..." });
76
81
  const volumeChart = await client.trader.getTraderVolumeChart({ address: "0x..." });
82
+ const leaderboard = await client.trader.getGlobalPnl();
77
83
  ```
78
84
 
79
85
  ### Holders
80
86
 
81
87
  ```typescript
82
88
  const marketHolders = await client.holders.getMarketHolders({ condition_id: "0x..." });
83
- const eventHolders = await client.holders.getEventHolders({ event_slug: "us-election" });
84
- const positionHolders = await client.holders.getPositionHolders({ position_id: "123" });
89
+ const positionHolders = await client.holders.getPositionHolders({ positionId: "123" });
85
90
  const history = await client.holders.getMarketHoldersHistory({ condition_id: "0x..." });
91
+ const posHistory = await client.holders.getPositionHoldersHistory({ positionId: "123" });
86
92
  ```
87
93
 
88
94
  ### Series
@@ -92,14 +98,53 @@ const series = await client.series.getSeriesList();
92
98
  const outcomes = await client.series.getSeriesOutcomes({ series_slug: "my-series" });
93
99
  ```
94
100
 
95
- ### Search, Tags, Bonds
101
+ ### Assets, Search, Tags, Bonds
96
102
 
97
103
  ```typescript
104
+ const assetHistory = await client.assets.getAssetHistory({ symbol: "BTC", variant: "1d" });
98
105
  const results = await client.search.search({ query: "election" });
99
106
  const tags = await client.tags.getTags();
107
+ const tag = await client.tags.getTag({ identifier: "politics" });
100
108
  const bonds = await client.bonds.getBonds();
101
109
  ```
102
110
 
111
+ ### Trade Types
112
+
113
+ Trade endpoints (`getTrades`, `getTraderTrades`) return a discriminated union of all on-chain event types. Use the `trade_type` field to narrow:
114
+
115
+ ```typescript
116
+ import type { Trade, MarketTrade, OracleEvent, TradeEventType } from "@structbuild/sdk";
117
+
118
+ const { data: trades } = await client.markets.getTrades();
119
+
120
+ for (const trade of trades) {
121
+ switch (trade.trade_type) {
122
+ case "OrderFilled":
123
+ case "OrdersMatched":
124
+ console.log(trade.price, trade.usd_amount, trade.shares_amount);
125
+ break;
126
+ case "Redemption":
127
+ console.log(trade.winning_outcome_index, trade.position_details);
128
+ break;
129
+ case "Merge":
130
+ case "Split":
131
+ console.log(trade.usd_amount, trade.position_details);
132
+ break;
133
+ case "Resolution":
134
+ console.log(trade.payout_numerators);
135
+ break;
136
+ }
137
+ }
138
+ ```
139
+
140
+ The SDK exports convenience sub-unions for common filtering:
141
+
142
+ - **`MarketTrade`** — actual on-chain trades: `OrderFilled`, `OrdersMatched`, `Redemption`, `Merge`, `Split`, `PositionsConverted`, `Cancelled`, `RegisterToken`, `Approval`
143
+ - **`OracleEvent`** — protocol lifecycle events: `Initialization`, `Proposal`, `Dispute`, `Settled`, `Resolution`, `ConditionResolution`, `Reset`, `Flag`, `Unflag`, `Pause`, `Unpause`, `ManualResolution`, `NegRiskOutcomeReported`
144
+ - **`TradeEventType`** — string literal union of all `trade_type` values for autocomplete
145
+
146
+ Individual schemas are also exported: `OrderFilledTrade`, `RedemptionTrade`, `MergeTrade`, `SplitTrade`, `CancelledTrade`, `PositionsConvertedTrade`, `RegisterTokenTrade`, `ApprovalTrade`, and all oracle event types.
147
+
103
148
  ### Webhooks
104
149
 
105
150
  Manage webhook subscriptions for real-time event notifications. Webhook endpoints are platform-level (not venue-scoped).
@@ -117,7 +162,9 @@ const webhook = await client.webhooks.create({
117
162
  const detail = await client.webhooks.getWebhook({ webhookId: webhook.data.id });
118
163
  await client.webhooks.update({ webhookId: webhook.data.id, events: ["first_trade"] });
119
164
  await client.webhooks.test({ webhookId: webhook.data.id });
165
+ await client.webhooks.rotateSecret({ webhookId: webhook.data.id });
120
166
  await client.webhooks.deleteWebhook({ webhookId: webhook.data.id });
167
+ const events = await client.webhooks.listEvents();
121
168
  ```
122
169
 
123
170
  #### Webhook Payload Types
@@ -137,7 +184,7 @@ function handleWebhook(payload: FirstTradePayload) {
137
184
  }
138
185
  ```
139
186
 
140
- Available payload types: `FirstTradePayload`, `GlobalPnlPayload`, `MarketPnlPayload`, `EventPnlPayload`, `PositionPnlPayload`, `ConditionMetricsPayload`, `EventMetricsPayload`, `PositionMetricsPayload`, `VolumeMilestonePayload`, `EventVolumeMilestonePayload`, `PositionVolumeMilestonePayload`, `ProbabilitySpikePayload`.
187
+ Available payload types: `FirstTradePayload`, `GlobalPnlPayload`, `MarketPnlPayload`, `EventPnlPayload`, `ConditionMetricsPayload`, `EventMetricsPayload`, `PositionMetricsPayload`, `VolumeMilestonePayload`, `EventVolumeMilestonePayload`, `PositionVolumeMilestonePayload`, `ProbabilitySpikePayload`.
141
188
 
142
189
  ## JWT Auth
143
190
 
@@ -184,7 +231,7 @@ for await (const market of paginate(
184
231
  import { HttpError, TimeoutError, NetworkError } from "@structbuild/sdk";
185
232
 
186
233
  try {
187
- await client.markets.getMarket({ condition_id: "0x..." });
234
+ await client.markets.getMarket({ conditionId: "0x..." });
188
235
  } catch (error) {
189
236
  if (error instanceof HttpError) {
190
237
  console.log(error.status, error.body);
package/dist/client.d.ts CHANGED
@@ -3,6 +3,7 @@ import type { RetryConfig, RequestHookInfo, ResponseHookInfo } from "./types/ind
3
3
  import { AssetsNamespace, HoldersNamespace, TagsNamespace, EventsNamespace, MarketsNamespace, SeriesNamespace, TraderNamespace, BondsNamespace, SearchNamespace, OrderBookNamespace, WebhooksNamespace } from "./namespaces/index.js";
4
4
  export interface StructClientConfig {
5
5
  apiKey: string;
6
+ jwt?: string;
6
7
  baseUrl?: string;
7
8
  venue?: Venue;
8
9
  headers?: Record<string, string>;