测试下单功能
2021-09-15 10:24:50 0 举报
AI智能生成
测试
作者其他创作
大纲/内容
操作指南
td
td路径
/root/axe/octopus/build/bin
启动命令
./trader
kungfu strategy
所在容器
axe23
策略py文件在宿主机上路径
/opt/data/strategy/test2/v1.1.1rc23_tdbybit/test.py
启动命令
docker exec -it axe23 /bin/bash
/opt/data/kungfu/kungfu/kungfu/core/build/kfc/kfc -H /opt/data/kungfu/test3 strategy -n risk_demo -p /opt/data/strategy/test.py
/opt/data/kungfu/kungfu/kungfu/core/build/kfc/kfc -H /opt/data/kungfu/test3 strategy -n risk_demo -p /opt/data/strategy/test.py
1.设置好配置
2启动td
3在容器axe23里启动strategy
2启动td
3在容器axe23里启动strategy
更改配置
td下单器配置
配置服务地址:/root/axe/gocode/test3.go
修改td下单器配置:
举例 :curl "http://127.0.0.1:10943/api/v1/change-exch-product?exch=7&&product=5&&api_key=f23682a356e0ffdf814c8e75599bdf291d1fae8d78f17537b640f7ae5b4195b7&&secret_key=02c20530bd9f700b825e5e4f22967f8febaa004aedf38a46ee73193c358c95c4"
可以修改exch(交易所)、product(产品类型)、api_key、secret_key
exch的枚举
enum Exch
{
ExchUnknown = 0;
ExchBitmex = 1;
ExchOkex = 2;
ExchBybit = 3;
ExchBitstamp = 4;
ExchCoinbasePro = 5;
ExchKraken = 6;
ExchBinance = 7;
ExchHuobiGlobal = 8;
ExchPhemex = 9;
ExchBybitCross = 10;
ExchFtx = 11;
ExchDeribit = 12;
ExchKucoin = 13;
ExchGateio = 14;
ExchHotbit = 15;
ExchMxc = 16;
}
{
ExchUnknown = 0;
ExchBitmex = 1;
ExchOkex = 2;
ExchBybit = 3;
ExchBitstamp = 4;
ExchCoinbasePro = 5;
ExchKraken = 6;
ExchBinance = 7;
ExchHuobiGlobal = 8;
ExchPhemex = 9;
ExchBybitCross = 10;
ExchFtx = 11;
ExchDeribit = 12;
ExchKucoin = 13;
ExchGateio = 14;
ExchHotbit = 15;
ExchMxc = 16;
}
product的枚举
enum product
{ProductUnknown = 0,
ProductSpot = 1,
ProductUSDTFuture = 2,
ProductCoinFuture = 3,
ProductUSDTSwap = 4,
ProductCoinSwap = 5,
ProductOption = 6}
{ProductUnknown = 0,
ProductSpot = 1,
ProductUSDTFuture = 2,
ProductCoinFuture = 3,
ProductUSDTSwap = 4,
ProductCoinSwap = 5,
ProductOption = 6}
目前支持的exch和product
binance(exch:7)
ProductUSDTSwap(4)
ProductCoinSwap(5)
ProductUSDTFuture(2)
ProductCoinFuture(3)
ProductSpot(1)
ftx(exch:11)
ProductCoinSwap(5)
ProductCoinFuture(3)
查询td下单器的配置
curl "http://127.0.0.1:10943/api/v1/open/stg-external"
策略配置
sid(内部交易symbol的id)
[
{
"sid": 10000,
"exch": 7,
"product": 4,
"symbol": "BTCUSDT",
"name": "binance_swap_BTCUSDT"
},
{
"sid": 10001,
"exch": 7,
"product": 5,
"symbol": "BTCUSD_PERP",
"name": "binance_swap_BTCUSD_PERP"
},
{
"sid": 10002,
"exch": 7,
"product": 2,
"symbol": "BTCUSDT_210924",
"name": "binance_future_BTCUSDT_210924"
},
{
"sid": 10003,
"exch": 7,
"product": 3,
"symbol": "BTCUSD_210924",
"name": "binance_future_BTCUSD_210924"
},
{
"sid": 10004,
"exch": 7,
"product": 1,
"symbol": "BTCUSDT",
"name": "binance_spot_BTCUSDT"
},
{
"sid": 10010,
"exch": 11,
"product": 5,
"symbol": "DOGE-PREP",
"name": "ftx_coinswap_DOGE_PREP"
},
{
"sid": 10010,
"exch": 11,
"product": 3,
"symbol": "DOGE-0924",
"name": "ftx_coinfuture_DOGE_0924"
}
]
{
"sid": 10000,
"exch": 7,
"product": 4,
"symbol": "BTCUSDT",
"name": "binance_swap_BTCUSDT"
},
{
"sid": 10001,
"exch": 7,
"product": 5,
"symbol": "BTCUSD_PERP",
"name": "binance_swap_BTCUSD_PERP"
},
{
"sid": 10002,
"exch": 7,
"product": 2,
"symbol": "BTCUSDT_210924",
"name": "binance_future_BTCUSDT_210924"
},
{
"sid": 10003,
"exch": 7,
"product": 3,
"symbol": "BTCUSD_210924",
"name": "binance_future_BTCUSD_210924"
},
{
"sid": 10004,
"exch": 7,
"product": 1,
"symbol": "BTCUSDT",
"name": "binance_spot_BTCUSDT"
},
{
"sid": 10010,
"exch": 11,
"product": 5,
"symbol": "DOGE-PREP",
"name": "ftx_coinswap_DOGE_PREP"
},
{
"sid": 10010,
"exch": 11,
"product": 3,
"symbol": "DOGE-0924",
"name": "ftx_coinfuture_DOGE_0924"
}
]
td下单器的配置需要和策略里的sid配置相匹配
下单
下单函数
context.ReqInsertOrder(acct,context.InsertOrder)
下单结构体
InsertOrder
struct InsertOrder
{
uint32_t logicAccountId_;//内部交易账号
uint32_t sid_;//内部symbolId
uint64_t clientOrderId_;//自定义委托单号 //algo_Id+connecttime+increaseid(algo_id+连接时间+自增ID)
double price_;//价格
double qty_;//数量
Side side_;//买卖方向
OrderType orderType_;//报单类型
Offset offset_;//开平方向
TimeInForce timeInForce_;//报单有效时间类型
}__attribute__((packed));
{
uint32_t logicAccountId_;//内部交易账号
uint32_t sid_;//内部symbolId
uint64_t clientOrderId_;//自定义委托单号 //algo_Id+connecttime+increaseid(algo_id+连接时间+自增ID)
double price_;//价格
double qty_;//数量
Side side_;//买卖方向
OrderType orderType_;//报单类型
Offset offset_;//开平方向
TimeInForce timeInForce_;//报单有效时间类型
}__attribute__((packed));
相关枚举
//买卖方向
enum class Side : int8_t
{
//未知0
Unknown,
//买1
Buy,
//卖2
Sell
};
//买卖方向
enum class Side : int8_t
{
//未知0
Unknown,
//买1
Buy,
//卖2
Sell
};
//报单类型
enum class OrderType : int8_t
{
//限价0
Limit,
//市价1
Market,
//限价止损2
StopLimit,
//市价止损3
StopMarket,
//限价止盈4
TakeProfitLimit,
//市价止盈5
TakeProfitMarket
};
enum class OrderType : int8_t
{
//限价0
Limit,
//市价1
Market,
//限价止损2
StopLimit,
//市价止损3
StopMarket,
//限价止盈4
TakeProfitLimit,
//市价止盈5
TakeProfitMarket
};
//开平方向
enum class Offset : int8_t
{
//未知0
Unknown,
//开仓1
Open,
//平仓2
Close
};
enum class Offset : int8_t
{
//未知0
Unknown,
//开仓1
Open,
//平仓2
Close
};
//报单有效时间类型
enum class TimeInForce : int8_t
{
//一直挂单直到成交0
GTC,
//立即成交或取消1
IOC,
//完全成交或取消2
FOK,
//只挂单3
PO
};
enum class TimeInForce : int8_t
{
//一直挂单直到成交0
GTC,
//立即成交或取消1
IOC,
//完全成交或取消2
FOK,
//只挂单3
PO
};
下单举例
context.InsertOrder.logicAccountId_=1;
context.InsertOrder.sid_ = 10000
context.InsertOrder.qty_ = 0.001
context.InsertOrder.price_ = 35000
context.InsertOrder.side_ = Side.Buy
context.InsertOrder.offset_ = Offset.Open
context.InsertOrder.orderType_ = OrderType.Limit
context.InsertOrder.timeInForce_ =TimeInForce.GTC
context.InsertOrder.clientOrderId_ = 1
context.ReqInsertOrder(acct,context.InsertOrder)
context.InsertOrder.sid_ = 10000
context.InsertOrder.qty_ = 0.001
context.InsertOrder.price_ = 35000
context.InsertOrder.side_ = Side.Buy
context.InsertOrder.offset_ = Offset.Open
context.InsertOrder.orderType_ = OrderType.Limit
context.InsertOrder.timeInForce_ =TimeInForce.GTC
context.InsertOrder.clientOrderId_ = 1
context.ReqInsertOrder(acct,context.InsertOrder)
回调函数
下单响应函数rsp_insert_order(event,RspInsertOrder)
下单响应结构体RspInsertOrder
struct RspInsertOrder
{
uint32_t sid_; //内部symbolId
char orderId_[36];//交易所报单号
uint64_t clientOrderId_;//自定义委托单号
OrderStatus orderStatus_;//报单状态
int64_t insertTsE9_;//下单时间的纳秒时间戳
int32_t insertOrderLimitCount_;//剩余可下单次数
uint16_t errCode_; //订单是否成功
}__attribute__((packed));
{
uint32_t sid_; //内部symbolId
char orderId_[36];//交易所报单号
uint64_t clientOrderId_;//自定义委托单号
OrderStatus orderStatus_;//报单状态
int64_t insertTsE9_;//下单时间的纳秒时间戳
int32_t insertOrderLimitCount_;//剩余可下单次数
uint16_t errCode_; //订单是否成功
}__attribute__((packed));
相关枚举
//报单状态
enum class OrderStatus : int8_t
{
//未知0
Unknown,
//等待报入1
PendingNew,
//等待撤单2
PendingCancel,
//已报入3
New,
//部分成交4
PartiallyFilled,
//全部成交5
Filled,
//已撤单6
Cancelled,
//已拒单7
Rejected,
//Trade Server内部拒单8
InternalRejected,
Error
};
enum class OrderStatus : int8_t
{
//未知0
Unknown,
//等待报入1
PendingNew,
//等待撤单2
PendingCancel,
//已报入3
New,
//部分成交4
PartiallyFilled,
//全部成交5
Filled,
//已撤单6
Cancelled,
//已拒单7
Rejected,
//Trade Server内部拒单8
InternalRejected,
Error
};
报单变化和成交的推送函数on_order
报单(包含成交)的结构体Order
struct Order
{
uint32_t logicAccountId_;//内部交易账号
uint32_t sid_;//内部symbol_id
Side side_;//买卖方向
OrderStatus orderStatus_;//报单状态
OrderType orderType_;//报单类型
Offset offset_;//开平方向
TimeInForce timeInForce_;//报单有效时间类型
PositionSide positionSide_;//持仓方向
MarginMode marginMode_;//保证金模式
double orderPrice_;//价格
double originQty_;//委托量
double execPrice_;//最近成交价
double execQty_;//最近成交量
double fee_;//手续费
double cumExecQty_;//累计成交量
double avgExecPrice_;//平均成交价
char orderId_[36];//交易所委托单号
char tradeId_[36];//成交号
uint64_t clientOrderId_;//自定义委托单号
int64_t insertTsE9_;//下单时间的纳秒时间戳
int64_t updateTsE9_;//报单最近更新时间的纳秒时间戳
int64_t execTsE9_;//最近一次成交时间的纳秒时间戳
}__attribute__((packed));
{
uint32_t logicAccountId_;//内部交易账号
uint32_t sid_;//内部symbol_id
Side side_;//买卖方向
OrderStatus orderStatus_;//报单状态
OrderType orderType_;//报单类型
Offset offset_;//开平方向
TimeInForce timeInForce_;//报单有效时间类型
PositionSide positionSide_;//持仓方向
MarginMode marginMode_;//保证金模式
double orderPrice_;//价格
double originQty_;//委托量
double execPrice_;//最近成交价
double execQty_;//最近成交量
double fee_;//手续费
double cumExecQty_;//累计成交量
double avgExecPrice_;//平均成交价
char orderId_[36];//交易所委托单号
char tradeId_[36];//成交号
uint64_t clientOrderId_;//自定义委托单号
int64_t insertTsE9_;//下单时间的纳秒时间戳
int64_t updateTsE9_;//报单最近更新时间的纳秒时间戳
int64_t execTsE9_;//最近一次成交时间的纳秒时间戳
}__attribute__((packed));
下单场景
下单成功
回调rsp_insert_order
insert_order.errCode_为0
回调on_order
order.status_为New
下单失败
回调rsp_insert_order
insert_order.errCode不为0
成交
回调on_order
order.trade_id不为0
撤单
撤单函数
context.cancel_order(acct,context.CancelOrder)
撤单结构体
CancelOrder
//撤单
struct CancelOrder
{
uint32_t logicAccountId_;//内部交易账号
uint32_t sid_;//内部symbolId
char orderId_[36];//交易所报单号
uint64_t clientOrderId_;//algo自定义的报单号
}__attribute__((packed));
struct CancelOrder
{
uint32_t logicAccountId_;//内部交易账号
uint32_t sid_;//内部symbolId
char orderId_[36];//交易所报单号
uint64_t clientOrderId_;//algo自定义的报单号
}__attribute__((packed));
撤单举例
context.CancelOrder.sid_ = 10000
context.CancelOrder.logicAccountId_ = 1
context.CancelOrder.clientOrderId_ =1
context.CancelOrder.orderId_ = "1"
context.cancel_order(acct,context.CancelOrder)
context.CancelOrder.logicAccountId_ = 1
context.CancelOrder.clientOrderId_ =1
context.CancelOrder.orderId_ = "1"
context.cancel_order(acct,context.CancelOrder)
回调函数
撤单响应函数rsp_cancel_order
撤单响应结构体RspCancelOrder
struct RspCancelOrder
{
uint32_t sid_;//内部symbol的ID
char orderId_[36];//交易所报单号
uint64_t clientOrderId_;//自定义委托单号
uint64_t errCode_;//error
}__attribute__((packed));
{
uint32_t sid_;//内部symbol的ID
char orderId_[36];//交易所报单号
uint64_t clientOrderId_;//自定义委托单号
uint64_t errCode_;//error
}__attribute__((packed));
撤单场景
撤单成功
回调rsp_cancel_order
errCode_为0
回调on_order
status为canceled
撤单失败
回调rsp_cancel_order
errCode不为0
0 条评论
下一页