akshare 0.1.14

100% pure Rust implementation of akshare — unified access to Chinese and global financial market data APIs
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
//! US macro-economic data from Eastmoney datacenter and Jin10.

use crate::client::AkShareClient;
use crate::error::Result;
use crate::types::MacroDataPoint;

use super::shared::{fetch_em_indicator, fetch_jin10_report};

// ---------------------------------------------------------------------------
// Eastmoney datacenter — RPT_ECONOMICVALUE_USA with INDICATOR_ID
// ---------------------------------------------------------------------------

impl AkShareClient {
    /// US pending home sales monthly rate (未决房屋销售月率).
    pub async fn us_pending_home_sales(&self) -> Result<Vec<MacroDataPoint>> {
        fetch_em_indicator(
            self,
            "RPT_ECONOMICVALUE_USA",
            "EMG00342249",
            "US Pending Home Sales",
        )
        .await
    }

    /// US CPI YoY (CPI年率).
    pub async fn us_cpi_yoy(&self) -> Result<Vec<MacroDataPoint>> {
        fetch_em_indicator(self, "RPT_ECONOMICVALUE_USA", "EMG00000733", "US CPI YoY").await
    }
}

// ---------------------------------------------------------------------------
// Jin10 datacenter — US macro indicators with attr_id
// ---------------------------------------------------------------------------

impl AkShareClient {
    /// US GDP monthly (美国国内生产总值).
    pub async fn us_gdp_monthly(&self) -> Result<Vec<MacroDataPoint>> {
        fetch_jin10_report(self, "53", "US GDP Monthly").await
    }

    /// US CPI monthly (美国CPI月率).
    pub async fn us_cpi_monthly(&self) -> Result<Vec<MacroDataPoint>> {
        fetch_jin10_report(self, "9", "US CPI Monthly").await
    }

    /// US core CPI monthly (美国核心CPI月率).
    pub async fn us_core_cpi_monthly(&self) -> Result<Vec<MacroDataPoint>> {
        fetch_jin10_report(self, "6", "US Core CPI Monthly").await
    }

    /// US personal spending (美国个人支出月率).
    pub async fn us_personal_spending(&self) -> Result<Vec<MacroDataPoint>> {
        fetch_jin10_report(self, "35", "US Personal Spending").await
    }

    /// US retail sales (美国零售销售月率).
    pub async fn us_retail_sales(&self) -> Result<Vec<MacroDataPoint>> {
        fetch_jin10_report(self, "39", "US Retail Sales").await
    }

    /// US import price (美国进口物价指数).
    pub async fn us_import_price(&self) -> Result<Vec<MacroDataPoint>> {
        fetch_jin10_report(self, "18", "US Import Price").await
    }

    /// US export price (美国出口价格指数).
    pub async fn us_export_price(&self) -> Result<Vec<MacroDataPoint>> {
        fetch_jin10_report(self, "79", "US Export Price").await
    }

    /// US LMCI (美联储劳动力市场状况指数).
    pub async fn us_lmci(&self) -> Result<Vec<MacroDataPoint>> {
        fetch_jin10_report(self, "93", "US LMCI").await
    }

    /// US unemployment rate (美国失业率).
    pub async fn us_unemployment_rate(&self) -> Result<Vec<MacroDataPoint>> {
        fetch_jin10_report(self, "47", "US Unemployment Rate").await
    }

    /// US job cuts (挑战者企业裁员人数).
    pub async fn us_job_cuts(&self) -> Result<Vec<MacroDataPoint>> {
        fetch_jin10_report(self, "78", "US Job Cuts").await
    }

    /// US non-farm payrolls (非农就业人数).
    pub async fn us_non_farm(&self) -> Result<Vec<MacroDataPoint>> {
        fetch_jin10_report(self, "33", "US Non-Farm Payrolls").await
    }

    /// US ADP employment (ADP就业人数).
    pub async fn us_adp_employment(&self) -> Result<Vec<MacroDataPoint>> {
        fetch_jin10_report(self, "1", "US ADP Employment").await
    }

    /// US core PCE price (核心PCE物价指数).
    pub async fn us_core_pce_price(&self) -> Result<Vec<MacroDataPoint>> {
        fetch_jin10_report(self, "80", "US Core PCE Price").await
    }

    /// US real consumer spending (实际个人消费支出).
    pub async fn us_real_consumer_spending(&self) -> Result<Vec<MacroDataPoint>> {
        fetch_jin10_report(self, "81", "US Real Consumer Spending").await
    }

    /// US trade balance (贸易帐).
    pub async fn us_trade_balance(&self) -> Result<Vec<MacroDataPoint>> {
        fetch_jin10_report(self, "42", "US Trade Balance").await
    }

    /// US current account (经常帐).
    pub async fn us_current_account(&self) -> Result<Vec<MacroDataPoint>> {
        fetch_jin10_report(self, "12", "US Current Account").await
    }

    /// US PPI (生产者物价指数).
    pub async fn us_ppi(&self) -> Result<Vec<MacroDataPoint>> {
        fetch_jin10_report(self, "37", "US PPI").await
    }

    /// US core PPI (核心生产者物价指数).
    pub async fn us_core_ppi(&self) -> Result<Vec<MacroDataPoint>> {
        fetch_jin10_report(self, "7", "US Core PPI").await
    }

    /// US API crude stock (API原油库存).
    pub async fn us_api_crude_stock(&self) -> Result<Vec<MacroDataPoint>> {
        fetch_jin10_report(self, "69", "US API Crude Stock").await
    }

    /// US PMI (制造业PMI).
    pub async fn us_pmi(&self) -> Result<Vec<MacroDataPoint>> {
        fetch_jin10_report(self, "74", "US PMI").await
    }

    /// US ISM PMI (ISM制造业PMI).
    pub async fn us_ism_pmi(&self) -> Result<Vec<MacroDataPoint>> {
        fetch_jin10_report(self, "28", "US ISM PMI").await
    }

    /// US industrial production (工业产出月率).
    pub async fn us_industrial_production(&self) -> Result<Vec<MacroDataPoint>> {
        fetch_jin10_report(self, "20", "US Industrial Production").await
    }

    /// US durable goods orders (耐用品订单月率).
    pub async fn us_durable_goods_orders(&self) -> Result<Vec<MacroDataPoint>> {
        fetch_jin10_report(self, "13", "US Durable Goods Orders").await
    }

    /// US factory orders (工厂订单月率).
    pub async fn us_factory_orders(&self) -> Result<Vec<MacroDataPoint>> {
        fetch_jin10_report(self, "16", "US Factory Orders").await
    }

    /// US services PMI (服务业PMI).
    pub async fn us_services_pmi(&self) -> Result<Vec<MacroDataPoint>> {
        fetch_jin10_report(self, "89", "US Services PMI").await
    }

    /// US business inventories (商业库存月率).
    pub async fn us_business_inventories(&self) -> Result<Vec<MacroDataPoint>> {
        fetch_jin10_report(self, "4", "US Business Inventories").await
    }

    /// US ISM non-manufacturing PMI (ISM非制造业PMI).
    pub async fn us_ism_non_pmi(&self) -> Result<Vec<MacroDataPoint>> {
        fetch_jin10_report(self, "29", "US ISM Non-PMI").await
    }

    /// US NAHB housing market index (NAHB房产市场指数).
    pub async fn us_nahb_house_market_index(&self) -> Result<Vec<MacroDataPoint>> {
        fetch_jin10_report(self, "31", "US NAHB House Market").await
    }

    /// US housing starts (新屋开工月率).
    pub async fn us_house_starts(&self) -> Result<Vec<MacroDataPoint>> {
        fetch_jin10_report(self, "17", "US House Starts").await
    }

    /// US new home sales (新屋销售月率).
    pub async fn us_new_home_sales(&self) -> Result<Vec<MacroDataPoint>> {
        fetch_jin10_report(self, "32", "US New Home Sales").await
    }

    /// US building permits (营建许可月率).
    pub async fn us_building_permits(&self) -> Result<Vec<MacroDataPoint>> {
        fetch_jin10_report(self, "3", "US Building Permits").await
    }

    /// US existing home sales (成屋销售月率).
    pub async fn us_exist_home_sales(&self) -> Result<Vec<MacroDataPoint>> {
        fetch_jin10_report(self, "15", "US Existing Home Sales").await
    }

    /// US house price index (房价指数月率).
    pub async fn us_house_price_index(&self) -> Result<Vec<MacroDataPoint>> {
        fetch_jin10_report(self, "51", "US House Price Index").await
    }

    /// US S&P/Case-Shiller 20-city house price index.
    pub async fn us_spcs20(&self) -> Result<Vec<MacroDataPoint>> {
        fetch_jin10_report(self, "52", "US SPCS20").await
    }

    /// US pending home sales (未决房屋销售月率 Jin10).
    pub async fn us_pending_home_sales_jin10(&self) -> Result<Vec<MacroDataPoint>> {
        fetch_jin10_report(self, "34", "US Pending Home Sales").await
    }

    /// US CB consumer confidence (谘商会消费者信心指数).
    pub async fn us_cb_consumer_confidence(&self) -> Result<Vec<MacroDataPoint>> {
        fetch_jin10_report(self, "5", "US CB Consumer Confidence").await
    }

    /// US NFIB small business optimism (NFIB小型企业乐观指数).
    pub async fn us_nfib_small_business(&self) -> Result<Vec<MacroDataPoint>> {
        fetch_jin10_report(self, "63", "US NFIB Small Business").await
    }

    /// US Michigan consumer sentiment (密歇根大学消费者信心指数).
    pub async fn us_michigan_consumer_sentiment(&self) -> Result<Vec<MacroDataPoint>> {
        fetch_jin10_report(self, "50", "US Michigan Consumer Sentiment").await
    }

    /// US EIA crude oil rate (EIA原油库存变化率).
    pub async fn us_eia_crude_rate(&self) -> Result<Vec<MacroDataPoint>> {
        fetch_jin10_report(self, "10", "US EIA Crude Rate").await
    }

    /// US initial jobless claims (初请失业金人数).
    pub async fn us_initial_jobless(&self) -> Result<Vec<MacroDataPoint>> {
        fetch_jin10_report(self, "44", "US Initial Jobless Claims").await
    }
}

// ---------------------------------------------------------------------------
// Jin10 CDN — US macro indicators
// ---------------------------------------------------------------------------

use serde::Deserialize;

#[derive(Debug, Deserialize)]
struct Jin10CdnResp {
    values: Option<serde_json::Value>,
}

impl AkShareClient {
    /// Baker Hughes US rig count (贝克休斯钻井报告).
    pub async fn us_rig_count(&self) -> Result<Vec<MacroDataPoint>> {
        let url = "https://cdn.jin10.com/data_center/reports/baker.json";
        let resp: Jin10CdnResp = self.get(url).send().await?.json().await?;

        let values = resp.values.unwrap_or_default();
        let mut items = Vec::new();
        if let Some(obj) = values.as_object() {
            for (date, row) in obj {
                if let Some(arr) = row.as_array()
                    && arr.len() >= 2
                {
                    let count = arr[0].as_f64().unwrap_or(0.0);
                    items.push(MacroDataPoint {
                        date: date.clone(),
                        value: count,
                        name: "US Rig Count".to_string(),
                    });
                }
            }
        }
        items.sort_by(|a, b| a.date.cmp(&b.date));
        Ok(items)
    }

    /// US crude oil production (美国原油产量).
    pub async fn us_crude_production(&self) -> Result<Vec<MacroDataPoint>> {
        let url = "https://cdn.jin10.com/data_center/reports/usa_oil.json";
        let resp: Jin10CdnResp = self.get(url).send().await?.json().await?;

        let values = resp.values.unwrap_or_default();
        let mut items = Vec::new();
        if let Some(obj) = values.as_object() {
            for (date, row) in obj {
                if let Some(arr) = row.as_array() {
                    // First key is total US crude production
                    if let Some(inner) = arr.first().and_then(|v| v.as_array())
                        && let Some(val) = inner.first().and_then(serde_json::Value::as_f64)
                    {
                        items.push(MacroDataPoint {
                            date: date.clone(),
                            value: val,
                            name: "US Crude Production".to_string(),
                        });
                    }
                }
            }
        }
        items.sort_by(|a, b| a.date.cmp(&b.date));
        Ok(items)
    }

    /// US crude oil production (美国原油产量报告) - alias.
    pub async fn macro_usa_crude_inner(&self) -> Result<Vec<MacroDataPoint>> {
        self.us_crude_production().await
    }
}

// ---------------------------------------------------------------------------
// Python-compatible macro_usa_* aliases
// ---------------------------------------------------------------------------

impl AkShareClient {
    /// Fetch usa phs macro data.
    pub async fn macro_usa_phs(&self) -> Result<Vec<MacroDataPoint>> {
        self.us_pending_home_sales().await
    }

    /// Fetch usa cpi yoy macro data.
    pub async fn macro_usa_cpi_yoy(&self) -> Result<Vec<MacroDataPoint>> {
        self.us_cpi_yoy().await
    }

    /// Fetch usa gdp monthly macro data.
    pub async fn macro_usa_gdp_monthly(&self) -> Result<Vec<MacroDataPoint>> {
        self.us_gdp_monthly().await
    }

    /// Fetch usa cpi monthly macro data.
    pub async fn macro_usa_cpi_monthly(&self) -> Result<Vec<MacroDataPoint>> {
        self.us_cpi_monthly().await
    }

    /// Fetch usa core cpi monthly macro data.
    pub async fn macro_usa_core_cpi_monthly(&self) -> Result<Vec<MacroDataPoint>> {
        self.us_core_cpi_monthly().await
    }

    /// Fetch usa personal spending macro data.
    pub async fn macro_usa_personal_spending(&self) -> Result<Vec<MacroDataPoint>> {
        self.us_personal_spending().await
    }

    /// Fetch usa retail sales macro data.
    pub async fn macro_usa_retail_sales(&self) -> Result<Vec<MacroDataPoint>> {
        self.us_retail_sales().await
    }

    /// Fetch usa import price macro data.
    pub async fn macro_usa_import_price(&self) -> Result<Vec<MacroDataPoint>> {
        self.us_import_price().await
    }

    /// Fetch usa export price macro data.
    pub async fn macro_usa_export_price(&self) -> Result<Vec<MacroDataPoint>> {
        self.us_export_price().await
    }

    /// Fetch usa lmci macro data.
    pub async fn macro_usa_lmci(&self) -> Result<Vec<MacroDataPoint>> {
        self.us_lmci().await
    }

    /// Fetch usa unemployment rate macro data.
    pub async fn macro_usa_unemployment_rate(&self) -> Result<Vec<MacroDataPoint>> {
        self.us_unemployment_rate().await
    }

    /// Fetch usa job cuts macro data.
    pub async fn macro_usa_job_cuts(&self) -> Result<Vec<MacroDataPoint>> {
        self.us_job_cuts().await
    }

    /// Fetch usa non farm macro data.
    pub async fn macro_usa_non_farm(&self) -> Result<Vec<MacroDataPoint>> {
        self.us_non_farm().await
    }

    /// Fetch usa adp employment macro data.
    pub async fn macro_usa_adp_employment(&self) -> Result<Vec<MacroDataPoint>> {
        self.us_adp_employment().await
    }

    /// Fetch usa core pce price macro data.
    pub async fn macro_usa_core_pce_price(&self) -> Result<Vec<MacroDataPoint>> {
        self.us_core_pce_price().await
    }

    /// Fetch usa real consumer spending macro data.
    pub async fn macro_usa_real_consumer_spending(&self) -> Result<Vec<MacroDataPoint>> {
        self.us_real_consumer_spending().await
    }

    /// Fetch usa trade balance macro data.
    pub async fn macro_usa_trade_balance(&self) -> Result<Vec<MacroDataPoint>> {
        self.us_trade_balance().await
    }

    /// Fetch usa current account macro data.
    pub async fn macro_usa_current_account(&self) -> Result<Vec<MacroDataPoint>> {
        self.us_current_account().await
    }

    /// Fetch usa ppi macro data.
    pub async fn macro_usa_ppi(&self) -> Result<Vec<MacroDataPoint>> {
        self.us_ppi().await
    }

    /// Fetch usa core ppi macro data.
    pub async fn macro_usa_core_ppi(&self) -> Result<Vec<MacroDataPoint>> {
        self.us_core_ppi().await
    }

    /// Fetch usa api crude stock macro data.
    pub async fn macro_usa_api_crude_stock(&self) -> Result<Vec<MacroDataPoint>> {
        self.us_api_crude_stock().await
    }

    /// Fetch usa pmi macro data.
    pub async fn macro_usa_pmi(&self) -> Result<Vec<MacroDataPoint>> {
        self.us_pmi().await
    }

    /// Fetch usa ism pmi macro data.
    pub async fn macro_usa_ism_pmi(&self) -> Result<Vec<MacroDataPoint>> {
        self.us_ism_pmi().await
    }

    /// Fetch usa industrial production macro data.
    pub async fn macro_usa_industrial_production(&self) -> Result<Vec<MacroDataPoint>> {
        self.us_industrial_production().await
    }

    /// Fetch usa durable goods orders macro data.
    pub async fn macro_usa_durable_goods_orders(&self) -> Result<Vec<MacroDataPoint>> {
        self.us_durable_goods_orders().await
    }

    /// Fetch usa factory orders macro data.
    pub async fn macro_usa_factory_orders(&self) -> Result<Vec<MacroDataPoint>> {
        self.us_factory_orders().await
    }

    /// Fetch usa services pmi macro data.
    pub async fn macro_usa_services_pmi(&self) -> Result<Vec<MacroDataPoint>> {
        self.us_services_pmi().await
    }

    /// Fetch usa business inventories macro data.
    pub async fn macro_usa_business_inventories(&self) -> Result<Vec<MacroDataPoint>> {
        self.us_business_inventories().await
    }

    /// Fetch usa ism non pmi macro data.
    pub async fn macro_usa_ism_non_pmi(&self) -> Result<Vec<MacroDataPoint>> {
        self.us_ism_non_pmi().await
    }

    /// Fetch usa nahb house market index macro data.
    pub async fn macro_usa_nahb_house_market_index(&self) -> Result<Vec<MacroDataPoint>> {
        self.us_nahb_house_market_index().await
    }

    /// Fetch usa house starts macro data.
    pub async fn macro_usa_house_starts(&self) -> Result<Vec<MacroDataPoint>> {
        self.us_house_starts().await
    }

    /// Fetch usa new home sales macro data.
    pub async fn macro_usa_new_home_sales(&self) -> Result<Vec<MacroDataPoint>> {
        self.us_new_home_sales().await
    }

    /// Fetch usa building permits macro data.
    pub async fn macro_usa_building_permits(&self) -> Result<Vec<MacroDataPoint>> {
        self.us_building_permits().await
    }

    /// Fetch usa exist home sales macro data.
    pub async fn macro_usa_exist_home_sales(&self) -> Result<Vec<MacroDataPoint>> {
        self.us_exist_home_sales().await
    }

    /// Fetch usa house price index macro data.
    pub async fn macro_usa_house_price_index(&self) -> Result<Vec<MacroDataPoint>> {
        self.us_house_price_index().await
    }

    /// Fetch usa spcs20 macro data.
    pub async fn macro_usa_spcs20(&self) -> Result<Vec<MacroDataPoint>> {
        self.us_spcs20().await
    }

    /// Fetch usa pending home sales macro data.
    pub async fn macro_usa_pending_home_sales(&self) -> Result<Vec<MacroDataPoint>> {
        self.us_pending_home_sales().await
    }

    /// Fetch usa cb consumer confidence macro data.
    pub async fn macro_usa_cb_consumer_confidence(&self) -> Result<Vec<MacroDataPoint>> {
        self.us_cb_consumer_confidence().await
    }

    /// Fetch usa nfib small business macro data.
    pub async fn macro_usa_nfib_small_business(&self) -> Result<Vec<MacroDataPoint>> {
        self.us_nfib_small_business().await
    }

    /// Fetch usa michigan consumer sentiment macro data.
    pub async fn macro_usa_michigan_consumer_sentiment(&self) -> Result<Vec<MacroDataPoint>> {
        self.us_michigan_consumer_sentiment().await
    }

    /// Fetch usa eia crude rate macro data.
    pub async fn macro_usa_eia_crude_rate(&self) -> Result<Vec<MacroDataPoint>> {
        self.us_eia_crude_rate().await
    }

    /// Fetch usa initial jobless macro data.
    pub async fn macro_usa_initial_jobless(&self) -> Result<Vec<MacroDataPoint>> {
        self.us_initial_jobless().await
    }

    /// Fetch usa rig count macro data.
    pub async fn macro_usa_rig_count(&self) -> Result<Vec<MacroDataPoint>> {
        self.us_rig_count().await
    }

    /// Fetch usa cftc nc holding macro data.
    pub async fn macro_usa_cftc_nc_holding(&self) -> Result<Vec<MacroDataPoint>> {
        self.us_cftc_nc_holding().await
    }

    /// Fetch usa cftc c holding macro data.
    pub async fn macro_usa_cftc_c_holding(&self) -> Result<Vec<MacroDataPoint>> {
        self.us_cftc_c_holding().await
    }

    /// Fetch usa cftc merchant currency holding macro data.
    pub async fn macro_usa_cftc_merchant_currency_holding(&self) -> Result<Vec<MacroDataPoint>> {
        self.us_cftc_merchant_currency_holding().await
    }

    /// Fetch usa cftc merchant goods holding macro data.
    pub async fn macro_usa_cftc_merchant_goods_holding(&self) -> Result<Vec<MacroDataPoint>> {
        self.us_cftc_merchant_goods_holding().await
    }

    /// CME precious metals holding report (CME贵金属).
    pub async fn macro_usa_cme_merchant_goods_holding(&self) -> Result<Vec<MacroDataPoint>> {
        let url = "https://cdn.jin10.com/data_center/reports/cme_3.json";
        let resp: Jin10CdnResp = self.get(url).send().await?.json().await?;

        let values = resp.values.unwrap_or_default();
        let mut items = Vec::new();
        if let Some(obj) = values.as_object() {
            for (date, products) in obj {
                if let Some(arr) = products.as_array() {
                    for product in arr {
                        if let Some(parr) = product.as_array() {
                            let pz = parr.first().and_then(|v| v.as_str()).unwrap_or("");
                            let tc = parr.get(1).and_then(|v| v.as_str()).unwrap_or("");
                            // Column index 5 is volume
                            if let Some(vol) = parr.get(5).and_then(serde_json::Value::as_f64) {
                                items.push(MacroDataPoint {
                                    date: date.clone(),
                                    value: vol,
                                    name: format!("CME {pz}-{tc}"),
                                });
                            }
                        }
                    }
                }
            }
        }
        items.sort_by(|a, b| a.date.cmp(&b.date));
        Ok(items)
    }
}

// ---------------------------------------------------------------------------
// Jin10 CDN — CFTC data
// ---------------------------------------------------------------------------

#[derive(Debug, Deserialize)]
struct Jin10CftcResp {
    values: Option<serde_json::Value>,
}

/// Helper to fetch CFTC holding data from Jin10 CDN.
async fn fetch_cftc_holding(
    client: &AkShareClient,
    url: &str,
    name_label: &str,
) -> Result<Vec<MacroDataPoint>> {
    let resp: Jin10CftcResp = client.get(url).send().await?.json().await?;

    let values = resp.values.unwrap_or_default();
    let mut items = Vec::new();
    if let Some(obj) = values.as_object() {
        for (date, row) in obj {
            if let Some(cols) = row.as_object() {
                for (col_name, col_data) in cols {
                    if let Some(arr) = col_data.as_array()
                        && let Some(val) = arr.first().and_then(serde_json::Value::as_f64)
                    {
                        items.push(MacroDataPoint {
                            date: date.clone(),
                            value: val,
                            name: format!("{name_label} {col_name}"),
                        });
                    }
                }
            }
        }
    }
    items.sort_by(|a, b| a.date.cmp(&b.date));
    Ok(items)
}

impl AkShareClient {
    /// CFTC non-commercial holding report (CFTC外汇类非商业持仓报告).
    pub async fn us_cftc_nc_holding(&self) -> Result<Vec<MacroDataPoint>> {
        fetch_cftc_holding(
            self,
            "https://cdn.jin10.com/data_center/reports/cftc_4.json",
            "CFTC NC",
        )
        .await
    }

    /// CFTC commodity non-commercial holding report (CFTC商品类非商业持仓报告).
    pub async fn us_cftc_c_holding(&self) -> Result<Vec<MacroDataPoint>> {
        fetch_cftc_holding(
            self,
            "https://cdn.jin10.com/data_center/reports/cftc_2.json",
            "CFTC C",
        )
        .await
    }

    /// CFTC merchant currency holding report (CFTC外汇类商业持仓报告).
    pub async fn us_cftc_merchant_currency_holding(&self) -> Result<Vec<MacroDataPoint>> {
        fetch_cftc_holding(
            self,
            "https://cdn.jin10.com/data_center/reports/cftc_3.json",
            "CFTC Merchant Currency",
        )
        .await
    }

    /// CFTC merchant goods holding report (CFTC商品类商业持仓报告).
    pub async fn us_cftc_merchant_goods_holding(&self) -> Result<Vec<MacroDataPoint>> {
        fetch_cftc_holding(
            self,
            "https://cdn.jin10.com/data_center/reports/cftc_1.json",
            "CFTC Merchant Goods",
        )
        .await
    }
}