获取当前设置的交易对、合约代码对应的{@struct/Ticker Ticker}结构,即行情数据。 GetTicker()
函数是交易所对象{@var/EXCHANGE exchange}的成员函数,exchange
对象的成员函数(方法)的用途只和exchange
相关,文档之后不再赘述。
exchange.GetTicker()
函数请求数据成功时返回{@struct/Ticker Ticker}结构,请求数据失败时返回空值。
{@struct/Ticker Ticker}、空值
exchange.GetTicker() exchange.GetTicker(symbol)
参数symbol
用于指定请求的{@struct/Ticker Ticker}数据对应的合约代码。不传该参数时默认请求当前设置的合约代码的行情数据。
symbol false string
function main(){
// 鉴于测试代码,不使用商品期货策略一般架构,这里仅仅判断exchange.IO("status")函数,判断连接期货公司前置机成功后立即执行测试代码。股票证券无需使用exchange.IO("status")判断连接状态
while(!exchange.IO("status")) {
Sleep(1000)
}
Log(exchange.SetContractType("rb888"))
var ticker = exchange.GetTicker()
Log("Symbol:", ticker.Symbol, "High:", ticker.High, "Low:", ticker.Low, "Sell:", ticker.Sell, "Buy:", ticker.Buy, "Last:", ticker.Last, "Open:", ticker.Open, "Volume:", ticker.Volume)
}
def main():
while not exchange.IO("status"):
Sleep(1000)
Log(exchange.SetContractType("rb888"))
ticker = exchange.GetTicker()
Log("Symbol:", ticker["Symbol"], "High:", ticker["High"], "Low:", ticker["Low"], "Sell:", ticker["Sell"], "Buy:", ticker["Buy"], "Last:", ticker["Last"], "Open:", ticker.Open, "Volume:", ticker["Volume"])
void main() {
while(exchange.IO("status") == 0) {
Sleep(1000);
}
Log(exchange.SetContractType("rb888"));
auto ticker = exchange.GetTicker();
Log("Symbol:", ticker.Symbol, "High:", ticker.High, "Low:", ticker.Low, "Sell:", ticker.Sell, "Buy:", ticker.Buy, "Last:", ticker.Last, "Open:", ticker.Open, "Volume:", ticker.Volume);
}
测试exchange.GetTicker()
函数:
回测系统中exchange.GetTicker()
函数返回的Ticker
数据, 其中High
、Low
为模拟值,取自当时盘口的卖一、买一。
商品期货策略实盘中如果没有行情推送过来时,exchange.GetTicker()函数会阻塞,等待行情推送。
exchange.GetDepth()
、exchange.GetTrades()
、exchange.GetRecords()
同理。如果不希望阻塞可以使用切换行情模式:
实盘时(非回测)exchange.GetTicker()
函数的返回值中Info
属性储存接口调用时返回的原始数据。
商品期货 返回商品期货CTP协议/易盛协议接口应答数据,以CTP协议为例:
{
"BidPrice4": 1.7976931348623157e+308,
"AskVolume4": 0,
"AskVolume5": 0,
"Turnover": 26229625880,
"OpenInterest": 1364847, // 持仓量
"ClosePrice": 1.7976931348623157e+308,
"LowerLimitPrice": 3473,
"BidPrice3": 1.7976931348623157e+308,
"ExchangeID": "",
"BidPrice2": 1.7976931348623157e+308,
"BidPrice5": 1.7976931348623157e+308,
"AveragePrice": 37323.89130239898,
"BidVolume4": 0,
"BidVolume5": 0,
"ExchangeInstID": "",
"LowestPrice": 3715,
"Volume": 702757,
"BidVolume3": 0,
"AskPrice3": 1.7976931348623157e+308,
"AskVolume3": 0,
"ActionDay": "20200714",
"PreClosePrice": 3739,
"SettlementPrice": 1.7976931348623157e+308,
"UpdateTime": "13:40:01",
"BidPrice1": 3727,
"AskPrice2": 1.7976931348623157e+308,
"UpperLimitPrice": 3996,
"CurrDelta": 1.7976931348623157e+308,
"UpdateMillisec": 500,
"AskVolume1": 154,
"BidVolume2": 0,
"PreOpenInterest": 1372843,
"PreDelta": 0,
"AskPrice1": 3728,
"AskVolume2": 0,
"TradingDay": "20200714",
"InstrumentID": "rb2010",
"LastPrice": 3727,
"HighestPrice": 3749,
"BidVolume1": 444,
"PreSettlementPrice": 3735,
"OpenPrice": 3740,
"AskPrice4": 1.7976931348623157e+308,
"AskPrice5": 1.7976931348623157e+308
}
{@fun/Market/exchange.GetDepth exchange.GetDepth}, {@fun/Market/exchange.GetTrades exchange.GetTrades}, {@fun/Market/exchange.GetRecords exchange.GetRecords}
Log exchange.GetDepth