资源加载中... loading...

exchange.GetTicker

获取当前设置的交易对、合约代码对应的{@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数据, 其中HighLow为模拟值,取自当时盘口的卖一、买一。 商品期货策略实盘中如果没有行情推送过来时,exchange.GetTicker()函数会阻塞,等待行情推送。 exchange.GetDepth()exchange.GetTrades()exchange.GetRecords()同理。如果不希望阻塞可以使用切换行情模式:

  • exchange.IO("mode", 0) 立即返回模式,如果当前还没有接收到交易所最新的行情数据推送,就立即返回旧的行情数据,如果有新的数据就返回新的数据。
  • exchange.IO("mode", 1) 缓存模式(默认模式),如果当前还没有收到交易所最新的行情数据(同上一次接口获取的数据比较),就等待接收然后再返回,如果调用该函数之前收到了最新的行情数据,就立即返回最新的数据。
  • exchange.IO("mode", 2) 强制更新模式,进入等待一直到接收到交易所下一次的最新推送数据后返回。

实盘时(非回测)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