Skip to content

请问一下,我这里为什么会发生程序恐慌? #34

Description

@amazcuter

不确定是不是IP地址的问题,如果是IP地址的问题,请教我如何正确使用。
或者是我使用的问题,如果是,请告诉我正确的使用方法。

#[allow(unused_imports)]
use rustdx::tcp::{ip::STOCK_IP, tcpstream_ip};
#[allow(unused_imports)]
use rustdx::tcp::{
    stock::{Kline, Xdxr},
    SecurityList, Tcp, Tdx,
};

fn main() -> Result<(), Box<dyn std::error::Error>> {

    // // 创建一个新的 TCP 连接,默认连接到第一个可用的 IP 地址
    // let mut api = Tcp::new()?;

    // 指定 IP 地址链接
    let mut api = Tcp::new_with_ip(&"175.178.128.227:7709".parse().unwrap())?;

    // 创建一个查询股票列表的请求
    // 这里使用 market=0 就没问题,1 就会发生程序恐慌,恐慌发生在解析获得的内容的那一步
    let mut security_list = SecurityList::new(1, 0);

    // 发送请求并解析响应
    let result = security_list.recv_parsed(&mut api)?;   //在这里会调用恐慌的代码,似乎是回复的头的问题
    for stock in result {
        println!("Code: {}, Name: {}", stock.code, stock.name);
    }

    // // 创建一个查询深市股票 000001 日线数据的请求
    // let mut kline = Kline::new(0, "000004", 9, 0, 3);

    // // kline.market(1);
    // kline.code("000002");

    // // 发送请求并解析响应
    // let result = kline.recv_parsed(&mut api)?;
    // for kline_data in result {
    //     println!("Date: {}, Open: {}, Close: {}, High: {}, Low: {}, Vol: {}, Amount: {}",
    //              kline_data.dt.clone().into_string(9), kline_data.open, kline_data.close, kline_data.high, kline_data.low, kline_data.vol, kline_data.amount);
    // }

    // // 创建一个 Xdxr 实例,并设置市场和股票代码
    // let mut xdxr = Xdxr {
    //     market: 1, // 0 表示上海市场,1 表示深圳市场
    //     code: "600000", // 股票代码
    //     ..Default::default()
    // };
    // println!("{:?}",xdxr);

    // // 发送请求并解析响应
    // xdxr.recv_parsed(&mut api)?;
    // for xdxr_data in xdxr.result() {
    //     println!("Date: {}, Category: {}, FH_QLTP: {}, PGJ_QZGB: {}, SG_HLTP: {}, PG_HZGB: {}",
    //              xdxr_data.date, xdxr_data.category, xdxr_data.fh_qltp, xdxr_data.pgj_qzgb, xdxr_data.sg_hltp, xdxr_data.pg_hzgb);
    // }
    Ok(())
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions