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

Account

exchange.GetAccount

exchange.GetAccount()函数用于请求交易所账户信息。 GetAccount()函数是交易所对象{@var/EXCHANGE exchange}的成员函数,exchange对象的成员函数(方法)的用途只和exchange相关,文档之后不再赘述。

查询账户资产信息,查询成功返回{@struct/Account Account}结构,查询失败返回空值。 {@struct/Account Account}、空值

exchange.GetAccount()

function main(){
    // 鉴于测试代码,不使用商品期货策略一般架构,这里仅仅判断exchange.IO("status")函数,判断连接期货公司前置机成功后立即执行测试代码。股票证券无需使用exchange.IO("status")判断连接状态
    while (!exchange.IO("status")) {
        Sleep(1000)
    }
    
    // 获取账户资产信息,可以不用设置合约
    var account = exchange.GetAccount()
    Log("账户信息,Balance:", account.Balance, "FrozenBalance:", account.FrozenBalance, "Equity:", account.Equity, "UPnL:", account.UPnL)
}
def main():
    while not exchange.IO("status"):
        Sleep(1000)
    
    account = exchange.GetAccount()
    Log("账户信息,Balance", account["Balance"], "FrozenBalance:", account["FrozenBalance"], "Equity:", account["Equity"], "UPnL:", account["UPnL"])
void main() {
    while (exchange.IO("status") == 0) {
        Sleep(1000);
    }
    
    auto account = exchange.GetAccount();
    Log("账户信息,Balance", account.Balance, "FrozenBalance:", account.FrozenBalance, "Equity:", account.Equity, "UPnL:", account.UPnL);
}

获取当前账户信息。

{@struct/Account Account}

exchange.GetName

exchange.GetName()函数用于获取当前交易所对象绑定的交易所名称。

exchange.GetName()函数返回优宽量化交易平台定义的交易所名称。 string

exchange.GetName()

function main() {
    Log("判断交易所对象exchange为商品期货-CTP协议,判断结果为:", exchange.GetName() == "Futures_CTP")
}
def main():
    Log("判断交易所对象exchange为商品期货-CTP协议,判断结果为:", exchange.GetName() == "Futures_CTP")
void main() {
    Log("判断交易所对象exchange为商品期货-CTP协议,判断结果为:", exchange.GetName() == "Futures_CTP");
}

exchange.GetName()函数一般用来识别策略代码中的exchange或者exchanges[1]exchanges[2]这些交易所对象。

  • 股票证券 实盘:富途证券交易所对象时exchange.GetName()函数返回Futures_Futu。中泰XTP交易所对象时exchange.GetName()函数返回Futures_XTP。 回测系统:回测系统并不区分协议,所以exchange.GetName()函数返回Futures_XTP

  • 商品期货 实盘:CTP协议的交易所对象时exchange.GetName()函数返回Futures_CTP,易盛协议的交易所对象时exchange.GetName()函数返回Futures_Esunny。 回测系统:回测系统并不区分协议,所以exchange.GetName()函数返回Futures_CTP

{@fun/Account/exchange.GetLabel exchange.GetLabel}

exchange.GetLabel

exchange.GetLabel()函数用于获取配置交易所对象时设置的自定义标签。

exchange.GetLabel()函数返回配置交易所对象时设置的自定义标签。 string

exchange.GetLabel()

function main() {
    Log("exchange label:", exchange.GetLabel())
}
def main():
    Log("exchange label:", exchange.GetLabel())
void main() {
    Log("exchange label:", exchange.GetLabel());
}

通过设置的标签来识别策略代码中的exchange或者exchanges[1]exchanges[2]等交易所对象。

{@var/EXCHANGE exchange}

exchange.GetCurrency

exchange.GetCurrency()函数用于获取当前设置的交易对。

exchange.GetCurrency()函数返回当前{@var/EXCHANGE exchange}交易所对象设置的交易对。 string

exchange.GetCurrency()

function main() {
    Log("exchange 当前交易对为:", exchange.GetCurrency())
}
def main():
    Log("exchange 当前交易对为:", exchange.GetCurrency())
void main() {
    Log("exchange 当前交易对为:", exchange.GetCurrency());
}

商品期货、股票证券等返回固定的字符串: - 股票证券 实盘:富途证券交易所对象时exchange.GetCurrency()函数返回STOCK。 回测系统:exchange.GetCurrency()函数返回STOCK_CNY

  • 商品期货 实盘:exchange.GetCurrency()函数返回FUTURES。 回测系统:exchange.GetCurrency()函数返回FUTURES_CNY

{@fun exchange.SetCurrency}

exchange.GetQuoteCurrency

exchange.GetQuoteCurrency()函数用于获取当前交易对的计价币名称,即quoteCurrency

exchange.GetQuoteCurrency()函数返回当前交易对的计价币名称。 string

exchange.GetQuoteCurrency()

例如:国内商品期货的交易所对象返回CNY

{@fun/Account/exchange.GetCurrency exchange.GetCurrency}

Trade Futures