Skip to content

Commit 4b5a749

Browse files
authored
Merge pull request #60 from Polymarket/fix/complete-json-output-fields
fix: add all missing fields to JSON output across all endpoints
2 parents e1c021f + b3b7dbf commit 4b5a749

4 files changed

Lines changed: 103 additions & 7 deletions

File tree

src/output/bridge.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ pub fn print_supported_assets(
7373
println!("{table}");
7474
}
7575
OutputFormat::Json => {
76-
let data: Vec<_> = response
76+
let assets: Vec<_> = response
7777
.supported_assets
7878
.iter()
7979
.map(|a| {
@@ -88,6 +88,10 @@ pub fn print_supported_assets(
8888
})
8989
})
9090
.collect();
91+
let data = json!({
92+
"supported_assets": assets,
93+
"note": response.note,
94+
});
9195
super::print_json(&data)?;
9296
}
9397
}

src/output/clob/account.rs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,28 @@ pub fn print_notifications(
132132
.map(|n| {
133133
json!({
134134
"type": n.r#type,
135-
"question": n.payload.question,
136-
"side": n.payload.side.to_string(),
137-
"price": n.payload.price.to_string(),
138-
"outcome": n.payload.outcome,
135+
"owner": n.owner.to_string(),
136+
"asset_id": n.payload.asset_id.to_string(),
137+
"condition_id": n.payload.condition_id.to_string(),
138+
"event_slug": n.payload.event_slug,
139+
"icon": n.payload.icon,
140+
"image": n.payload.image,
141+
"market": n.payload.market.to_string(),
142+
"market_slug": n.payload.market_slug,
139143
"matched_size": n.payload.matched_size.to_string(),
140-
"original_size": n.payload.original_size.to_string(),
141144
"order_id": n.payload.order_id,
145+
"original_size": n.payload.original_size.to_string(),
146+
"outcome": n.payload.outcome,
147+
"outcome_index": n.payload.outcome_index,
148+
"owner_payload": n.payload.owner.to_string(),
149+
"price": n.payload.price.to_string(),
150+
"question": n.payload.question,
151+
"remaining_size": n.payload.remaining_size.to_string(),
152+
"series_slug": n.payload.series_slug,
153+
"side": n.payload.side.to_string(),
142154
"trade_id": n.payload.trade_id,
143-
"market": n.payload.market.to_string(),
155+
"transaction_hash": n.payload.transaction_hash.to_string(),
156+
"order_type": n.payload.order_type.to_string(),
144157
})
145158
})
146159
.collect();
@@ -293,6 +306,7 @@ pub fn print_user_earnings_markets(
293306
"question": e.question,
294307
"market_slug": e.market_slug,
295308
"event_slug": e.event_slug,
309+
"image": e.image,
296310
"earning_percentage": e.earning_percentage.to_string(),
297311
"rewards_max_spread": e.rewards_max_spread.to_string(),
298312
"rewards_min_size": e.rewards_min_size.to_string(),
@@ -467,6 +481,7 @@ pub fn print_market_reward(
467481
"question": r.question,
468482
"market_slug": r.market_slug,
469483
"event_slug": r.event_slug,
484+
"image": r.image,
470485
"rewards_max_spread": r.rewards_max_spread.to_string(),
471486
"rewards_min_size": r.rewards_min_size.to_string(),
472487
"market_competitiveness": r.market_competitiveness.to_string(),

src/output/clob/orders.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,15 @@ pub fn print_orders(result: &Page<OpenOrderResponse>, output: &OutputFormat) ->
6060
json!({
6161
"id": o.id,
6262
"status": o.status.to_string(),
63+
"owner": o.owner.to_string(),
64+
"maker_address": o.maker_address.to_string(),
6365
"market": o.market.to_string(),
6466
"asset_id": o.asset_id.to_string(),
6567
"side": o.side.to_string(),
6668
"price": o.price.to_string(),
6769
"original_size": o.original_size.to_string(),
6870
"size_matched": o.size_matched.to_string(),
71+
"associate_trades": o.associate_trades,
6972
"outcome": o.outcome,
7073
"order_type": o.order_type.to_string(),
7174
"created_at": o.created_at.to_rfc3339(),
@@ -273,9 +276,25 @@ pub fn print_trades(result: &Page<TradeResponse>, output: &OutputFormat) -> anyh
273276
"fee_rate_bps": t.fee_rate_bps.to_string(),
274277
"status": t.status.to_string(),
275278
"match_time": t.match_time.to_rfc3339(),
279+
"last_update": t.last_update.to_rfc3339(),
276280
"outcome": t.outcome,
281+
"bucket_index": t.bucket_index,
282+
"owner": t.owner.to_string(),
283+
"maker_address": t.maker_address.to_string(),
284+
"maker_orders": t.maker_orders.iter().map(|m| json!({
285+
"order_id": m.order_id,
286+
"owner": m.owner.to_string(),
287+
"maker_address": m.maker_address.to_string(),
288+
"matched_amount": m.matched_amount.to_string(),
289+
"price": m.price.to_string(),
290+
"fee_rate_bps": m.fee_rate_bps.to_string(),
291+
"asset_id": m.asset_id.to_string(),
292+
"outcome": m.outcome,
293+
"side": m.side.to_string(),
294+
})).collect::<Vec<_>>(),
277295
"trader_side": format!("{:?}", t.trader_side),
278296
"transaction_hash": t.transaction_hash.to_string(),
297+
"error_msg": t.error_msg,
279298
})
280299
})
281300
.collect();

src/output/data.rs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,30 @@ pub fn print_positions(positions: &[Position], output: &OutputFormat) -> anyhow:
5959
json!({
6060
"title": p.title,
6161
"slug": p.slug,
62+
"icon": p.icon,
63+
"event_slug": p.event_slug,
64+
"event_id": p.event_id,
6265
"outcome": p.outcome,
6366
"outcome_index": p.outcome_index,
67+
"opposite_outcome": p.opposite_outcome,
68+
"opposite_asset": p.opposite_asset.to_string(),
69+
"asset": p.asset.to_string(),
6470
"size": p.size.to_string(),
6571
"avg_price": p.avg_price.to_string(),
6672
"initial_value": p.initial_value.to_string(),
6773
"current_value": p.current_value.to_string(),
6874
"cash_pnl": p.cash_pnl.to_string(),
6975
"percent_pnl": p.percent_pnl.to_string(),
76+
"total_bought": p.total_bought.to_string(),
7077
"realized_pnl": p.realized_pnl.to_string(),
78+
"percent_realized_pnl": p.percent_realized_pnl.to_string(),
7179
"cur_price": p.cur_price.to_string(),
7280
"condition_id": p.condition_id.to_string(),
7381
"proxy_wallet": p.proxy_wallet.to_string(),
7482
"redeemable": p.redeemable,
7583
"mergeable": p.mergeable,
84+
"end_date": p.end_date.to_string(),
85+
"negative_risk": p.negative_risk,
7686
})
7787
})
7888
.collect();
@@ -122,15 +132,21 @@ pub fn print_closed_positions(
122132
json!({
123133
"title": p.title,
124134
"slug": p.slug,
135+
"icon": p.icon,
136+
"event_slug": p.event_slug,
125137
"outcome": p.outcome,
126138
"outcome_index": p.outcome_index,
139+
"opposite_outcome": p.opposite_outcome,
140+
"opposite_asset": p.opposite_asset.to_string(),
141+
"asset": p.asset.to_string(),
127142
"avg_price": p.avg_price.to_string(),
128143
"total_bought": p.total_bought.to_string(),
129144
"realized_pnl": p.realized_pnl.to_string(),
130145
"cur_price": p.cur_price.to_string(),
131146
"condition_id": p.condition_id.to_string(),
132147
"proxy_wallet": p.proxy_wallet.to_string(),
133148
"timestamp": p.timestamp,
149+
"end_date": p.end_date.date_naive().to_string(),
134150
})
135151
})
136152
.collect();
@@ -228,15 +244,23 @@ pub fn print_trades(trades: &[Trade], output: &OutputFormat) -> anyhow::Result<(
228244
json!({
229245
"title": t.title,
230246
"slug": t.slug,
247+
"icon": t.icon,
248+
"event_slug": t.event_slug,
231249
"side": t.side.to_string(),
232250
"outcome": t.outcome,
233251
"outcome_index": t.outcome_index,
252+
"asset": t.asset.to_string(),
234253
"size": t.size.to_string(),
235254
"price": t.price.to_string(),
236255
"timestamp": t.timestamp,
237256
"condition_id": t.condition_id.to_string(),
238257
"proxy_wallet": t.proxy_wallet.to_string(),
239258
"transaction_hash": t.transaction_hash.to_string(),
259+
"name": t.name,
260+
"pseudonym": t.pseudonym,
261+
"bio": t.bio,
262+
"profile_image": t.profile_image,
263+
"profile_image_optimized": t.profile_image_optimized,
240264
})
241265
})
242266
.collect();
@@ -259,6 +283,12 @@ pub fn print_activity(activity: &[Activity], output: &OutputFormat) -> anyhow::R
259283
activity_type: String,
260284
#[tabled(rename = "Market")]
261285
title: String,
286+
#[tabled(rename = "Side")]
287+
side: String,
288+
#[tabled(rename = "Outcome")]
289+
outcome: String,
290+
#[tabled(rename = "Price")]
291+
price: String,
262292
#[tabled(rename = "Size")]
263293
size: String,
264294
#[tabled(rename = "USDC")]
@@ -271,6 +301,9 @@ pub fn print_activity(activity: &[Activity], output: &OutputFormat) -> anyhow::R
271301
.map(|a| Row {
272302
activity_type: a.activity_type.to_string(),
273303
title: truncate(a.title.as_deref().unwrap_or(DASH), 35),
304+
side: a.side.as_ref().map(|s| s.to_string()).unwrap_or_default(),
305+
outcome: a.outcome.as_deref().unwrap_or(DASH).into(),
306+
price: a.price.map(|p| format!("{:.4}", p)).unwrap_or_default(),
274307
size: format!("{:.2}", a.size),
275308
usdc_size: format_decimal(a.usdc_size),
276309
tx: truncate(&a.transaction_hash.to_string(), 14),
@@ -286,11 +319,25 @@ pub fn print_activity(activity: &[Activity], output: &OutputFormat) -> anyhow::R
286319
json!({
287320
"activity_type": a.activity_type.to_string(),
288321
"title": a.title,
322+
"slug": a.slug,
323+
"icon": a.icon,
324+
"event_slug": a.event_slug,
325+
"side": a.side.as_ref().map(|s| s.to_string()),
326+
"outcome": a.outcome,
327+
"outcome_index": a.outcome_index,
328+
"price": a.price.map(|p| p.to_string()),
329+
"asset": a.asset.map(|a| a.to_string()),
330+
"condition_id": a.condition_id.map(|c| c.to_string()),
289331
"size": a.size.to_string(),
290332
"usdc_size": a.usdc_size.to_string(),
291333
"timestamp": a.timestamp,
292334
"transaction_hash": a.transaction_hash.to_string(),
293335
"proxy_wallet": a.proxy_wallet.to_string(),
336+
"name": a.name,
337+
"pseudonym": a.pseudonym,
338+
"bio": a.bio,
339+
"profile_image": a.profile_image,
340+
"profile_image_optimized": a.profile_image_optimized,
294341
})
295342
})
296343
.collect();
@@ -349,8 +396,14 @@ pub fn print_holders(meta_holders: &[MetaHolder], output: &OutputFormat) -> anyh
349396
"proxy_wallet": h.proxy_wallet.to_string(),
350397
"name": h.name,
351398
"pseudonym": h.pseudonym,
399+
"bio": h.bio,
400+
"asset": h.asset.to_string(),
352401
"amount": h.amount.to_string(),
353402
"outcome_index": h.outcome_index,
403+
"display_username_public": h.display_username_public,
404+
"profile_image": h.profile_image,
405+
"profile_image_optimized": h.profile_image_optimized,
406+
"verified": h.verified,
354407
})
355408
})
356409
.collect();
@@ -487,6 +540,9 @@ pub fn print_leaderboard(
487540
"user_name": e.user_name,
488541
"pnl": e.pnl.to_string(),
489542
"volume": e.vol.to_string(),
543+
"profile_image": e.profile_image,
544+
"x_username": e.x_username,
545+
"verified_badge": e.verified_badge,
490546
})
491547
})
492548
.collect();
@@ -539,6 +595,7 @@ pub fn print_builder_leaderboard(
539595
"volume": e.volume.to_string(),
540596
"active_users": e.active_users,
541597
"verified": e.verified,
598+
"builder_logo": e.builder_logo,
542599
})
543600
})
544601
.collect();
@@ -591,6 +648,7 @@ pub fn print_builder_volume(
591648
json!({
592649
"date": e.dt.to_rfc3339(),
593650
"builder": e.builder,
651+
"builder_logo": e.builder_logo,
594652
"volume": e.volume.to_string(),
595653
"active_users": e.active_users,
596654
"rank": e.rank,

0 commit comments

Comments
 (0)