exchange是一个交易所对象,是策略实盘设置、回测设置中添加的第一个交易所对象,所有与交易所(这里是泛指,具体例如:商品期货市场,期货公司的前置服务器)的交互都通过这个对象的成员函数实现。
object
function main() {
// 不使用接口获取数据的测试,就无需使用exchange.IO("status")函数判断连接状态,也不用设置合约代码,因为这里仅仅是测试
Log("实盘页面或者回测页面上,添加的第一个交易所对象名字:", exchange.GetName(), ",标签:", exchange.GetLabel())
}
def main():
Log("实盘页面或者回测页面上,添加的第一个交易所对象名字:", exchange.GetName(), ",标签:", exchange.GetLabel())
void main() {
Log("实盘页面或者回测页面上,添加的第一个交易所对象名字:", exchange.GetName(), ",标签:", exchange.GetLabel());
}
{@var/EXCHANGE/exchanges exchanges}, {@fun/Account/exchange.GetName exchange.GetName}, {@fun/Account/exchange.GetLabel exchange.GetLabel}
exchanges是一个交易所对象数组,包含策略实盘设置、回测设置中添加的所有交易所对象,exchanges[0]即是{@var/EXCHANGE exchange}。 在策略实盘设置或者回测设置中添加的交易所对象,根据添加的先后顺序依次对应exchanges[0]、exchanges[1]、exchanges[2]、… exchanges[n]。
array
function main() {
// 不使用接口获取数据的测试,就无需使用exchange.IO("status")函数判断连接状态,也不用设置合约代码,因为这里仅仅是测试
for(var i = 0; i < exchanges.length; i++) {
Log("添加的交易所对象索引(第一个为0以此类推):", i, "名称:", exchanges[i].GetName(), "标签:", exchanges[i].GetLabel())
}
}
def main():
for i in range(len(exchanges)):
Log("添加的交易所对象索引(第一个为0以此类推):", i, "名称:", exchanges[i].GetName(), "标签:", exchanges[i].GetLabel())
void main() {
for(int i = 0; i < exchanges.size(); i++) {
Log("添加的交易所对象索引(第一个为0以此类推):", i, "名称:", exchanges[i].GetName(), "标签:", exchanges[i].GetLabel());
}
}
{@var/EXCHANGE exchange}, {@fun/Account/exchange.GetName exchange.GetName}, {@fun/Account/exchange.GetLabel exchange.GetLabel}
ORDER_STATE_PENDING是{@struct/Order Order}结构中的Status
属性的值,表示订单状态为未完成状态。
number
ORDER_STATE_PENDING的值为0。
{@var/ORDER_STATE/ORDER_STATE_CLOSED ORDER_STATE_CLOSED}, {@var/ORDER_STATE/ORDER_STATE_CANCELED ORDER_STATE_CANCELED}, {@var/ORDER_STATE/ORDER_STATE_UNKNOWN ORDER_STATE_UNKNOWN}
ORDER_STATE_CLOSED是{@struct/Order Order}结构中的Status
属性的值,表示订单状态为已经完成状态。
number
ORDER_STATE_CLOSED的值为1。
{@var/ORDER_STATE/ORDER_STATE_PENDING ORDER_STATE_PENDING}, {@var/ORDER_STATE/ORDER_STATE_CANCELED ORDER_STATE_CANCELED}, {@var/ORDER_STATE/ORDER_STATE_UNKNOWN ORDER_STATE_UNKNOWN}
ORDER_STATE_CANCELED是{@struct/Order Order}结构中的Status
属性的值,表示订单状态为已经取消状态。
number
ORDER_STATE_CANCELED的值为2。
{@var/ORDER_STATE/ORDER_STATE_PENDING ORDER_STATE_PENDING}, {@var/ORDER_STATE/ORDER_STATE_CLOSED ORDER_STATE_CLOSED}, {@var/ORDER_STATE/ORDER_STATE_UNKNOWN ORDER_STATE_UNKNOWN}
ORDER_STATE_UNKNOWN是{@struct/Order Order}结构中的Status
属性的值,表示订单状态为未知状态(其它状态)。
number
ORDER_STATE_UNKNOWN的值为3。
对于ORDER_STATE_UNKNOWN
状态,可以查询{@struct/Order Order}结构中的Info
字段。 这些常量名可以直接在策略代码中用于和Order结构的Status属性比较、判断是否相等从而确定订单状态。打印这些常量名会显示这些常量名对应的值,以下其它常量名同理,不再赘述。
{@var/ORDER_STATE/ORDER_STATE_PENDING ORDER_STATE_PENDING}, {@var/ORDER_STATE/ORDER_STATE_CLOSED ORDER_STATE_CLOSED}, {@var/ORDER_STATE/ORDER_STATE_CANCELED ORDER_STATE_CANCELED}
ORDER_TYPE_BUY是{@struct/Order Order}结构中的Type
属性的值,表示买单类型。
number
ORDER_TYPE_BUY的值为0。
{@var/ORDER_TYPE/ORDER_TYPE_SELL ORDER_TYPE_SELL}
ORDER_TYPE_SELL是{@struct/Order Order}结构中的Type
属性的值,表示卖单类型。
number
ORDER_TYPE_SELL的值为1。
{@var/ORDER_TYPE/ORDER_TYPE_BUY ORDER_TYPE_BUY}
PD_LONG是{@struct/Position Position}结构中的Type
属性的值,表示多头仓位(如果区分今仓、昨仓,PD_LONG表示今仓)类型。
number
PD_LONG的值为0。 对于合约市场多头持仓,使用exchange.SetDirection(“closebuy_today”)设置平仓方向,平掉该类型的持仓。
{@var/POSITION_DIRECTION/PD_SHORT PD_SHORT}, {@var/POSITION_DIRECTION/PD_LONG_YD PD_LONG_YD}, {@var/POSITION_DIRECTION/PD_SHORT_YD PD_SHORT_YD}
PD_SHORT是{@struct/Position Position}结构中的Type
属性的值,表示空头仓位(如果区分今仓、昨仓,PD_SHORT表示今仓)类型。
number
PD_SHORT的值为1。 对于合约市场空头持仓,使用exchange.SetDirection(“closesell_today”)设置平仓方向,平掉该类型的持仓。
{@var/POSITION_DIRECTION/PD_LONG PD_LONG}, {@var/POSITION_DIRECTION/PD_LONG_YD PD_LONG_YD}, {@var/POSITION_DIRECTION/PD_SHORT_YD PD_SHORT_YD}
PD_LONG_YD是{@struct/Position Position}结构中的Type
属性的值,表示昨日多头仓位类型。
number
PD_LONG_YD的值为2。 对于合约市场昨日多头持仓,使用exchange.SetDirection(“closebuy”)设置平仓方向,平掉该类型的持仓。
{@var/POSITION_DIRECTION/PD_LONG PD_LONG}, {@var/POSITION_DIRECTION/PD_SHORT PD_SHORT}, {@var/POSITION_DIRECTION/PD_SHORT_YD PD_SHORT_YD}
PD_SHORT_YD是{@struct/Position Position}结构中的Type
属性的值,表示昨日空头仓位类型。
number
PD_SHORT_YD的值为3。 对于合约市场昨日空头持仓,使用exchange.SetDirection(“closesell”)设置平仓方向,平掉该类型的持仓。
{@var/POSITION_DIRECTION/PD_LONG PD_LONG}, {@var/POSITION_DIRECTION/PD_SHORT PD_SHORT}, {@var/POSITION_DIRECTION/PD_LONG_YD PD_LONG_YD}
ORDER_OFFSET_OPEN是{@struct/Order Order}结构中的Offset
属性的值,表示订单为开仓方向。
number
ORDER_OFFSET_OPEN的值为0。
{@var/ORDER_OFFSET/ORDER_OFFSET_CLOSE ORDER_OFFSET_CLOSE}
ORDER_OFFSET_CLOSE是{@struct/Order Order}结构中的Offset
属性的值,表示订单为平仓方向。
number
ORDER_OFFSET_CLOSE的值为1。
{@var/ORDER_OFFSET/ORDER_OFFSET_OPEN ORDER_OFFSET_OPEN}
表示1分钟K线周期的常数,值为60。
number
{@fun/Market/exchange.GetRecords exchange.GetRecords}, {@var/PERIOD/PERIOD_M3 PERIOD_M3}, {@var/PERIOD/PERIOD_M5 PERIOD_M5}, {@var/PERIOD/PERIOD_M15 PERIOD_M15}, {@var/PERIOD/PERIOD_M30 PERIOD_M30}, {@var/PERIOD/PERIOD_H1 PERIOD_H1}, {@var/PERIOD/PERIOD_H2 PERIOD_H2}, {@var/PERIOD/PERIOD_H4 PERIOD_H4}, {@var/PERIOD/PERIOD_H6 PERIOD_H6}, {@var/PERIOD/PERIOD_H12 PERIOD_H12}, {@var/PERIOD/PERIOD_D1 PERIOD_D1}, {@var/PERIOD/PERIOD_D3 PERIOD_D3}, {@var/PERIOD/PERIOD_W1 PERIOD_W1}
表示3分钟K线周期的常数,值为180。
number
{@fun/Market/exchange.GetRecords exchange.GetRecords}, {@var/PERIOD/PERIOD_M1 PERIOD_M1}, {@var/PERIOD/PERIOD_M5 PERIOD_M5}, {@var/PERIOD/PERIOD_M15 PERIOD_M15}, {@var/PERIOD/PERIOD_M30 PERIOD_M30}, {@var/PERIOD/PERIOD_H1 PERIOD_H1}, {@var/PERIOD/PERIOD_H2 PERIOD_H2}, {@var/PERIOD/PERIOD_H4 PERIOD_H4}, {@var/PERIOD/PERIOD_H6 PERIOD_H6}, {@var/PERIOD/PERIOD_H12 PERIOD_H12}, {@var/PERIOD/PERIOD_D1 PERIOD_D1}, {@var/PERIOD/PERIOD_D3 PERIOD_D3}, {@var/PERIOD/PERIOD_W1 PERIOD_W1}
表示5分钟K线周期的常数,值为300。
number
{@fun/Market/exchange.GetRecords exchange.GetRecords}, {@var/PERIOD/PERIOD_M1 PERIOD_M1}, {@var/PERIOD/PERIOD_M3 PERIOD_M3}, {@var/PERIOD/PERIOD_M15 PERIOD_M15}, {@var/PERIOD/PERIOD_M30 PERIOD_M30}, {@var/PERIOD/PERIOD_H1 PERIOD_H1}, {@var/PERIOD/PERIOD_H2 PERIOD_H2}, {@var/PERIOD/PERIOD_H4 PERIOD_H4}, {@var/PERIOD/PERIOD_H6 PERIOD_H6}, {@var/PERIOD/PERIOD_H12 PERIOD_H12}, {@var/PERIOD/PERIOD_D1 PERIOD_D1}, {@var/PERIOD/PERIOD_D3 PERIOD_D3}, {@var/PERIOD/PERIOD_W1 PERIOD_W1}
表示15分钟K线周期的常数,值为900。
number
{@fun/Market/exchange.GetRecords exchange.GetRecords}, {@var/PERIOD/PERIOD_M1 PERIOD_M1}, {@var/PERIOD/PERIOD_M3 PERIOD_M3}, {@var/PERIOD/PERIOD_M5 PERIOD_M5}, {@var/PERIOD/PERIOD_M30 PERIOD_M30}, {@var/PERIOD/PERIOD_H1 PERIOD_H1}, {@var/PERIOD/PERIOD_H2 PERIOD_H2}, {@var/PERIOD/PERIOD_H4 PERIOD_H4}, {@var/PERIOD/PERIOD_H6 PERIOD_H6}, {@var/PERIOD/PERIOD_H12 PERIOD_H12}, {@var/PERIOD/PERIOD_D1 PERIOD_D1}, {@var/PERIOD/PERIOD_D3 PERIOD_D3}, {@var/PERIOD/PERIOD_W1 PERIOD_W1}
表示30分钟K线周期的常数,值为1800。
number
{@fun/Market/exchange.GetRecords exchange.GetRecords}, {@var/PERIOD/PERIOD_M1 PERIOD_M1}, {@var/PERIOD/PERIOD_M3 PERIOD_M3}, {@var/PERIOD/PERIOD_M5 PERIOD_M5}, {@var/PERIOD/PERIOD_M15 PERIOD_M15}, {@var/PERIOD/PERIOD_H1 PERIOD_H1}, {@var/PERIOD/PERIOD_H2 PERIOD_H2}, {@var/PERIOD/PERIOD_H4 PERIOD_H4}, {@var/PERIOD/PERIOD_H6 PERIOD_H6}, {@var/PERIOD/PERIOD_H12 PERIOD_H12}, {@var/PERIOD/PERIOD_D1 PERIOD_D1}, {@var/PERIOD/PERIOD_D3 PERIOD_D3}, {@var/PERIOD/PERIOD_W1 PERIOD_W1}
表示1小时K线周期的常数,值为3600。
number
{@fun/Market/exchange.GetRecords exchange.GetRecords}, {@var/PERIOD/PERIOD_M1 PERIOD_M1}, {@var/PERIOD/PERIOD_M3 PERIOD_M3}, {@var/PERIOD/PERIOD_M5 PERIOD_M5}, {@var/PERIOD/PERIOD_M15 PERIOD_M15}, {@var/PERIOD/PERIOD_M30 PERIOD_M30}, {@var/PERIOD/PERIOD_H2 PERIOD_H2}, {@var/PERIOD/PERIOD_H4 PERIOD_H4}, {@var/PERIOD/PERIOD_H6 PERIOD_H6}, {@var/PERIOD/PERIOD_H12 PERIOD_H12}, {@var/PERIOD/PERIOD_D1 PERIOD_D1}, {@var/PERIOD/PERIOD_D3 PERIOD_D3}, {@var/PERIOD/PERIOD_W1 PERIOD_W1}
表示2小时K线周期的常数,值为7200。
number
{@fun/Market/exchange.GetRecords exchange.GetRecords}, {@var/PERIOD/PERIOD_M1 PERIOD_M1}, {@var/PERIOD/PERIOD_M3 PERIOD_M3}, {@var/PERIOD/PERIOD_M5 PERIOD_M5}, {@var/PERIOD/PERIOD_M15 PERIOD_M15}, {@var/PERIOD/PERIOD_M30 PERIOD_M30}, {@var/PERIOD/PERIOD_H1 PERIOD_H1}, {@var/PERIOD/PERIOD_H4 PERIOD_H4}, {@var/PERIOD/PERIOD_H6 PERIOD_H6}, {@var/PERIOD/PERIOD_H12 PERIOD_H12}, {@var/PERIOD/PERIOD_D1 PERIOD_D1}, {@var/PERIOD/PERIOD_D3 PERIOD_D3}, {@var/PERIOD/PERIOD_W1 PERIOD_W1}
表示4小时K线周期的常数,值为14400。
number
{@fun/Market/exchange.GetRecords exchange.GetRecords}, {@var/PERIOD/PERIOD_M1 PERIOD_M1}, {@var/PERIOD/PERIOD_M3 PERIOD_M3}, {@var/PERIOD/PERIOD_M5 PERIOD_M5}, {@var/PERIOD/PERIOD_M15 PERIOD_M15}, {@var/PERIOD/PERIOD_M30 PERIOD_M30}, {@var/PERIOD/PERIOD_H1 PERIOD_H1}, {@var/PERIOD/PERIOD_H2 PERIOD_H2}, {@var/PERIOD/PERIOD_H6 PERIOD_H6}, {@var/PERIOD/PERIOD_H12 PERIOD_H12}, {@var/PERIOD/PERIOD_D1 PERIOD_D1}, {@var/PERIOD/PERIOD_D3 PERIOD_D3}, {@var/PERIOD/PERIOD_W1 PERIOD_W1}
表示6小时K线周期的常数,值为21600。
number
{@fun/Market/exchange.GetRecords exchange.GetRecords}, {@var/PERIOD/PERIOD_M1 PERIOD_M1}, {@var/PERIOD/PERIOD_M3 PERIOD_M3}, {@var/PERIOD/PERIOD_M5 PERIOD_M5}, {@var/PERIOD/PERIOD_M15 PERIOD_M15}, {@var/PERIOD/PERIOD_M30 PERIOD_M30}, {@var/PERIOD/PERIOD_H1 PERIOD_H1}, {@var/PERIOD/PERIOD_H2 PERIOD_H2}, {@var/PERIOD/PERIOD_H4 PERIOD_H4}, {@var/PERIOD/PERIOD_H12 PERIOD_H12}, {@var/PERIOD/PERIOD_D1 PERIOD_D1}, {@var/PERIOD/PERIOD_D3 PERIOD_D3}, {@var/PERIOD/PERIOD_W1 PERIOD_W1}
表示12小时K线周期的常数,值为43200。
number
{@fun/Market/exchange.GetRecords exchange.GetRecords}, {@var/PERIOD/PERIOD_M1 PERIOD_M1}, {@var/PERIOD/PERIOD_M3 PERIOD_M3}, {@var/PERIOD/PERIOD_M5 PERIOD_M5}, {@var/PERIOD/PERIOD_M15 PERIOD_M15}, {@var/PERIOD/PERIOD_M30 PERIOD_M30}, {@var/PERIOD/PERIOD_H1 PERIOD_H1}, {@var/PERIOD/PERIOD_H2 PERIOD_H2}, {@var/PERIOD/PERIOD_H4 PERIOD_H4}, {@var/PERIOD/PERIOD_H6 PERIOD_H6}, {@var/PERIOD/PERIOD_D1 PERIOD_D1}, {@var/PERIOD/PERIOD_D3 PERIOD_D3}, {@var/PERIOD/PERIOD_W1 PERIOD_W1}
表示1日K线周期的常数,值为86400。
number
{@fun/Market/exchange.GetRecords exchange.GetRecords}, {@var/PERIOD/PERIOD_M1 PERIOD_M1}, {@var/PERIOD/PERIOD_M3 PERIOD_M3}, {@var/PERIOD/PERIOD_M5 PERIOD_M5}, {@var/PERIOD/PERIOD_M15 PERIOD_M15}, {@var/PERIOD/PERIOD_M30 PERIOD_M30}, {@var/PERIOD/PERIOD_H1 PERIOD_H1}, {@var/PERIOD/PERIOD_H2 PERIOD_H2}, {@var/PERIOD/PERIOD_H4 PERIOD_H4}, {@var/PERIOD/PERIOD_H6 PERIOD_H6}, {@var/PERIOD/PERIOD_H12 PERIOD_H12}, {@var/PERIOD/PERIOD_D3 PERIOD_D3}, {@var/PERIOD/PERIOD_W1 PERIOD_W1}
表示3日K线周期的常数,值为259200。
number
{@fun/Market/exchange.GetRecords exchange.GetRecords}, {@var/PERIOD/PERIOD_M1 PERIOD_M1}, {@var/PERIOD/PERIOD_M3 PERIOD_M3}, {@var/PERIOD/PERIOD_M5 PERIOD_M5}, {@var/PERIOD/PERIOD_M15 PERIOD_M15}, {@var/PERIOD/PERIOD_M30 PERIOD_M30}, {@var/PERIOD/PERIOD_H1 PERIOD_H1}, {@var/PERIOD/PERIOD_H2 PERIOD_H2}, {@var/PERIOD/PERIOD_H4 PERIOD_H4}, {@var/PERIOD/PERIOD_H6 PERIOD_H6}, {@var/PERIOD/PERIOD_H12 PERIOD_H12}, {@var/PERIOD/PERIOD_D1 PERIOD_D1}, {@var/PERIOD/PERIOD_W1 PERIOD_W1}
表示1周K线周期的常数,值为604800。
number
{@fun/Market/exchange.GetRecords exchange.GetRecords}, {@var/PERIOD/PERIOD_M1 PERIOD_M1}, {@var/PERIOD/PERIOD_M3 PERIOD_M3}, {@var/PERIOD/PERIOD_M5 PERIOD_M5}, {@var/PERIOD/PERIOD_M15 PERIOD_M15}, {@var/PERIOD/PERIOD_M30 PERIOD_M30}, {@var/PERIOD/PERIOD_H1 PERIOD_H1}, {@var/PERIOD/PERIOD_H2 PERIOD_H2}, {@var/PERIOD/PERIOD_H4 PERIOD_H4}, {@var/PERIOD/PERIOD_H6 PERIOD_H6}, {@var/PERIOD/PERIOD_H12 PERIOD_H12}, {@var/PERIOD/PERIOD_D1 PERIOD_D1}, {@var/PERIOD/PERIOD_D3 PERIOD_D3}
LOG_TYPE_BUY是{@fun/Trade/exchange.Log exchange.Log}函数的LogType
参数可选值,设置exchange.Log
函数打印的日志为买单日志。
LOG_TYPE_BUY的值为0。
number
{@var/LOG_TYPE/LOG_TYPE_SELL LOG_TYPE_SELL}, {@var/LOG_TYPE/LOG_TYPE_CANCEL LOG_TYPE_CANCEL}
LOG_TYPE_SELL是{@fun/Trade/exchange.Log exchange.Log}函数的LogType
参数可选值,设置exchange.Log
函数打印的日志为卖单日志。
LOG_TYPE_SELL的值为1。
number
{@var/LOG_TYPE/LOG_TYPE_BUY LOG_TYPE_BUY}, {@var/LOG_TYPE/LOG_TYPE_CANCEL LOG_TYPE_CANCEL}
LOG_TYPE_CANCEL是{@fun/Trade/exchange.Log exchange.Log}函数的LogType
参数可选值,设置exchange.Log
函数打印的日志为撤销订单日志。
LOG_TYPE_CANCEL的值为2。
number
{@var/LOG_TYPE/LOG_TYPE_BUY LOG_TYPE_BUY}, {@var/LOG_TYPE/LOG_TYPE_SELL LOG_TYPE_SELL}
结构体