use crate::encoding::GbkConverter;
use crate::error::CtpResult;
pub type TraderIdType = [u8; 21];
pub type InvestorIdType = [u8; 13];
pub type BrokerIdType = [u8; 11];
pub type BrokerAbbrType = [u8; 9];
pub type BrokerNameType = [u8; 81];
pub type InstrumentIdType = [u8; 31];
pub type PasswordType = [u8; 41];
pub type UserIdType = [u8; 16];
pub type ProductInfoType = [u8; 11];
pub type CurrencyIdType = [u8; 4];
pub type BizTypeType = [u8; 1];
pub type AccountIdType = [u8; 13];
pub type ExchangeIdType = [u8; 9];
pub type InvestUnitIdType = [u8; 17];
pub type ProtocolInfoType = [u8; 11];
pub type MacAddressType = [u8; 21];
pub type AuthCodeType = [u8; 17];
pub type AppIdType = [u8; 21];
pub type IpAddressType = [u8; 16];
pub type IpPortType = [u8; 6];
pub type OrderSysIdType = [u8; 21];
pub type TimeType = [u8; 9];
pub type TradeIdType = [u8; 21];
pub type ExchangeInstIdType = [u8; 31];
pub type OrderActionRefType = [u8; 13];
pub type ActionFlagType = u8;
pub type IPAddressType = [u8; 16];
pub type OrderRefType = [u8; 13];
pub type RequestIdType = i32;
pub type FrontIdType = i32;
pub type SessionIdType = i32;
pub type BusinessUnitType = [u8; 21];
pub type ClientIdType = [u8; 11];
pub type ParkedOrderIdType = [u8; 13];
pub type TradingDayType = [u8; 9];
pub type BankIdType = [u8; 4];
pub type BankBrchIdType = [u8; 5];
pub type BankNameType = [u8; 101];
pub type PriceType = f64;
pub type DateType = [u8; 9];
pub type InstallIdType = i32;
pub type OrderLocalIdType = [u8; 13];
pub type ParticipantIdType = [u8; 11];
pub type OrderActionStatusType = u8;
pub type ErrorMsgType = [u8; 81];
pub type BranchIdType = [u8; 9];
pub type VolumeType = i32;
#[repr(C)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ResumeType {
Restart = 0,
Resume = 1,
Quick = 2,
None = 3,
}
impl Default for ResumeType {
fn default() -> Self {
ResumeType::Restart
}
}
pub trait StringConvert {
fn to_utf8_string(&self) -> CtpResult<String>;
fn from_utf8_string(s: &str) -> CtpResult<Self>
where
Self: Sized;
}
macro_rules! impl_string_convert {
($type:ty, $size:expr) => {
impl StringConvert for $type {
fn to_utf8_string(&self) -> CtpResult<String> {
GbkConverter::fixed_bytes_to_utf8(self)
}
fn from_utf8_string(s: &str) -> CtpResult<Self> {
GbkConverter::utf8_to_fixed_bytes::<$size>(s)
}
}
};
}
impl_string_convert!([u8; 21], 21); impl_string_convert!([u8; 13], 13); impl_string_convert!([u8; 11], 11); impl_string_convert!([u8; 9], 9); impl_string_convert!([u8; 81], 81); impl_string_convert!([u8; 31], 31); impl_string_convert!([u8; 41], 41); impl_string_convert!([u8; 17], 17); impl_string_convert!([u8; 16], 16); impl_string_convert!([u8; 6], 6); impl_string_convert!([u8; 4], 4); impl_string_convert!([u8; 1], 1);
#[repr(C)]
#[derive(Debug, Clone)]
pub struct ReqUserLoginField {
pub trading_day: [u8; 9],
pub broker_id: BrokerIdType,
pub user_id: UserIdType,
pub password: PasswordType,
pub user_product_info: ProductInfoType,
pub interface_product_info: ProductInfoType,
pub protocol_info: ProtocolInfoType,
pub mac_address: MacAddressType,
pub one_time_password: PasswordType,
pub client_ip_address: IpAddressType,
pub client_ip_port: IpPortType,
pub login_remark: [u8; 36],
}
impl Default for ReqUserLoginField {
fn default() -> Self {
Self {
trading_day: [0; 9],
broker_id: [0; 11],
user_id: [0; 16],
password: [0; 41],
user_product_info: [0; 11],
interface_product_info: [0; 11],
protocol_info: [0; 11],
mac_address: [0; 21],
one_time_password: [0; 41],
client_ip_address: [0; 16],
client_ip_port: [0; 6],
login_remark: [0; 36],
}
}
}
impl ReqUserLoginField {
pub fn new(broker_id: &str, user_id: &str, password: &str) -> CtpResult<Self> {
let mut req = Self::default();
req.broker_id = BrokerIdType::from_utf8_string(broker_id)?;
req.user_id = UserIdType::from_utf8_string(user_id)?;
req.password = PasswordType::from_utf8_string(password)?;
Ok(req)
}
pub fn with_product_info(mut self, product_info: &str) -> CtpResult<Self> {
self.user_product_info = ProductInfoType::from_utf8_string(product_info)?;
self.interface_product_info = ProductInfoType::from_utf8_string(product_info)?;
Ok(self)
}
pub fn with_auth_code(mut self, auth_code: &str) -> CtpResult<Self> {
self.one_time_password = PasswordType::from_utf8_string(auth_code)?;
Ok(self)
}
pub fn with_mac_address(mut self, mac_address: &str) -> CtpResult<Self> {
self.mac_address = MacAddressType::from_utf8_string(mac_address)?;
Ok(self)
}
pub fn with_client_ip(mut self, ip: &str, port: &str) -> CtpResult<Self> {
self.client_ip_address = IpAddressType::from_utf8_string(ip)?;
self.client_ip_port = IpPortType::from_utf8_string(port)?;
Ok(self)
}
}
#[repr(C)]
#[derive(Debug, Clone)]
pub struct RspUserLoginField {
pub trading_day: [u8; 9],
pub login_time: [u8; 9],
pub broker_id: BrokerIdType,
pub user_id: UserIdType,
pub system_name: [u8; 41],
pub front_id: i32,
pub session_id: i32,
pub max_order_ref: [u8; 13],
pub shfe_time: [u8; 9],
pub dce_time: [u8; 9],
pub czce_time: [u8; 9],
pub ffex_time: [u8; 9],
pub ine_time: [u8; 9],
}
impl Default for RspUserLoginField {
fn default() -> Self {
Self {
trading_day: [0; 9],
login_time: [0; 9],
broker_id: [0; 11],
user_id: [0; 16],
system_name: [0; 41],
front_id: 0,
session_id: 0,
max_order_ref: [0; 13],
shfe_time: [0; 9],
dce_time: [0; 9],
czce_time: [0; 9],
ffex_time: [0; 9],
ine_time: [0; 9],
}
}
}
#[repr(C)]
#[derive(Debug, Clone)]
pub struct RspInfoField {
pub error_id: i32,
pub error_msg: [u8; 81],
}
impl Default for RspInfoField {
fn default() -> Self {
Self {
error_id: 0,
error_msg: [0; 81],
}
}
}
impl RspInfoField {
pub fn get_error_msg(&self) -> CtpResult<String> {
GbkConverter::fixed_bytes_to_utf8(&self.error_msg)
}
pub fn is_success(&self) -> bool {
self.error_id == 0
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_string_convert() {
let test_str = "测试用户";
let user_id = UserIdType::from_utf8_string(test_str).unwrap();
let converted = user_id.to_utf8_string().unwrap();
assert_eq!(converted.trim_end_matches('\0'), test_str);
}
#[test]
fn test_login_request_creation() {
let req = ReqUserLoginField::new("9999", "investor1", "123456").unwrap();
assert_eq!(
req.broker_id
.to_utf8_string()
.unwrap()
.trim_end_matches('\0'),
"9999"
);
assert_eq!(
req.user_id.to_utf8_string().unwrap().trim_end_matches('\0'),
"investor1"
);
assert_eq!(
req.password
.to_utf8_string()
.unwrap()
.trim_end_matches('\0'),
"123456"
);
}
#[test]
fn test_rsp_info_success() {
let mut rsp = RspInfoField::default();
assert!(rsp.is_success());
rsp.error_id = -1;
assert!(!rsp.is_success());
}
}
#[repr(C)]
#[derive(Debug, Clone)]
pub struct QryTradingAccountField {
pub broker_id: BrokerIdType,
pub investor_id: InvestorIdType,
pub currency_id: CurrencyIdType,
pub biz_type: BizTypeType,
pub account_id: AccountIdType,
}
impl Default for QryTradingAccountField {
fn default() -> Self {
unsafe { std::mem::zeroed() }
}
}
impl QryTradingAccountField {
pub fn new(broker_id: &str, investor_id: &str) -> CtpResult<Self> {
let mut req = Self::default();
req.broker_id = BrokerIdType::from_utf8_string(broker_id)?;
req.investor_id = InvestorIdType::from_utf8_string(investor_id)?;
Ok(req)
}
pub fn with_currency(mut self, currency_id: &str) -> CtpResult<Self> {
self.currency_id = CurrencyIdType::from_utf8_string(currency_id)?;
Ok(self)
}
}
#[repr(C)]
#[derive(Debug, Clone)]
pub struct QryInvestorPositionField {
pub broker_id: BrokerIdType,
pub investor_id: InvestorIdType,
pub instrument_id: InstrumentIdType,
pub exchange_id: ExchangeIdType,
pub invest_unit_id: InvestUnitIdType,
}
impl Default for QryInvestorPositionField {
fn default() -> Self {
unsafe { std::mem::zeroed() }
}
}
impl QryInvestorPositionField {
pub fn new(broker_id: &str, investor_id: &str) -> CtpResult<Self> {
let mut req = Self::default();
req.broker_id = BrokerIdType::from_utf8_string(broker_id)?;
req.investor_id = InvestorIdType::from_utf8_string(investor_id)?;
Ok(req)
}
pub fn with_instrument_id(mut self, instrument_id: &str) -> CtpResult<Self> {
self.instrument_id = InstrumentIdType::from_utf8_string(instrument_id)?;
Ok(self)
}
}
#[repr(C)]
#[derive(Debug, Clone)]
pub struct QryOrderField {
pub broker_id: BrokerIdType,
pub investor_id: InvestorIdType,
pub instrument_id: InstrumentIdType,
pub exchange_id: ExchangeIdType,
pub order_sys_id: OrderSysIdType,
pub insert_time_start: TimeType,
pub insert_time_end: TimeType,
pub invest_unit_id: InvestUnitIdType,
}
impl Default for QryOrderField {
fn default() -> Self {
unsafe { std::mem::zeroed() }
}
}
impl QryOrderField {
pub fn new(broker_id: &str, investor_id: &str) -> CtpResult<Self> {
let mut req = Self::default();
req.broker_id = BrokerIdType::from_utf8_string(broker_id)?;
req.investor_id = InvestorIdType::from_utf8_string(investor_id)?;
Ok(req)
}
pub fn with_instrument_id(mut self, instrument_id: &str) -> CtpResult<Self> {
self.instrument_id = InstrumentIdType::from_utf8_string(instrument_id)?;
Ok(self)
}
}
#[repr(C)]
#[derive(Debug, Clone)]
pub struct QryTradeField {
pub broker_id: BrokerIdType,
pub investor_id: InvestorIdType,
pub instrument_id: InstrumentIdType,
pub exchange_id: ExchangeIdType,
pub trade_id: TradeIdType,
pub trade_time_start: TimeType,
pub trade_time_end: TimeType,
pub invest_unit_id: InvestUnitIdType,
}
impl Default for QryTradeField {
fn default() -> Self {
unsafe { std::mem::zeroed() }
}
}
impl QryTradeField {
pub fn new(broker_id: &str, investor_id: &str) -> CtpResult<Self> {
let mut req = Self::default();
req.broker_id = BrokerIdType::from_utf8_string(broker_id)?;
req.investor_id = InvestorIdType::from_utf8_string(investor_id)?;
Ok(req)
}
pub fn with_instrument_id(mut self, instrument_id: &str) -> CtpResult<Self> {
self.instrument_id = InstrumentIdType::from_utf8_string(instrument_id)?;
Ok(self)
}
}
#[repr(C)]
#[derive(Debug, Clone)]
pub struct QryInstrumentField {
pub instrument_id: InstrumentIdType,
pub exchange_id: ExchangeIdType,
pub exchange_inst_id: ExchangeInstIdType,
pub product_id: InstrumentIdType,
}
impl Default for QryInstrumentField {
fn default() -> Self {
unsafe { std::mem::zeroed() }
}
}
impl QryInstrumentField {
pub fn new() -> Self {
Self::default()
}
pub fn with_instrument_id(mut self, instrument_id: &str) -> CtpResult<Self> {
self.instrument_id = InstrumentIdType::from_utf8_string(instrument_id)?;
Ok(self)
}
pub fn with_exchange_id(mut self, exchange_id: &str) -> CtpResult<Self> {
self.exchange_id = ExchangeIdType::from_utf8_string(exchange_id)?;
Ok(self)
}
}
#[repr(C)]
#[derive(Debug, Clone)]
pub struct InputOrderActionField {
pub broker_id: BrokerIdType,
pub investor_id: InvestorIdType,
pub order_action_ref: OrderActionRefType,
pub order_ref: OrderRefType,
pub request_id: RequestIdType,
pub front_id: FrontIdType,
pub session_id: SessionIdType,
pub exchange_id: ExchangeIdType,
pub order_sys_id: OrderSysIdType,
pub action_flag: ActionFlagType,
pub limit_price: PriceType,
pub volume_change: VolumeType,
pub user_id: UserIdType,
pub instrument_id: InstrumentIdType,
pub invest_unit_id: InvestUnitIdType,
pub ip_address: IPAddressType,
pub mac_address: MacAddressType,
}
impl Default for InputOrderActionField {
fn default() -> Self {
unsafe { std::mem::zeroed() }
}
}
impl InputOrderActionField {
pub fn new(
broker_id: &str,
investor_id: &str,
action_flag: u8,
order_ref: &str,
front_id: i32,
session_id: i32,
exchange_id: &str,
order_sys_id: &str,
) -> CtpResult<Self> {
let mut req = Self::default();
req.broker_id = BrokerIdType::from_utf8_string(broker_id)?;
req.investor_id = InvestorIdType::from_utf8_string(investor_id)?;
req.action_flag = action_flag;
req.order_ref = OrderRefType::from_utf8_string(order_ref)?;
req.front_id = front_id;
req.session_id = session_id;
req.exchange_id = ExchangeIdType::from_utf8_string(exchange_id)?;
req.order_sys_id = OrderSysIdType::from_utf8_string(order_sys_id)?;
Ok(req)
}
}
#[repr(C)]
#[derive(Debug, Clone)]
pub struct OrderActionField {
pub broker_id: BrokerIdType,
pub investor_id: InvestorIdType,
pub order_action_ref: OrderActionRefType,
pub order_ref: OrderRefType,
pub request_id: RequestIdType,
pub front_id: FrontIdType,
pub session_id: SessionIdType,
pub exchange_id: ExchangeIdType,
pub order_sys_id: OrderSysIdType,
pub action_flag: ActionFlagType,
pub limit_price: PriceType,
pub volume_change: VolumeType,
pub action_date: DateType,
pub action_time: TimeType,
pub trader_id: TraderIdType,
pub install_id: InstallIdType,
pub order_local_id: OrderLocalIdType,
pub action_local_id: OrderLocalIdType,
pub participant_id: ParticipantIdType,
pub client_id: ClientIdType,
pub business_unit: BusinessUnitType,
pub order_action_status: OrderActionStatusType,
pub user_id: UserIdType,
pub status_msg: ErrorMsgType,
pub instrument_id: InstrumentIdType,
pub branch_id: BranchIdType,
pub invest_unit_id: InvestUnitIdType,
pub ip_address: IPAddressType,
pub mac_address: MacAddressType,
}
impl Default for OrderActionField {
fn default() -> Self {
unsafe { std::mem::zeroed() }
}
}
#[repr(C)]
#[derive(Debug, Clone)]
pub struct QryInstrumentMarginRateField {
pub broker_id: BrokerIdType,
pub investor_id: InvestorIdType,
pub instrument_id: InstrumentIdType,
pub hedge_flag: u8,
pub exchange_id: ExchangeIdType,
pub invest_unit_id: InvestUnitIdType,
}
impl Default for QryInstrumentMarginRateField {
fn default() -> Self {
unsafe { std::mem::zeroed() }
}
}
impl QryInstrumentMarginRateField {
pub fn new(broker_id: &str, investor_id: &str, instrument_id: &str) -> CtpResult<Self> {
let mut req = Self::default();
req.broker_id = BrokerIdType::from_utf8_string(broker_id)?;
req.investor_id = InvestorIdType::from_utf8_string(investor_id)?;
req.instrument_id = InstrumentIdType::from_utf8_string(instrument_id)?;
Ok(req)
}
pub fn with_hedge_flag(mut self, hedge_flag: u8) -> Self {
self.hedge_flag = hedge_flag;
self
}
pub fn with_exchange_id(mut self, exchange_id: &str) -> CtpResult<Self> {
self.exchange_id = ExchangeIdType::from_utf8_string(exchange_id)?;
Ok(self)
}
}
#[repr(C)]
#[derive(Debug, Clone)]
pub struct QryInstrumentCommissionRateField {
pub broker_id: BrokerIdType,
pub investor_id: InvestorIdType,
pub instrument_id: InstrumentIdType,
pub exchange_id: ExchangeIdType,
pub invest_unit_id: InvestUnitIdType,
}
impl Default for QryInstrumentCommissionRateField {
fn default() -> Self {
unsafe { std::mem::zeroed() }
}
}
impl QryInstrumentCommissionRateField {
pub fn new(broker_id: &str, investor_id: &str, instrument_id: &str) -> CtpResult<Self> {
let mut req = Self::default();
req.broker_id = BrokerIdType::from_utf8_string(broker_id)?;
req.investor_id = InvestorIdType::from_utf8_string(investor_id)?;
req.instrument_id = InstrumentIdType::from_utf8_string(instrument_id)?;
Ok(req)
}
pub fn with_exchange_id(mut self, exchange_id: &str) -> CtpResult<Self> {
self.exchange_id = ExchangeIdType::from_utf8_string(exchange_id)?;
Ok(self)
}
}
#[repr(C)]
#[derive(Debug, Clone)]
pub struct QryExchangeField {
pub exchange_id: ExchangeIdType,
}
impl Default for QryExchangeField {
fn default() -> Self {
unsafe { std::mem::zeroed() }
}
}
impl QryExchangeField {
pub fn new() -> Self {
Self::default()
}
pub fn with_exchange_id(mut self, exchange_id: &str) -> CtpResult<Self> {
self.exchange_id = ExchangeIdType::from_utf8_string(exchange_id)?;
Ok(self)
}
}
#[repr(C)]
#[derive(Debug, Clone)]
pub struct QryProductField {
pub product_id: InstrumentIdType,
pub product_class: u8,
pub exchange_id: ExchangeIdType,
}
impl Default for QryProductField {
fn default() -> Self {
unsafe { std::mem::zeroed() }
}
}
impl QryProductField {
pub fn new() -> Self {
Self::default()
}
pub fn with_product_id(mut self, product_id: &str) -> CtpResult<Self> {
self.product_id = InstrumentIdType::from_utf8_string(product_id)?;
Ok(self)
}
pub fn with_exchange_id(mut self, exchange_id: &str) -> CtpResult<Self> {
self.exchange_id = ExchangeIdType::from_utf8_string(exchange_id)?;
Ok(self)
}
pub fn with_product_class(mut self, product_class: u8) -> Self {
self.product_class = product_class;
self
}
}
#[repr(C)]
#[derive(Debug, Clone)]
pub struct SettlementInfoConfirmField {
pub broker_id: BrokerIdType,
pub investor_id: InvestorIdType,
pub confirm_date: [u8; 9],
pub confirm_time: [u8; 9],
pub settlement_id: i32,
pub account_id: AccountIdType,
pub currency_id: CurrencyIdType,
}
impl Default for SettlementInfoConfirmField {
fn default() -> Self {
unsafe { std::mem::zeroed() }
}
}
impl SettlementInfoConfirmField {
pub fn new(broker_id: &str, investor_id: &str) -> CtpResult<Self> {
let mut req = Self::default();
req.broker_id = BrokerIdType::from_utf8_string(broker_id)?;
req.investor_id = InvestorIdType::from_utf8_string(investor_id)?;
Ok(req)
}
pub fn with_account_id(mut self, account_id: &str) -> CtpResult<Self> {
self.account_id = AccountIdType::from_utf8_string(account_id)?;
Ok(self)
}
}
#[repr(C)]
#[derive(Debug, Clone)]
pub struct ParkedOrderField {
pub broker_id: BrokerIdType,
pub investor_id: InvestorIdType,
pub instrument_id: InstrumentIdType,
pub order_ref: OrderRefType,
pub user_id: UserIdType,
pub order_price_type: u8,
pub direction: u8,
pub comb_offset_flag: [u8; 5],
pub comb_hedge_flag: [u8; 5],
pub limit_price: PriceType,
pub volume_total_original: VolumeType,
pub time_condition: u8,
pub gtd_date: [u8; 9],
pub volume_condition: u8,
pub min_volume: VolumeType,
pub contingent_condition: u8,
pub stop_price: PriceType,
pub force_close_reason: u8,
pub is_auto_suspend: i32,
pub business_unit: [u8; 21],
pub request_id: RequestIdType,
pub user_force_close: i32,
pub exchange_id: ExchangeIdType,
pub parked_order_id: [u8; 13],
pub user_type: u8,
pub status: u8,
pub error_id: i32,
pub error_msg: [u8; 81],
pub is_swap_order: i32,
pub invest_unit_id: InvestUnitIdType,
pub account_id: AccountIdType,
pub currency_id: CurrencyIdType,
pub client_id: [u8; 11],
pub ip_address: IPAddressType,
pub mac_address: MacAddressType,
}
impl Default for ParkedOrderField {
fn default() -> Self {
unsafe { std::mem::zeroed() }
}
}
impl ParkedOrderField {
pub fn new(
broker_id: &str,
investor_id: &str,
instrument_id: &str,
order_ref: &str,
direction: u8,
limit_price: f64,
volume: i32,
) -> CtpResult<Self> {
let mut req = Self::default();
req.broker_id = BrokerIdType::from_utf8_string(broker_id)?;
req.investor_id = InvestorIdType::from_utf8_string(investor_id)?;
req.instrument_id = InstrumentIdType::from_utf8_string(instrument_id)?;
req.order_ref = OrderRefType::from_utf8_string(order_ref)?;
req.direction = direction;
req.limit_price = limit_price;
req.volume_total_original = volume;
Ok(req)
}
}
#[repr(C)]
#[derive(Debug, Clone)]
pub struct ParkedOrderActionField {
pub broker_id: BrokerIdType,
pub investor_id: InvestorIdType,
pub order_action_ref: OrderActionRefType,
pub order_ref: OrderRefType,
pub request_id: RequestIdType,
pub front_id: FrontIdType,
pub session_id: SessionIdType,
pub exchange_id: ExchangeIdType,
pub order_sys_id: OrderSysIdType,
pub action_flag: ActionFlagType,
pub limit_price: PriceType,
pub volume_change: VolumeType,
pub user_id: UserIdType,
pub instrument_id: InstrumentIdType,
pub parked_order_action_id: [u8; 13],
pub user_type: u8,
pub status: u8,
pub error_id: i32,
pub error_msg: [u8; 81],
pub invest_unit_id: InvestUnitIdType,
pub ip_address: IPAddressType,
pub mac_address: MacAddressType,
}
impl Default for ParkedOrderActionField {
fn default() -> Self {
unsafe { std::mem::zeroed() }
}
}
impl ParkedOrderActionField {
pub fn new(
broker_id: &str,
investor_id: &str,
action_flag: u8,
order_ref: &str,
front_id: i32,
session_id: i32,
exchange_id: &str,
order_sys_id: &str,
) -> CtpResult<Self> {
let mut req = Self::default();
req.broker_id = BrokerIdType::from_utf8_string(broker_id)?;
req.investor_id = InvestorIdType::from_utf8_string(investor_id)?;
req.action_flag = action_flag;
req.order_ref = OrderRefType::from_utf8_string(order_ref)?;
req.front_id = front_id;
req.session_id = session_id;
req.exchange_id = ExchangeIdType::from_utf8_string(exchange_id)?;
req.order_sys_id = OrderSysIdType::from_utf8_string(order_sys_id)?;
Ok(req)
}
}
#[repr(C)]
#[derive(Debug, Clone)]
pub struct InstrumentMarginRateField {
pub instrument_id: InstrumentIdType,
pub investor_range: u8,
pub broker_id: BrokerIdType,
pub investor_id: InvestorIdType,
pub hedge_flag: u8,
pub long_margin_ratio_by_money: f64,
pub long_margin_ratio_by_volume: f64,
pub short_margin_ratio_by_money: f64,
pub short_margin_ratio_by_volume: f64,
pub is_relative: i32,
pub exchange_id: ExchangeIdType,
pub invest_unit_id: InvestUnitIdType,
}
impl Default for InstrumentMarginRateField {
fn default() -> Self {
unsafe { std::mem::zeroed() }
}
}
#[repr(C)]
#[derive(Debug, Clone)]
pub struct InstrumentCommissionRateField {
pub instrument_id: InstrumentIdType,
pub investor_range: u8,
pub broker_id: BrokerIdType,
pub investor_id: InvestorIdType,
pub open_ratio_by_money: f64,
pub open_ratio_by_volume: f64,
pub close_ratio_by_money: f64,
pub close_ratio_by_volume: f64,
pub close_today_ratio_by_money: f64,
pub close_today_ratio_by_volume: f64,
pub exchange_id: ExchangeIdType,
pub biz_type: u8,
pub invest_unit_id: InvestUnitIdType,
}
impl Default for InstrumentCommissionRateField {
fn default() -> Self {
unsafe { std::mem::zeroed() }
}
}
#[repr(C)]
#[derive(Debug, Clone)]
pub struct ExchangeField {
pub exchange_id: ExchangeIdType,
pub exchange_name: [u8; 61],
pub exchange_property: u8,
}
impl Default for ExchangeField {
fn default() -> Self {
unsafe { std::mem::zeroed() }
}
}
#[repr(C)]
#[derive(Debug, Clone)]
pub struct ProductField {
pub product_id: InstrumentIdType,
pub product_name: [u8; 21],
pub exchange_id: ExchangeIdType,
pub product_class: u8,
pub volume_multiple: i32,
pub price_tick: f64,
pub max_market_order_volume: i32,
pub min_market_order_volume: i32,
pub max_limit_order_volume: i32,
pub min_limit_order_volume: i32,
pub position_type: u8,
pub position_date_type: u8,
pub close_deal_type: u8,
pub trade_currency_id: CurrencyIdType,
pub margin_currency_id: CurrencyIdType,
}
impl Default for ProductField {
fn default() -> Self {
unsafe { std::mem::zeroed() }
}
}
#[repr(C)]
#[derive(Debug, Clone)]
pub struct InputExecOrderField {
pub broker_id: BrokerIdType,
pub investor_id: InvestorIdType,
pub instrument_id: InstrumentIdType,
pub exec_order_ref: OrderRefType,
pub user_id: UserIdType,
pub volume: i32,
pub request_id: i32,
pub business_unit: BusinessUnitType,
pub offset_flag: u8,
pub hedge_flag: u8,
pub action_type: u8,
pub posidir: u8,
pub reserve_position_flag: u8,
pub close_flag: u8,
pub exchange_id: ExchangeIdType,
pub invest_unit_id: InvestUnitIdType,
pub account_id: AccountIdType,
pub currency_id: CurrencyIdType,
pub client_id: ClientIdType,
pub ip_address: [u8; 16],
pub mac_address: [u8; 21],
}
impl Default for InputExecOrderField {
fn default() -> Self {
unsafe { std::mem::zeroed() }
}
}
impl InputExecOrderField {
pub fn new(
broker_id: &str,
investor_id: &str,
instrument_id: &str,
exec_order_ref: &str,
user_id: &str,
volume: i32,
action_type: u8,
) -> CtpResult<Self> {
let mut req = Self::default();
req.broker_id = BrokerIdType::from_utf8_string(broker_id)?;
req.investor_id = InvestorIdType::from_utf8_string(investor_id)?;
req.instrument_id = InstrumentIdType::from_utf8_string(instrument_id)?;
req.exec_order_ref = OrderRefType::from_utf8_string(exec_order_ref)?;
req.user_id = UserIdType::from_utf8_string(user_id)?;
req.volume = volume;
req.action_type = action_type;
Ok(req)
}
}
#[repr(C)]
#[derive(Debug, Clone)]
pub struct InputExecOrderActionField {
pub broker_id: BrokerIdType,
pub investor_id: InvestorIdType,
pub exec_order_action_ref: OrderRefType,
pub exec_order_ref: OrderRefType,
pub request_id: i32,
pub front_id: i32,
pub session_id: i32,
pub exchange_id: ExchangeIdType,
pub exec_order_sys_id: OrderSysIdType,
pub action_flag: u8,
pub user_id: UserIdType,
pub instrument_id: InstrumentIdType,
pub invest_unit_id: InvestUnitIdType,
pub ip_address: [u8; 16],
pub mac_address: [u8; 21],
}
impl Default for InputExecOrderActionField {
fn default() -> Self {
unsafe { std::mem::zeroed() }
}
}
impl InputExecOrderActionField {
pub fn new(
broker_id: &str,
investor_id: &str,
exec_order_action_ref: &str,
exec_order_ref: &str,
user_id: &str,
action_flag: u8,
) -> CtpResult<Self> {
let mut req = Self::default();
req.broker_id = BrokerIdType::from_utf8_string(broker_id)?;
req.investor_id = InvestorIdType::from_utf8_string(investor_id)?;
req.exec_order_action_ref = OrderRefType::from_utf8_string(exec_order_action_ref)?;
req.exec_order_ref = OrderRefType::from_utf8_string(exec_order_ref)?;
req.user_id = UserIdType::from_utf8_string(user_id)?;
req.action_flag = action_flag;
Ok(req)
}
}
#[repr(C)]
#[derive(Debug, Clone)]
pub struct InputForQuoteField {
pub broker_id: BrokerIdType,
pub investor_id: InvestorIdType,
pub instrument_id: InstrumentIdType,
pub for_quote_ref: OrderRefType,
pub user_id: UserIdType,
pub exchange_id: ExchangeIdType,
pub invest_unit_id: InvestUnitIdType,
pub ip_address: [u8; 16],
pub mac_address: [u8; 21],
}
impl Default for InputForQuoteField {
fn default() -> Self {
unsafe { std::mem::zeroed() }
}
}
impl InputForQuoteField {
pub fn new(
broker_id: &str,
investor_id: &str,
instrument_id: &str,
for_quote_ref: &str,
user_id: &str,
) -> CtpResult<Self> {
let mut req = Self::default();
req.broker_id = BrokerIdType::from_utf8_string(broker_id)?;
req.investor_id = InvestorIdType::from_utf8_string(investor_id)?;
req.instrument_id = InstrumentIdType::from_utf8_string(instrument_id)?;
req.for_quote_ref = OrderRefType::from_utf8_string(for_quote_ref)?;
req.user_id = UserIdType::from_utf8_string(user_id)?;
Ok(req)
}
}
#[repr(C)]
#[derive(Debug, Clone)]
pub struct InputQuoteField {
pub broker_id: BrokerIdType,
pub investor_id: InvestorIdType,
pub instrument_id: InstrumentIdType,
pub quote_ref: OrderRefType,
pub user_id: UserIdType,
pub ask_price: f64,
pub bid_price: f64,
pub ask_volume: i32,
pub bid_volume: i32,
pub request_id: i32,
pub business_unit: BusinessUnitType,
pub ask_offset_flag: u8,
pub bid_offset_flag: u8,
pub ask_hedge_flag: u8,
pub bid_hedge_flag: u8,
pub ask_order_ref: OrderRefType,
pub bid_order_ref: OrderRefType,
pub for_quote_sys_id: OrderSysIdType,
pub exchange_id: ExchangeIdType,
pub invest_unit_id: InvestUnitIdType,
pub account_id: AccountIdType,
pub currency_id: CurrencyIdType,
pub client_id: ClientIdType,
pub ip_address: [u8; 16],
pub mac_address: [u8; 21],
}
impl Default for InputQuoteField {
fn default() -> Self {
unsafe { std::mem::zeroed() }
}
}
impl InputQuoteField {
pub fn new(
broker_id: &str,
investor_id: &str,
instrument_id: &str,
quote_ref: &str,
user_id: &str,
ask_price: f64,
bid_price: f64,
ask_volume: i32,
bid_volume: i32,
) -> CtpResult<Self> {
let mut req = Self::default();
req.broker_id = BrokerIdType::from_utf8_string(broker_id)?;
req.investor_id = InvestorIdType::from_utf8_string(investor_id)?;
req.instrument_id = InstrumentIdType::from_utf8_string(instrument_id)?;
req.quote_ref = OrderRefType::from_utf8_string(quote_ref)?;
req.user_id = UserIdType::from_utf8_string(user_id)?;
req.ask_price = ask_price;
req.bid_price = bid_price;
req.ask_volume = ask_volume;
req.bid_volume = bid_volume;
Ok(req)
}
}
#[repr(C)]
#[derive(Debug, Clone)]
pub struct InputQuoteActionField {
pub broker_id: BrokerIdType,
pub investor_id: InvestorIdType,
pub quote_action_ref: OrderRefType,
pub quote_ref: OrderRefType,
pub request_id: i32,
pub front_id: i32,
pub session_id: i32,
pub exchange_id: ExchangeIdType,
pub quote_sys_id: OrderSysIdType,
pub action_flag: u8,
pub user_id: UserIdType,
pub instrument_id: InstrumentIdType,
pub invest_unit_id: InvestUnitIdType,
pub client_id: ClientIdType,
pub ip_address: [u8; 16],
pub mac_address: [u8; 21],
}
impl Default for InputQuoteActionField {
fn default() -> Self {
unsafe { std::mem::zeroed() }
}
}
impl InputQuoteActionField {
pub fn new(
broker_id: &str,
investor_id: &str,
quote_action_ref: &str,
quote_ref: &str,
user_id: &str,
action_flag: u8,
) -> CtpResult<Self> {
let mut req = Self::default();
req.broker_id = BrokerIdType::from_utf8_string(broker_id)?;
req.investor_id = InvestorIdType::from_utf8_string(investor_id)?;
req.quote_action_ref = OrderRefType::from_utf8_string(quote_action_ref)?;
req.quote_ref = OrderRefType::from_utf8_string(quote_ref)?;
req.user_id = UserIdType::from_utf8_string(user_id)?;
req.action_flag = action_flag;
Ok(req)
}
}
#[repr(C)]
#[derive(Debug, Clone)]
pub struct InputBatchOrderActionField {
pub broker_id: BrokerIdType,
pub investor_id: InvestorIdType,
pub order_action_ref: OrderRefType,
pub request_id: i32,
pub front_id: i32,
pub session_id: i32,
pub exchange_id: ExchangeIdType,
pub user_id: UserIdType,
pub invest_unit_id: InvestUnitIdType,
pub ip_address: [u8; 16],
pub mac_address: [u8; 21],
}
impl Default for InputBatchOrderActionField {
fn default() -> Self {
unsafe { std::mem::zeroed() }
}
}
impl InputBatchOrderActionField {
pub fn new(
broker_id: &str,
investor_id: &str,
order_action_ref: &str,
user_id: &str,
exchange_id: &str,
) -> CtpResult<Self> {
let mut req = Self::default();
req.broker_id = BrokerIdType::from_utf8_string(broker_id)?;
req.investor_id = InvestorIdType::from_utf8_string(investor_id)?;
req.order_action_ref = OrderRefType::from_utf8_string(order_action_ref)?;
req.user_id = UserIdType::from_utf8_string(user_id)?;
req.exchange_id = ExchangeIdType::from_utf8_string(exchange_id)?;
Ok(req)
}
}
#[repr(C)]
#[derive(Debug, Clone)]
pub struct RemoveParkedOrderField {
pub broker_id: BrokerIdType,
pub investor_id: InvestorIdType,
pub parked_order_id: ParkedOrderIdType,
pub invest_unit_id: InvestUnitIdType,
}
impl Default for RemoveParkedOrderField {
fn default() -> Self {
unsafe { std::mem::zeroed() }
}
}
impl RemoveParkedOrderField {
pub fn new(broker_id: &str, investor_id: &str, parked_order_id: &str) -> CtpResult<Self> {
let mut req = Self::default();
req.broker_id = BrokerIdType::from_utf8_string(broker_id)?;
req.investor_id = InvestorIdType::from_utf8_string(investor_id)?;
req.parked_order_id = ParkedOrderIdType::from_utf8_string(parked_order_id)?;
Ok(req)
}
}
#[repr(C)]
#[derive(Debug, Clone)]
pub struct RemoveParkedOrderActionField {
pub broker_id: BrokerIdType,
pub investor_id: InvestorIdType,
pub parked_order_action_id: ParkedOrderIdType,
pub invest_unit_id: InvestUnitIdType,
}
impl Default for RemoveParkedOrderActionField {
fn default() -> Self {
unsafe { std::mem::zeroed() }
}
}
impl RemoveParkedOrderActionField {
pub fn new(
broker_id: &str,
investor_id: &str,
parked_order_action_id: &str,
) -> CtpResult<Self> {
let mut req = Self::default();
req.broker_id = BrokerIdType::from_utf8_string(broker_id)?;
req.investor_id = InvestorIdType::from_utf8_string(investor_id)?;
req.parked_order_action_id = ParkedOrderIdType::from_utf8_string(parked_order_action_id)?;
Ok(req)
}
}
#[repr(C)]
#[derive(Debug, Clone)]
pub struct QryMaxOrderVolumeField {
pub broker_id: BrokerIdType,
pub investor_id: InvestorIdType,
pub instrument_id: InstrumentIdType,
pub direction: u8,
pub offset_flag: u8,
pub hedge_flag: u8,
pub max_volume: i32,
pub exchange_id: ExchangeIdType,
pub invest_unit_id: InvestUnitIdType,
}
impl Default for QryMaxOrderVolumeField {
fn default() -> Self {
unsafe { std::mem::zeroed() }
}
}
impl QryMaxOrderVolumeField {
pub fn new(
broker_id: &str,
investor_id: &str,
instrument_id: &str,
direction: u8,
) -> CtpResult<Self> {
let mut req = Self::default();
req.broker_id = BrokerIdType::from_utf8_string(broker_id)?;
req.investor_id = InvestorIdType::from_utf8_string(investor_id)?;
req.instrument_id = InstrumentIdType::from_utf8_string(instrument_id)?;
req.direction = direction;
Ok(req)
}
}
#[repr(C)]
#[derive(Debug, Clone)]
pub struct QryDepthMarketDataField {
pub instrument_id: InstrumentIdType,
pub exchange_id: ExchangeIdType,
}
impl Default for QryDepthMarketDataField {
fn default() -> Self {
unsafe { std::mem::zeroed() }
}
}
impl QryDepthMarketDataField {
pub fn new() -> Self {
Self::default()
}
pub fn with_instrument_id(mut self, instrument_id: &str) -> CtpResult<Self> {
self.instrument_id = InstrumentIdType::from_utf8_string(instrument_id)?;
Ok(self)
}
}
#[repr(C)]
#[derive(Debug, Clone)]
pub struct QrySettlementInfoField {
pub broker_id: BrokerIdType,
pub investor_id: InvestorIdType,
pub trading_day: TradingDayType,
pub account_id: AccountIdType,
pub currency_id: CurrencyIdType,
}
impl Default for QrySettlementInfoField {
fn default() -> Self {
unsafe { std::mem::zeroed() }
}
}
impl QrySettlementInfoField {
pub fn new(broker_id: &str, investor_id: &str) -> CtpResult<Self> {
let mut req = Self::default();
req.broker_id = BrokerIdType::from_utf8_string(broker_id)?;
req.investor_id = InvestorIdType::from_utf8_string(investor_id)?;
Ok(req)
}
}
#[repr(C)]
#[derive(Debug, Clone)]
pub struct QryTransferBankField {
pub bank_id: BankIdType,
pub bank_brch_id: BankBrchIdType,
}
impl Default for QryTransferBankField {
fn default() -> Self {
unsafe { std::mem::zeroed() }
}
}
impl QryTransferBankField {
pub fn new() -> Self {
Self::default()
}
}
#[repr(C)]
#[derive(Debug, Clone)]
pub struct QryInvestorPositionDetailField {
pub broker_id: BrokerIdType,
pub investor_id: InvestorIdType,
pub instrument_id: InstrumentIdType,
pub exchange_id: ExchangeIdType,
pub invest_unit_id: InvestUnitIdType,
}
impl Default for QryInvestorPositionDetailField {
fn default() -> Self {
unsafe { std::mem::zeroed() }
}
}
impl QryInvestorPositionDetailField {
pub fn new(broker_id: &str, investor_id: &str) -> CtpResult<Self> {
let mut req = Self::default();
req.broker_id = BrokerIdType::from_utf8_string(broker_id)?;
req.investor_id = InvestorIdType::from_utf8_string(investor_id)?;
Ok(req)
}
}
#[repr(C)]
#[derive(Debug, Clone)]
pub struct QryNoticeField {
pub broker_id: BrokerIdType,
}
impl Default for QryNoticeField {
fn default() -> Self {
unsafe { std::mem::zeroed() }
}
}
impl QryNoticeField {
pub fn new(broker_id: &str) -> CtpResult<Self> {
let mut req = Self::default();
req.broker_id = BrokerIdType::from_utf8_string(broker_id)?;
Ok(req)
}
}
#[repr(C)]
#[derive(Debug, Clone)]
pub struct SettlementInfoField {
pub trading_day: TradingDayType,
pub settlement_id: i32,
pub broker_id: BrokerIdType,
pub investor_id: InvestorIdType,
pub sequence_no: i32,
pub content: [u8; 1001],
pub account_id: AccountIdType,
pub currency_id: CurrencyIdType,
}
impl Default for SettlementInfoField {
fn default() -> Self {
unsafe { std::mem::zeroed() }
}
}
#[repr(C)]
#[derive(Debug, Clone)]
pub struct TransferBankField {
pub bank_id: BankIdType,
pub bank_brch_id: BankBrchIdType,
pub bank_name: BankNameType,
pub is_active: i32,
}
impl Default for TransferBankField {
fn default() -> Self {
unsafe { std::mem::zeroed() }
}
}
#[repr(C)]
#[derive(Debug, Clone)]
pub struct InvestorPositionDetailField {
pub instrument_id: InstrumentIdType,
pub broker_id: BrokerIdType,
pub investor_id: InvestorIdType,
pub hedge_flag: u8,
pub direction: u8,
pub open_date: TradingDayType,
pub trade_id: TradeIdType,
pub volume: i32,
pub open_price: f64,
pub trading_day: TradingDayType,
pub settlement_id: i32,
pub trade_type: u8,
pub comb_instrument_id: InstrumentIdType,
pub exchange_id: ExchangeIdType,
pub close_profit_by_date: f64,
pub close_profit_by_trade: f64,
pub position_profit_by_date: f64,
pub position_profit_by_trade: f64,
pub margin: f64,
pub exch_margin: f64,
pub margin_rate_by_money: f64,
pub margin_rate_by_volume: f64,
pub last_settlement_price: f64,
pub settlement_price: f64,
pub close_volume: i32,
pub close_amount: f64,
pub time_first_volume: i32,
pub invest_unit_id: InvestUnitIdType,
pub spec_posidir: u8,
}
impl Default for InvestorPositionDetailField {
fn default() -> Self {
unsafe { std::mem::zeroed() }
}
}
#[repr(C)]
#[derive(Debug, Clone)]
pub struct NoticeField {
pub broker_id: BrokerIdType,
pub content: [u8; 501],
pub url_link: [u8; 201],
}
impl Default for NoticeField {
fn default() -> Self {
unsafe { std::mem::zeroed() }
}
}