jqdata_model/
models.rs

1use serde_derive::*;
2use serde::Deserialize;
3use jqdata_derive::*;
4use bigdecimal::BigDecimal;
5use std::io::Read;
6use crate::{Result, Error};
7
8/// Request
9/// 
10/// Generic request for all JQData APIs,
11/// uses serde flatten attribute to construct
12/// plain json with different fields.
13/// common fields are "token" and "method".
14/// specific ones are all passed by payload field.
15#[derive(Debug, Serialize, Deserialize)]
16pub struct Request<P> {
17    token: String,
18    method: String,
19    #[serde(flatten)]
20    payload: P,
21}
22
23/// helper trait to expose API method for each request,
24/// used by jqdata-derive crate
25pub trait HasMethod {
26    fn method(&self) -> String;
27}
28
29impl<P: HasMethod> Request<P> {
30    pub fn new(token: String, payload: P) -> Self {
31        Request{
32            token,
33            method: payload.method(),
34            payload,
35        }
36    }
37}
38
39/// helper trait to consume response body and construct
40/// the result
41pub trait BodyConsumer<T> 
42where for<'de> T: Deserialize<'de>
43{
44    fn consume_body<R: Read>(body: R) -> Result<T>;
45}
46
47/// consume body as csv
48/// used by jqdata-derive crate
49pub trait CsvListBodyConsumer {
50    type Output: for<'de> Deserialize<'de>;
51
52    fn consume<R: Read>(body: R) -> Result<Vec<Self::Output>> {
53        let mut reader = csv::ReaderBuilder::new()
54        // .has_headers(true)
55        .from_reader(body);
56        // consume the first row as header
57        let header_cols: Vec<&str> = reader.headers()?.into_iter().collect();
58        if header_cols.is_empty() {
59            return Err(Error::Server("empty response body returned".to_owned()));
60        }
61        let first_col = header_cols.first().cloned().unwrap();
62        if first_col.starts_with("error") {
63            return Err(Error::Server(first_col.to_owned()));
64        }
65        let mut rs = Vec::new();
66        for r in reader.deserialize() {
67            let s: Self::Output = r?;
68            rs.push(s);
69        }
70        Ok(rs)
71    }
72}
73
74/// consume body as lines
75/// used by jqdata-derive crate
76pub trait LineBodyConsumer {
77    fn consume<R: Read>(body: R) -> Result<Vec<String>> {
78        use std::io::BufRead;
79        let reader = std::io::BufReader::new(body);
80        let mut rs = Vec::new();
81        for line in reader.lines() {
82            rs.push(line?);
83        }
84        Ok(rs)
85    }
86}
87
88/// consume body as single result
89/// used by jqdata-derive crate
90pub trait SingleBodyConsumer<T> where T: std::str::FromStr, Error: From<T::Err> {
91    fn consume<R: Read>(body: R) -> Result<T> {
92        let mut body = body;
93        let mut vec = Vec::new();
94        std::io::copy(&mut body, &mut vec)?;
95        let s = String::from_utf8(vec)?;
96        let result = s.parse()?;
97        Ok(result)
98    }
99}
100
101/// consume body as json
102/// used by jqdata-derive crate
103pub trait JsonBodyConsumer {
104    type Output: for<'de> Deserialize<'de>;
105
106    fn consume<R: Read>(body: R) -> Result<Self::Output> {
107        let result = serde_json::from_reader(body)?;
108        Ok(result)
109    }
110}
111
112/// 证券类型
113#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
114#[serde(rename_all = "snake_case")]
115pub enum SecurityKind {
116    Stock,
117    Fund,
118    Index,
119    Futures,
120    #[serde(rename = "etf")]
121    ETF,
122    #[serde(rename = "lof")]
123    LOF,
124    #[serde(rename = "fja")]
125    FJA,
126    #[serde(rename = "fjb")]
127    FJB,
128    #[serde(rename = "QDII_fund")]
129    QDIIFund,
130    OpenFund,
131    BondFund,
132    StockFund,
133    MoneyMarketFund,
134    MixtureFund,
135    Options,
136}
137
138/// 证券信息
139#[derive(Debug, Serialize, Deserialize, PartialEq)]
140pub struct Security {
141    pub code: String,
142    pub display_name: String,
143    pub name: String,
144    pub start_date: String,
145    pub end_date: String,
146    #[serde(rename = "type")]
147    pub kind: SecurityKind,
148    #[serde(skip_serializing_if = "Option::is_none")]
149    pub parent: Option<String>,
150}
151
152/// 获取平台支持的所有股票、基金、指数、期货信息
153#[derive(Debug, Serialize, Deserialize, Jqdata)]
154#[method("get_all_securities")]
155#[consume(format = "csv", type = "Security")]
156pub struct GetAllSecurities {
157    pub code: SecurityKind,
158    #[serde(skip_serializing_if = "Option::is_none")]
159    pub date: Option<String>,
160}
161
162/// 获取股票/基金/指数的信息
163#[derive(Debug, Serialize, Deserialize, Jqdata)]
164#[method("get_security_info")]
165#[consume(format = "csv", type = "Security")]
166pub struct GetSecurityInfo {
167    pub code: String,
168}
169
170/// 获取一个指数给定日期在平台可交易的成分股列表
171#[derive(Debug, Serialize, Deserialize, Jqdata)]
172#[method("get_index_stocks")]
173#[consume(format = "line")]
174pub struct GetIndexStocks {
175    pub code: String,
176    pub date: String,
177}
178
179/// 获取指定日期上交所、深交所披露的的可融资标的列表
180/// 查询日期,默认为前一交易日
181#[derive(Debug, Serialize, Deserialize, Jqdata)]
182#[method("get_margincash_stocks")]
183#[consume(format = "line")]
184pub struct GetMargincashStocks {
185    #[serde(skip_serializing_if = "Option::is_none")]
186    pub date: Option<String>,
187}
188
189/// 获取指定日期区间内的限售解禁数据
190#[derive(Debug, Serialize, Deserialize, Jqdata)]
191#[method("get_locked_shares")]
192#[consume(format = "csv", type = "LockedShare")]
193pub struct GetLockedShares {
194    pub code: String,
195    pub date: String,
196    pub end_date: String,
197}
198
199#[derive(Debug, Serialize, Deserialize)]
200pub struct LockedShare {
201    pub day: String,
202    pub code: String,
203    pub num: BigDecimal,
204    pub rate1: BigDecimal,
205    pub rate2: BigDecimal,
206}
207
208/// 获取指数成份股给定日期的权重数据,每月更新一次
209/// code: 代表指数的标准形式代码, 形式:指数代码.交易所代码,例如"000001.XSHG"。
210/// date: 查询权重信息的日期,形式:"%Y-%m-%d",例如"2018-05-03";
211#[derive(Debug, Serialize, Deserialize, Jqdata)]
212#[method("get_index_weights")]
213#[consume(format = "csv", type = "IndexWeight")]
214pub struct GetIndexWeights {
215    pub code: String,
216    pub date: String,
217}
218
219#[derive(Debug, Serialize, Deserialize)]
220pub struct IndexWeight {
221    pub code: String,
222    pub display_name: String,
223    pub date: String,
224    pub weight: BigDecimal,
225}
226
227/// 按照行业分类获取行业列表
228/// code:行业代码
229/// sw_l1: 申万一级行业
230/// sw_l2: 申万二级行业
231/// sw_l3: 申万三级行业
232/// jq_l1: 聚宽一级行业
233/// jq_l2: 聚宽二级行业
234/// zjw: 证监会行业
235#[derive(Debug, Serialize, Deserialize, Jqdata)]
236#[method("get_industries")]
237#[consume(format = "csv", type = "IndustryIndex")]
238pub struct GetIndustries {
239    pub code: String,
240}
241
242#[derive(Debug, Serialize, Deserialize)]
243pub struct IndustryIndex {
244    pub index: String,
245    pub name: String,
246    pub start_date: String,
247}
248
249/// 查询股票所属行业
250/// 参数:
251/// code:证券代码
252/// date:查询的日期
253#[derive(Debug, Serialize, Deserialize, Jqdata)]
254#[method("get_industry")]
255#[consume(format = "csv", type = "Industry")]
256pub struct GetIndustry {
257    pub code: String,
258    pub date: String,
259}
260
261#[derive(Debug, Serialize, Deserialize)]
262pub struct Industry {
263    pub industry: String,
264    pub industry_code: String,
265    pub industry_name: String,
266}
267
268/// 获取在给定日期一个行业的所有股票
269/// 参数:
270/// code: 行业编码
271/// date: 查询日期
272#[derive(Debug, Serialize, Deserialize, Jqdata)]
273#[method("get_industry_stocks")]
274#[consume(format = "line")]
275pub struct GetIndustryStocks {
276    pub code: String,
277    pub date: String,
278}
279
280/// 获取在给定日期一个概念板块的所有股票
281/// 参数:
282/// code: 概念板块编码
283/// date: 查询日期,
284#[derive(Debug, Serialize, Deserialize, Jqdata)]
285#[method("get_concepts")]
286#[consume(format = "csv", type = "Concept")]
287pub struct GetConcepts {}
288
289#[derive(Debug, Serialize, Deserialize)]
290pub struct Concept {
291    pub code: String,
292    pub name: String,
293    pub start_date: String,
294}
295
296/// 获取在给定日期一个概念板块的所有股票
297/// 参数:
298/// code: 概念板块编码
299/// date: 查询日期,
300#[derive(Debug, Serialize, Deserialize, Jqdata)]
301#[method("get_concept_stocks")]
302#[consume(format = "line")]
303pub struct GetConceptStocks {
304    pub code: String,
305    pub date: String,
306}
307
308/// 获取指定日期范围内的所有交易日
309/// 参数:
310/// date: 开始日期
311/// end_date: 结束日期
312#[derive(Debug, Serialize, Deserialize, Jqdata)]
313#[method("get_trade_days")]
314#[consume(format = "line")]
315pub struct GetTradeDays {
316    pub date: String,
317    #[serde(skip_serializing_if = "Option::is_none")]
318    pub end_date: Option<String>,
319}
320
321/// 获取所有交易日
322#[derive(Debug, Serialize, Deserialize, Jqdata)]
323#[method("get_all_trade_days")]
324#[consume(format = "line")]
325pub struct GetAllTradeDays {}
326
327/// 获取一只股票在一个时间段内的融资融券信息
328/// 参数:
329/// code: 股票代码
330/// date: 开始日期
331/// end_date: 结束日期
332/// 返回:
333/// date: 日期
334/// sec_code: 股票代码
335/// fin_value: 融资余额(元)
336/// fin_buy_value: 融资买入额(元)
337/// fin_refund_value: 融资偿还额(元)
338/// sec_value: 融券余量(股)
339/// sec_sell_value: 融券卖出量(股)
340/// sec_refund_value: 融券偿还量(股)
341/// fin_sec_value: 融资融券余额(元)
342#[derive(Debug, Serialize, Deserialize, Jqdata)]
343#[method("get_mtss")]
344#[consume(format = "csv", type = "Mtss")]
345pub struct GetMtss {
346    pub code: String,
347    pub date: String,
348    pub end_date: String,
349}
350
351#[derive(Debug, Serialize, Deserialize)]
352pub struct Mtss {
353    pub date: String,
354    pub sec_code: String,
355    pub fin_value: BigDecimal,
356    pub fin_refund_value: BigDecimal,
357    pub sec_value: BigDecimal,
358    pub sec_sell_value: BigDecimal,
359    pub sec_refund_value: BigDecimal,
360    pub fin_sec_value: BigDecimal,
361}
362
363/// 获取一只股票在一个时间段内的资金流向数据,仅包含股票数据,不可用于获取期货数据
364/// 参数:
365/// code: 股票代码
366/// date: 开始日期
367/// end_date: 结束日期
368/// 返回:
369/// date: 日期
370/// sec_code: 股票代码
371/// change_pct: 涨跌幅(%)
372/// net_amount_main: 主力净额(万): 主力净额 = 超大单净额 + 大单净额
373/// net_pct_main: 主力净占比(%): 主力净占比 = 主力净额 / 成交额
374/// net_amount_xl: 超大单净额(万): 超大单:大于等于50万股或者100万元的成交单
375/// net_pct_xl: 超大单净占比(%): 超大单净占比 = 超大单净额 / 成交额
376/// net_amount_l: 大单净额(万): 大单:大于等于10万股或者20万元且小于50万股或者100万元的成交单
377/// net_pct_l: 大单净占比(%): 大单净占比 = 大单净额 / 成交额
378/// net_amount_m: 中单净额(万): 中单:大于等于2万股或者4万元且小于10万股或者20万元的成交单
379/// net_pct_m: 中单净占比(%): 中单净占比 = 中单净额 / 成交额
380/// net_amount_s: 小单净额(万): 小单:小于2万股或者4万元的成交单
381/// net_pct_s: 小单净占比(%): 小单净占比 = 小单净额 / 成交额
382#[derive(Debug, Serialize, Deserialize, Jqdata)]
383#[method("get_money_flow")]
384#[consume(format = "csv", type = "MoneyFlow")]
385pub struct GetMoneyFlow {
386    pub code: String,
387    pub date: String,
388    pub end_date: String,
389}
390
391#[derive(Debug, Serialize, Deserialize)]
392pub struct MoneyFlow {
393    pub date: String,
394    pub sec_code: String,
395    pub change_pct: BigDecimal,
396    pub net_amount_main: BigDecimal,
397    pub net_pct_main: BigDecimal,
398    pub net_amount_xl: BigDecimal,
399    pub net_pct_xl: BigDecimal,
400    pub net_amount_l: BigDecimal,
401    pub net_pct_l: BigDecimal,
402    pub net_amount_m: BigDecimal,
403    pub net_pct_m: BigDecimal,
404    pub net_amount_s: BigDecimal,
405    pub net_pct_s: BigDecimal,
406}
407
408/// 获取指定日期区间内的龙虎榜数据
409/// 参数:
410/// code: 股票代码
411/// date: 开始日期
412/// end_date: 结束日期
413/// 返回:
414/// code: 股票代码
415/// day: 日期
416/// direction: ALL 表示『汇总』,SELL 表示『卖』,BUY 表示『买』
417/// abnormal_code: 异常波动类型
418/// abnormal_name: 异常波动名称
419/// sales_depart_name: 营业部名称
420/// rank: 0 表示汇总, 1~5 表示买一到买五, 6~10 表示卖一到卖五
421/// buy_value: 买入金额
422/// buy_rate: 买入金额占比(买入金额/市场总成交额)
423/// sell_value: 卖出金额
424/// sell_rate: 卖出金额占比(卖出金额/市场总成交额)
425/// net_value: 净额(买入金额 - 卖出金额)
426/// amount: 市场总成交额
427#[derive(Debug, Serialize, Deserialize, Jqdata)]
428#[method("get_billboard_list")]
429#[consume(format = "csv", type = "BillboardStock")]
430pub struct GetBillboardList {
431    pub code: String,
432    pub date: String,
433    pub end_date: String,
434}
435
436#[derive(Debug, Serialize, Deserialize)]
437pub struct BillboardStock {
438    pub code: String,
439    pub day: String,
440    pub direction: String,
441    pub rank: i32,
442    pub abnormal_code: String,
443    pub abnormal_name: String,
444    pub sales_depart_name: String,
445    pub buy_value: BigDecimal,
446    pub buy_rate: BigDecimal,
447    pub sell_value: BigDecimal,
448    pub sell_rate: BigDecimal,
449    pub total_value: BigDecimal,
450    pub net_value: BigDecimal,
451    pub amount: BigDecimal,
452}
453
454/// 获取某期货品种在指定日期下的可交易合约标的列表
455/// 参数:
456/// code: 期货合约品种,如 AG (白银)
457/// date: 指定日期
458#[derive(Debug, Serialize, Deserialize, Jqdata)]
459#[method("get_future_contracts")]
460#[consume(format = "line")]
461pub struct GetFutureContracts {
462    pub code: String,
463    pub date: String,
464}
465
466/// 获取主力合约对应的标的
467/// 参数:
468/// code: 期货合约品种,如 AG (白银)
469/// date: 指定日期参数,获取历史上该日期的主力期货合约
470#[derive(Debug, Serialize, Deserialize, Jqdata)]
471#[method("get_dominant_future")]
472#[consume(format = "line")]
473pub struct GetDominantFuture {
474    pub code: String,
475    pub date: String,
476}
477
478/// 获取单个基金的基本信息
479/// 参数:
480/// code: 基金代码
481/// date: 查询日期, 默认日期是今天。
482/// 返回:
483/// fund_name: 基金全称
484/// fund_type: 基金类型
485/// fund_establishment_day: 基金成立日
486/// fund_manager: 基金管理人及基本信息
487/// fund_management_fee: 基金管理费
488/// fund_custodian_fee: 基金托管费
489/// fund_status: 基金申购赎回状态
490/// fund_size: 基金规模(季度)
491/// fund_share: 基金份额(季度)
492/// fund_asset_allocation_proportion: 基金资产配置比例(季度)
493/// heavy_hold_stocks: 基金重仓股(季度)
494/// heavy_hold_stocks_proportion: 基金重仓股占基金资产净值比例(季度)
495/// heavy_hold_bond: 基金重仓债券(季度)
496/// heavy_hold_bond_proportion: 基金重仓债券占基金资产净值比例(季度)
497#[derive(Debug, Serialize, Deserialize, Jqdata)]
498#[method("get_fund_info")]
499#[consume(format = "json", type = "FundInfo")]
500pub struct GetFundInfo {
501    pub code: String,
502    pub date: String,
503}
504
505#[derive(Debug, Serialize, Deserialize)]
506pub struct FundInfo {
507    pub fund_name: String,
508    pub fund_type: String,
509    pub fund_establishment_day: String,
510    pub fund_manager: String,
511    pub fund_management_fee: String,
512    pub fund_custodian_fee: String,
513    pub fund_status: String,
514    pub fund_size: String,
515    pub fund_share: BigDecimal,
516    pub fund_asset_allocation_proportion: String,
517    pub heavy_hold_stocks: Vec<String>,
518    pub heavy_hold_stocks_proportion: BigDecimal,
519    pub heavy_hold_bond: Vec<String>,
520    pub heavy_hold_bond_proportion: BigDecimal,
521}
522
523/// 获取最新的 tick 数据
524/// 参数:
525/// code: 标的代码, 支持股票、指数、基金、期货等。 不可以使用主力合约和指数合约代码。
526/// 返回:
527/// time: 时间
528/// current: 当前价
529/// high: 截至到当前时刻的日内最高价
530/// low: 截至到当前时刻的日内最低价
531/// volume: 累计成交量
532/// money: 累计成交额
533/// position: 持仓量,期货使用
534/// a1_v~a5_v: 五档卖量
535/// a1_p~a5_p: 五档卖价
536/// b1_v~b5_v: 五档买量
537/// b1_p~b5_p: 五档买价
538#[derive(Debug, Serialize, Deserialize, Jqdata)]
539#[method("get_current_tick")]
540#[consume(format = "csv", type = "Tick")]
541pub struct GetCurrentTick {
542    pub code: String,
543}
544
545#[derive(Debug, Serialize, Deserialize)]
546pub struct Tick {
547    pub time: BigDecimal,
548    pub current: BigDecimal,
549    pub high: BigDecimal,
550    pub low: BigDecimal,
551    pub volumn: BigDecimal,
552    pub money: BigDecimal,
553    pub position: BigDecimal,
554    pub a1_v: BigDecimal,
555    pub a2_v: BigDecimal,
556    pub a3_v: BigDecimal,
557    pub a4_v: BigDecimal,
558    pub a5_v: BigDecimal,
559    pub a1_p: BigDecimal,
560    pub a2_p: BigDecimal,
561    pub a3_p: BigDecimal,
562    pub a4_p: BigDecimal,
563    pub a5_p: BigDecimal,
564    pub b1_v: BigDecimal,
565    pub b2_v: BigDecimal,
566    pub b3_v: BigDecimal,
567    pub b4_v: BigDecimal,
568    pub b5_v: BigDecimal,
569    pub b1_p: BigDecimal,
570    pub b2_p: BigDecimal,
571    pub b3_p: BigDecimal,
572    pub b4_p: BigDecimal,
573    pub b5_p: BigDecimal,
574}
575
576/// 获取多标的最新的 tick 数据
577/// 参数:
578/// code: 标的代码, 多个标的使用,分隔。每次请求的标的必须是相同类型。标的类型包括: 股票、指数、场内基金、期货、期权
579#[derive(Debug, Serialize, Deserialize, Jqdata)]
580#[method("get_current_ticks")]
581#[consume(format = "csv", type = "Tick")]
582pub struct GetCurrentTicks {
583    pub code: String,
584}
585
586/// 获取基金净值/期货结算价等
587/// 参数:
588/// code: 证券代码
589/// date: 开始日期
590/// end_date: 结束日期
591/// 返回:
592/// date: 日期
593/// is_st: 是否是ST,是则返回 1,否则返回 0。股票使用
594/// acc_net_value: 基金累计净值。基金使用
595/// unit_net_value: 基金单位净值。基金使用
596/// futures_sett_price: 期货结算价。期货使用
597/// futures_positions: 期货持仓量。期货使用
598/// adj_net_value: 场外基金的复权净值。场外基金使用
599#[derive(Debug, Serialize, Deserialize, Jqdata)]
600#[method("get_extras")]
601#[consume(format = "csv", type = "Extra")]
602pub struct GetExtras {
603    pub code: String,
604    pub date: String,
605    pub end_date: String,
606}
607
608#[derive(Debug, Serialize, Deserialize)]
609pub struct Extra {
610    pub date: String,
611    pub is_st: Option<i8>,
612    pub acc_net_value: Option<f64>,
613    pub unit_net_value: Option<f64>,
614    pub futures_sett_price: Option<f64>,
615    pub futures_positions: Option<f64>,
616    pub adj_net_value: Option<f64>,
617}
618
619/// 获取各种时间周期的bar数据,bar的分割方式与主流股票软件相同, 同时还支持返回当前时刻所在 bar 的数据。get_price 与 get_bars 合并为一个函数
620/// 参数:
621/// code: 证券代码
622/// count: 大于0的整数,表示获取bar的条数,不能超过5000
623/// unit: bar的时间单位, 支持如下周期:1m, 5m, 15m, 30m, 60m, 120m, 1d, 1w, 1M。其中m表示分钟,d表示天,w表示周,M表示月
624/// end_date:查询的截止时间,默认是今天
625/// fq_ref_date:复权基准日期,该参数为空时返回不复权数据
626/// 返回:
627/// date: 日期
628/// open: 开盘价
629/// close: 收盘价
630/// high: 最高价
631/// low: 最低价
632/// volume: 成交量
633/// money: 成交额
634/// 当unit为1d时,包含以下返回值:
635/// paused: 是否停牌,0 正常;1 停牌
636/// high_limit: 涨停价
637/// low_limit: 跌停价
638/// avg: 当天均价
639/// pre_close:前收价
640/// 当code为期货和期权时,包含以下返回值:
641/// open_interest 持仓量
642#[derive(Debug, Serialize, Deserialize, Jqdata)]
643#[method("get_price")]
644#[consume(format = "csv", type = "Price")]
645pub struct GetPrice {
646    pub date: String,
647    pub count: u32,
648    pub unit: String,
649    #[serde(skip_serializing_if = "Option::is_none")]
650    pub end_date: Option<String>,
651    #[serde(skip_serializing_if = "Option::is_none")]
652    pub fq_ref_date: Option<String>,
653}
654
655#[derive(Debug, Serialize, Deserialize)]
656pub struct Price {
657    pub date: String,
658    pub open: BigDecimal,
659    pub close: BigDecimal,
660    pub high: BigDecimal,
661    pub low: BigDecimal,
662    pub volume: BigDecimal,
663    pub money: BigDecimal,
664    pub paused: Option<u8>,
665    pub high_limit: Option<f64>,
666    pub low_limit: Option<f64>,
667    pub avg: Option<f64>,
668    pub pre_close: Option<f64>,
669    pub open_interest: Option<f64>,
670}
671
672/// 指定开始时间date和结束时间end_date时间段,获取行情数据
673/// 参数:
674/// code: 证券代码
675/// unit: bar的时间单位, 支持如下周期:1m, 5m, 15m, 30m, 60m, 120m, 1d, 1w, 1M。其中m表示分钟,d表示天,w表示周,M表示月
676/// date: 开始时间,不能为空,格式2018-07-03或2018-07-03 10:40:00,如果是2018-07-03则默认为2018-07-03 00:00:00
677/// end_date:结束时间,不能为空,格式2018-07-03或2018-07-03 10:40:00,如果是2018-07-03则默认为2018-07-03 23:59:00
678/// fq_ref_date:复权基准日期,该参数为空时返回不复权数据
679/// 注:当unit是1w或1M时,第一条数据是开始时间date所在的周或月的行情。当unit为分钟时,第一条数据是开始时间date所在的一个unit切片的行情。
680/// 最大获取1000个交易日数据
681/// 返回:
682/// date: 日期
683/// open: 开盘价
684/// close: 收盘价
685/// high: 最高价
686/// low: 最低价
687/// volume: 成交量
688/// money: 成交额
689/// 当unit为1d时,包含以下返回值:
690/// paused: 是否停牌,0 正常;1 停牌
691/// high_limit: 涨停价
692/// low_limit: 跌停价
693/// 当code为期货和期权时,包含以下返回值:
694/// open_interest 持仓量
695#[derive(Debug, Serialize, Deserialize, Jqdata)]
696#[method("get_price_period")]
697#[consume(format = "csv", type = "Price")]
698pub struct GetPricePeriod {
699    pub code: String,
700    pub unit: String,
701    pub date: String,
702    pub end_date: String,
703    #[serde(skip_serializing_if = "Option::is_none")]
704    pub fq_ref_date: Option<String>,
705}
706
707/// 获取tick数据
708/// 股票部分, 支持 2010-01-01 至今的tick数据,提供买五卖五数据
709/// 期货部分, 支持 2010-01-01 至今的tick数据,提供买一卖一数据。 如果要获取主力合约的tick数据,可以先使用get_dominant_future获取主力合约对应的标的
710/// 期权部分,支持 2017-01-01 至今的tick数据,提供买五卖五数据
711/// 参数:
712/// code: 证券代码
713/// count: 取出指定时间区间内前多少条的tick数据,如不填count,则返回end_date一天内的全部tick
714/// end_date: 结束日期,格式2018-07-03或2018-07-03 10:40:00
715/// skip: 默认为true,过滤掉无成交变化的tick数据;
716/// 当skip=false时,返回的tick数据会保留从2019年6月25日以来无成交有盘口变化的tick数据。
717/// 由于期权成交频率低,所以建议请求期权数据时skip设为false
718#[derive(Debug, Serialize, Deserialize, Jqdata)]
719#[method("get_ticks")]
720#[consume(format = "csv", type = "Tick")]
721pub struct GetTicks {
722    pub code: String,
723    #[serde(skip_serializing_if = "Option::is_none")]
724    pub count: Option<u32>,
725    pub end_date: String,
726    pub skip: bool,
727}
728
729/// 按时间段获取tick数据
730/// 股票部分, 支持 2010-01-01 至今的tick数据,提供买五卖五数据
731/// 期货部分, 支持 2010-01-01 至今的tick数据,提供买一卖一数据。 如果要获取主力合约的tick数据,可以先使用get_dominant_future获取主力合约对应的标的
732/// 期权部分,支持 2017-01-01 至今的tick数据,提供买五卖五数据
733/// 参数:
734/// code: 证券代码
735/// date: 开始时间,格式2018-07-03或2018-07-03 10:40:00
736/// end_date: 结束时间,格式2018-07-03或2018-07-03 10:40:00
737/// skip: 默认为true,过滤掉无成交变化的tick数据;
738/// 当skip=false时,返回的tick数据会保留从2019年6月25日以来无成交有盘口变化的tick数据。
739/// 注:
740/// 如果时间跨度太大、数据量太多则可能导致请求超时,所有请控制好data-end_date之间的间隔!
741#[derive(Debug, Serialize, Deserialize, Jqdata)]
742#[method("get_ticks_period")]
743#[consume(format = "csv", type = "Tick")]
744pub struct GetTicksPeriod {
745    pub code: String,
746    pub date: String,
747    pub end_date: String,
748    pub skip: bool,
749}
750
751/// 获取因子值的 API,点击查看因子列表
752/// 参数:
753/// code: 单只股票代码
754/// columns: 因子名称,因子名称,多个因子用逗号分隔
755/// date: 开始日期
756/// end_date: 结束日期
757/// 返回:
758/// date:日期
759/// 查询因子值
760/// 注:
761/// 为保证数据的连续性,所有数据基于后复权计算
762/// 为了防止单次返回数据时间过长,尽量较少查询的因子数和时间段
763/// 如果第一次请求超时,尝试重试
764#[derive(Debug, Serialize, Deserialize, Jqdata)]
765#[method("get_factor_values")]
766#[consume(format = "csv", type = "FactorValue")]
767pub struct GetFactorValues {
768    pub code: String,
769    pub columns: String,
770    pub date: String,
771    pub end_date: String,
772}
773
774#[derive(Debug, Serialize, Deserialize)]
775pub struct FactorValue {
776    pub date: String,
777    pub cfo_to_ev: Option<f64>,
778    pub net_profit_ratio: Option<f64>,
779}
780
781/// 模拟JQDataSDK的run_query方法
782/// run_query api 是模拟了JQDataSDK run_query方法获取财务、宏观、期权等数据
783/// 可查询的数据内容请查看JQData文档
784/// 以查询上市公司分红送股(除权除息)数据为例:
785/// 参数:
786/// table: 要查询的数据库和表名,格式为 database + . + tablename 如finance.STK_XR_XD
787/// columns: 所查字段,为空时则查询所有字段,多个字段中间用,分隔。如id,company_id,columns不能有空格等特殊字符
788/// conditions: 查询条件,可以为空,格式为report_date#>=#2006-12-01&report_date#<=#2006-12-31,条件内部#号分隔,格式: column # 判断符 # value,多个条件使用&号分隔,表示and,conditions不能有空格等特殊字符
789/// count: 查询条数,count为空时默认1条,最多查询1000条
790#[derive(Debug, Serialize, Deserialize, Jqdata)]
791#[method(run_query)]
792#[consume(format = "line")]
793pub struct RunQuery {
794    pub table: String,
795    pub columns: String,
796    #[serde(skip_serializing_if = "Option::is_none")]
797    pub conditions: Option<String>,
798    #[serde(skip_serializing_if = "Option::is_none")]
799    pub count: Option<u32>,
800}
801
802/// 获取查询剩余条数
803#[derive(Debug, Serialize, Deserialize, Jqdata)]
804#[method("get_query_count")]
805#[consume(format = "single", type = "i32")]
806pub struct GetQueryCount {}