[TOC]
优宽量化的CTP(商品期货)终端提供了完整的全API实现, 当优宽平台的API满足不了你需要的功能时
可以用 exchange.IO
函数进行更深层的系统调用, 完全兼容官方的Api名称, 以几个简单的例子做为介绍
查询投资者信息
Log(exchange.IO("api", "ReqQryInvestor"))
修改密码
exchange.IO("api", "ReqUserPasswordUpdate", {BrokerID: "9999", UserID: "11111", OldPassword: "oldpass", NewPassword: "newpass"})
复杂的例子:
function main() {
// 如果再加一个参数值为false表示不等待返回值, 只发送请求
// 第三个参数只需要填充需要的字段, 也可省略此参数, 如果类型为char,传长度为1的字符串即可
var r = exchange.IO("api", "ReqQryProduct", {ProductID: "MA"});
if (!r) { // CTP 未登陆的时候会失败
return
}
_.each(r, function(item) { // IO请求可能返回多个数据包, 所以以数组的形式返回
_.each(item, function(f) { // 便历数据包的所有数据类型, 一个数据包可能包含多个具体数据
// 具体数据类型的名称, 请参数CTP官方文档 http://www.sfit.com.cn/5_2_DocumentDown.htm
if (f.Name == 'CThostFtdcProductField') { // 取出来需要的数据, Name 为此数据的类型, Value 为此数据的值
f.Value.ProductName = StrDecode(f.Value.ProductName) // CTP中的汉字是GBK编码可用此函数解码
Log(f.Value) // 打印查询的的甲醇的信息
}
})
});
}
查询结算单
function main() {
var r = exchange.IO("api", "ReqQrySettlementInfo", {TradingDay: "20190506"}); // 也可不指定日期
var s = ''
_.each(r, function(item) {
_.each(item, function(f) {
if (f.Name == 'CThostFtdcSettlementInfoField') {
s += f.Value.Content
}
})
});
Log(StrDecode(s));
}
CTP 文档 下载地址 : http://www.sfit.com.cn/DocumentDown/api_2/CTP-API-Interfacedescription-ct.zip
上期技术SIMNOW官网 : http://www.simnow.com.cn
CThostFtdcInputBatchOrderActionField {
Number OrderActionRef
Number FrontID
Number SessionID
String InvestUnitID
String IPAddress
String MacAddress
String BrokerID
String InvestorID
Number RequestID
String ExchangeID
String UserID
}
CThostFtdcInputCombActionField {
String InvestUnitID
String InvestorID
String InstrumentID
String UserID
String HedgeFlag // char
String ExchangeID
String IPAddress
String MacAddress
String BrokerID
String CombActionRef
String Direction // char
Number Volume
String CombDirection // char
}
CThostFtdcInputExecOrderActionField {
String MacAddress
String ExecOrderRef
String ExchangeID
String ExecOrderSysID
String BrokerID
String ActionFlag // char
String InvestUnitID
String UserID
Number ExecOrderActionRef
Number RequestID
Number SessionID
String IPAddress
String InvestorID
Number FrontID
String InstrumentID
}
CThostFtdcInputExecOrderField {
String InvestorID
Number Volume
String CloseFlag // char
String InvestUnitID
String BrokerID
String OffsetFlag // char
String ActionType // char
String PosiDirection // char
String ExchangeID
String AccountID
String IPAddress
Number RequestID
String CurrencyID
String ClientID
String MacAddress
String ReservePositionFlag // char
String ExecOrderRef
String UserID
String BusinessUnit
String HedgeFlag // char
String InstrumentID
}
CThostFtdcInputForQuoteField {
String MacAddress
String InvestorID
String InstrumentID
String IPAddress
String ExchangeID
String InvestUnitID
String BrokerID
String ForQuoteRef
String UserID
}
CThostFtdcReqTransferField {
String BankID
String BrokerBranchID
String BankSerial
Number PlateSerial
String IdCardType // char
String Message
String BankAccType // char
String DeviceID
String BankPwdFlag // char
Number RequestID
String TradeDate
String TradingDay
String CustomerName
String BankPassWord
String SecuPwdFlag // char
String LongCustomerName
String TradeCode
Number SessionID
String IdentifiedCardNo
String CustType // char
Number CustFee
String BrokerIDByBank
String BankSecuAcc
String OperNo
String TradeTime
String BankAccount
String AccountID
Number TradeAmount
Number FutureFetchAmount
String VerifyCertNoFlag // char
String BankBranchID
Number FutureSerial
String Password
Number InstallID
String Digest
Number TID
String BrokerID
String LastFragment // char
String UserID
String CurrencyID
String FeePayFlag // char
Number BrokerFee
String BankSecuAccType // char
String TransferStatus // char
}
CThostFtdcReqTransferField {
String BankID
String CurrencyID
String BankSecuAccType // char
String BrokerIDByBank
String TradeCode
String TradeTime
String IdentifiedCardNo
Number FutureFetchAmount
String BankBranchID
String BrokerBranchID
Number SessionID
String CustomerName
String Password
Number InstallID
Number TradeAmount
Number CustFee
String DeviceID
String SecuPwdFlag // char
String LastFragment // char
String BankAccount
String VerifyCertNoFlag // char
Number BrokerFee
String TransferStatus // char
String BrokerID
String TradeDate
String BankSerial
Number PlateSerial
String FeePayFlag // char
String BankPwdFlag // char
String TradingDay
String IdCardType // char
Number FutureSerial
String Message
Number RequestID
String UserID
String Digest
String BankSecuAcc
String OperNo
Number TID
String LongCustomerName
String CustType // char
String BankPassWord
String AccountID
String BankAccType // char
}
CThostFtdcReqGenUserCaptchaField {
String TradingDay
String BrokerID
String UserID
}
CThostFtdcReqGenUserTextField {
String BrokerID
String UserID
String TradingDay
}
CThostFtdcInputOptionSelfCloseActionField {
Number OptionSelfCloseActionRef
Number RequestID
String UserID
String IPAddress
String OptionSelfCloseRef
Number FrontID
String ExchangeID
String InstrumentID
String MacAddress
String BrokerID
String InvestorID
String OptionSelfCloseSysID
String ActionFlag // char
String InvestUnitID
Number SessionID
}
CThostFtdcInputOptionSelfCloseField {
Number RequestID
String IPAddress
String InstrumentID
Number Volume
String BusinessUnit
String InvestUnitID
String MacAddress
String BrokerID
String OptionSelfCloseRef
String UserID
String ExchangeID
String CurrencyID
String InvestorID
String HedgeFlag // char
String OptSelfCloseFlag // char
String AccountID
String ClientID
}
CThostFtdcInputOrderActionField {
String IPAddress
String MacAddress
String OrderSysID
Number OrderActionRef
Number RequestID
String ExchangeID
String UserID
String InstrumentID
String InvestorID
Number VolumeChange
String BrokerID
Number FrontID
Number SessionID
String ActionFlag // char
Number LimitPrice
String InvestUnitID
String OrderRef
}
CThostFtdcInputOrderField {
String ClientID
String UserID
String TimeCondition // char
String BusinessUnit
Number IsSwapOrder
String InvestUnitID
Number LimitPrice
String AccountID
String IPAddress
String VolumeCondition // char
Number StopPrice
Number UserForceClose
String Direction // char
Number VolumeTotalOriginal
String ForceCloseReason // char
String ExchangeID
String MacAddress
String InstrumentID
String CombHedgeFlag
Number MinVolume
String ContingentCondition // char
Number RequestID
String OrderRef
String OrderPriceType // char
String CurrencyID
String BrokerID
String InvestorID
String CombOffsetFlag
String GTDDate
Number IsAutoSuspend
}
CThostFtdcParkedOrderActionField {
String BrokerID
String OrderRef
String ActionFlag // char
Number VolumeChange
String UserID
String InstrumentID
String UserType // char
String Status // char
String ErrorMsg
String InvestorID
Number OrderActionRef
Number SessionID
String OrderSysID
String InvestUnitID
Number FrontID
String ExchangeID
Number LimitPrice
String ParkedOrderActionID
Number RequestID
Number ErrorID
String IPAddress
String MacAddress
}
CThostFtdcParkedOrderField {
String GTDDate
Number MinVolume
Number IsAutoSuspend
String Direction // char
String CombHedgeFlag
String ContingentCondition // char
Number StopPrice
Number RequestID
String ParkedOrderID
Number ErrorID
String InvestorID
String ErrorMsg
String CurrencyID
Number UserForceClose
String OrderPriceType // char
String CombOffsetFlag
String UserType // char
Number IsSwapOrder
String ClientID
String InvestUnitID
String InstrumentID
Number VolumeTotalOriginal
String TimeCondition // char
String BusinessUnit
String AccountID
String MacAddress
String BrokerID
Number LimitPrice
String ExchangeID
String Status // char
String IPAddress
String UserID
String VolumeCondition // char
String ForceCloseReason // char
String OrderRef
}
CThostFtdcQryAccountregisterField {
String BankID
String BankBranchID
String CurrencyID
String BrokerID
String AccountID
}
CThostFtdcQryBrokerTradingAlgosField {
String BrokerID
String ExchangeID
String InstrumentID
}
CThostFtdcQryBrokerTradingParamsField {
String BrokerID
String InvestorID
String CurrencyID
String AccountID
}
CThostFtdcQryCFMMCTradingAccountKeyField {
String BrokerID
String InvestorID
}
CThostFtdcQryCombActionField {
String InvestorID
String InstrumentID
String ExchangeID
String InvestUnitID
String BrokerID
}
CThostFtdcQryCombInstrumentGuardField {
String BrokerID
String InstrumentID
String ExchangeID
}
CThostFtdcQryContractBankField {
String BrokerID
String BankID
String BankBrchID
}
CThostFtdcQryDepthMarketDataField {
String InstrumentID
String ExchangeID
}
CThostFtdcQryEWarrantOffsetField {
String BrokerID
String InvestorID
String ExchangeID
String InstrumentID
String InvestUnitID
}
CThostFtdcQryExchangeField {
String ExchangeID
}
CThostFtdcQryExchangeMarginRateField {
String HedgeFlag // char
String ExchangeID
String BrokerID
String InstrumentID
}
CThostFtdcQryExchangeMarginRateAdjustField {
String BrokerID
String InstrumentID
String HedgeFlag // char
}
CThostFtdcQryExchangeRateField {
String BrokerID
String FromCurrencyID
String ToCurrencyID
}
CThostFtdcQryExecOrderField {
String InsertTimeStart
String InsertTimeEnd
String BrokerID
String InvestorID
String InstrumentID
String ExchangeID
String ExecOrderSysID
}
CThostFtdcQryForQuoteField {
String InstrumentID
String ExchangeID
String InsertTimeStart
String InsertTimeEnd
String InvestUnitID
String BrokerID
String InvestorID
}
CThostFtdcQryInstrumentField {
String InstrumentID
String ExchangeID
String ExchangeInstID
String ProductID
}
CThostFtdcQryInstrumentCommissionRateField {
String BrokerID
String InvestorID
String InstrumentID
String ExchangeID
String InvestUnitID
}
CThostFtdcQryInstrumentMarginRateField {
String InvestorID
String InstrumentID
String HedgeFlag // char
String ExchangeID
String InvestUnitID
String BrokerID
}
CThostFtdcQryInstrumentOrderCommRateField {
String BrokerID
String InvestorID
String InstrumentID
}
CThostFtdcQryInvestUnitField {
String InvestorID
String InvestUnitID
String BrokerID
}
CThostFtdcQryInvestorField {
String InvestorID
String BrokerID
}
CThostFtdcQryInvestorPositionField {
String BrokerID
String InvestorID
String InstrumentID
String ExchangeID
String InvestUnitID
}
CThostFtdcQryInvestorPositionCombineDetailField {
String ExchangeID
String InvestUnitID
String BrokerID
String InvestorID
String CombInstrumentID
}
CThostFtdcQryInvestorPositionDetailField {
String BrokerID
String InvestorID
String InstrumentID
String ExchangeID
String InvestUnitID
}
CThostFtdcQryInvestorProductGroupMarginField {
String ProductGroupID
String HedgeFlag // char
String ExchangeID
String InvestUnitID
String BrokerID
String InvestorID
}
CThostFtdcQryMMInstrumentCommissionRateField {
String BrokerID
String InvestorID
String InstrumentID
}
CThostFtdcQryMMOptionInstrCommRateField {
String BrokerID
String InvestorID
String InstrumentID
}
CThostFtdcQryNoticeField {
String BrokerID
}
CThostFtdcQryOptionInstrCommRateField {
String BrokerID
String InvestorID
String InstrumentID
String ExchangeID
String InvestUnitID
}
CThostFtdcQryOptionInstrTradeCostField {
String HedgeFlag // char
Number InputPrice
Number UnderlyingPrice
String ExchangeID
String InvestUnitID
String BrokerID
String InvestorID
String InstrumentID
}
CThostFtdcQryOptionSelfCloseField {
String InsertTimeStart
String InsertTimeEnd
String BrokerID
String InvestorID
String InstrumentID
String ExchangeID
String OptionSelfCloseSysID
}
CThostFtdcQryOrderField {
String InsertTimeEnd
String InvestUnitID
String BrokerID
String InvestorID
String InstrumentID
String ExchangeID
String OrderSysID
String InsertTimeStart
}
CThostFtdcQryParkedOrderField {
String BrokerID
String InvestorID
String InstrumentID
String ExchangeID
String InvestUnitID
}
CThostFtdcQryParkedOrderActionField {
String InvestorID
String InstrumentID
String ExchangeID
String InvestUnitID
String BrokerID
}
CThostFtdcQryProductField {
String ProductID
String ProductClass // char
String ExchangeID
}
CThostFtdcQryProductExchRateField {
String ProductID
String ExchangeID
}
CThostFtdcQryProductGroupField {
String ProductID
String ExchangeID
}
CThostFtdcQryQuoteField {
String InvestorID
String InstrumentID
String ExchangeID
String QuoteSysID
String InsertTimeStart
String InsertTimeEnd
String InvestUnitID
String BrokerID
}
CThostFtdcQrySecAgentACIDMapField {
String UserID
String AccountID
String CurrencyID
String BrokerID
}
CThostFtdcQrySecAgentCheckModeField {
String BrokerID
String InvestorID
}
CThostFtdcQrySecAgentTradeInfoField {
String BrokerSecAgentID
String BrokerID
}
CThostFtdcQryTradingAccountField {
String BrokerID
String InvestorID
String CurrencyID
String BizType // char
String AccountID
}
CThostFtdcQrySettlementInfoField {
String BrokerID
String InvestorID
String TradingDay
String AccountID
String CurrencyID
}
CThostFtdcQrySettlementInfoConfirmField {
String InvestorID
String AccountID
String CurrencyID
String BrokerID
}
CThostFtdcQryTradeField {
String BrokerID
String InvestorID
String InstrumentID
String ExchangeID
String TradeID
String TradeTimeStart
String TradeTimeEnd
String InvestUnitID
}
CThostFtdcQryTradingAccountField {
String BrokerID
String InvestorID
String CurrencyID
String BizType // char
String AccountID
}
CThostFtdcQryTradingCodeField {
String InvestorID
String ExchangeID
String ClientID
String ClientIDType // char
String InvestUnitID
String BrokerID
}
CThostFtdcQryTradingNoticeField {
String BrokerID
String InvestorID
String InvestUnitID
}
CThostFtdcQryTransferBankField {
String BankBrchID
String BankID
}
CThostFtdcQryTransferSerialField {
String BrokerID
String AccountID
String BankID
String CurrencyID
}
CThostFtdcReqQueryAccountField {
String BankID
String BankBranchID
Number SessionID
String IdentifiedCardNo
String Digest
Number PlateSerial
String LastFragment // char
String BankPassWord
String LongCustomerName
Number TID
String BankSerial
String UserID
String CurrencyID
String BankAccType // char
String BankSecuAcc
String SecuPwdFlag // char
String OperNo
String TradeCode
String TradeDate
String TradeTime
String TradingDay
String IdCardType // char
String BankAccount
String DeviceID
String BrokerIDByBank
String BrokerID
String Password
String BrokerBranchID
String CustType // char
Number FutureSerial
String BankPwdFlag // char
Number RequestID
String CustomerName
String AccountID
Number InstallID
String VerifyCertNoFlag // char
String BankSecuAccType // char
}
CThostFtdcQueryCFMMCTradingAccountTokenField {
String InvestUnitID
String BrokerID
String InvestorID
}
CThostFtdcQueryMaxOrderVolumeField {
String HedgeFlag // char
Number MaxVolume
String ExchangeID
String InvestUnitID
String BrokerID
String Direction // char
String OffsetFlag // char
String InvestorID
String InstrumentID
}
CThostFtdcInputQuoteActionField {
Number QuoteActionRef
Number FrontID
String QuoteSysID
String ActionFlag // char
String ClientID
String MacAddress
String BrokerID
String UserID
String IPAddress
Number SessionID
String InstrumentID
String ExchangeID
String QuoteRef
Number RequestID
String InvestUnitID
String InvestorID
}
CThostFtdcInputQuoteField {
Number BidVolume
String BidOffsetFlag // char
String BidHedgeFlag // char
String ForQuoteSysID
String BrokerID
String InstrumentID
Number BidPrice
String QuoteRef
String AskHedgeFlag // char
String IPAddress
String ExchangeID
String InvestUnitID
String MacAddress
String InvestorID
String UserID
String AskOrderRef
String BusinessUnit
String AskOffsetFlag // char
String BidOrderRef
String ClientID
Number AskPrice
Number AskVolume
Number RequestID
}
CThostFtdcRemoveParkedOrderField {
String ParkedOrderID
String InvestUnitID
String BrokerID
String InvestorID
}
CThostFtdcRemoveParkedOrderActionField {
String InvestorID
String ParkedOrderActionID
String InvestUnitID
String BrokerID
}
CThostFtdcSettlementInfoConfirmField {
String BrokerID
String InvestorID
String ConfirmDate
String ConfirmTime
Number SettlementID
String AccountID
String CurrencyID
}
CThostFtdcTradingAccountPasswordUpdateField {
String NewPassword
String CurrencyID
String BrokerID
String AccountID
String OldPassword
}
CThostFtdcReqUserAuthMethodField {
String TradingDay
String BrokerID
String UserID
}
CThostFtdcUserLogoutField {
String BrokerID
String UserID
}
CThostFtdcUserPasswordUpdateField {
String UserID
String OldPassword
String NewPassword
String BrokerID
}