TypeError: cannot read property 'Price' of null at main (Tập lỗi: không thể đọc thuộc tính 'Price' của null at main)FILE[553], dẫn đến chương trình thoát ra, hãy hỏi DreamHost, liệu đó là do trường tùy chỉnh bị null, hay do không có thông tin về giá, tôi sẽ thay đổi var pos = exchange.GetPosition() thành var pos = _C ((exchange.GetPosition()), có thể giải quyết được vấn đề này không; vì phản hồi mô phỏng không thể kiểm tra được lỗi này, nên phải dùng ổ cứng thực, vì vậy xin vui lòng nói chuyện với Dream Manager trước, cảm ơn!
var currTotalEq = getTotalEquity()
var pos = _C(exchange.GetPosition())
//var pos = exchange.GetPosition()
if (currTotalEq && pos) {
// LogStatus(_D(), "当前总权益:", currTotalEq, "持仓:", pos)
var tblPos = {
"type" : "table",
"title" : "持仓",
"cols" : ["持仓数量", "持仓方向", "持仓均价", "持仓盈亏", "合约代码", "自定义字段 / " + SpecifyPosField],
"rows" : []
}
var descType = ["多头仓位", "空头仓位"]
for (var posIndex = 0 ; posIndex < pos.length ; posIndex++) {
tblPos.rows.push([pos[posIndex].Amount, descType[pos[posIndex].Type], pos[posIndex].Price, pos[posIndex].Profit, pos[posIndex].ContractType, SpecifyPosField == "" ? "--" : pos[posIndex].Info[SpecifyPosField]])
}
var tbl = {
"type" : "table",
"title" : "数据",
"cols" : ["当前总权益", "实际盈亏", "当前价格", "买单价格/数量", "卖单价格/数量"],
"rows" : []
}
var buyOrder = null
var sellOrder = null
for (var orderIndex = 0 ; orderIndex < orders.length ; orderIndex++) {
if (orders[orderIndex].Type == ORDER_TYPE_BUY) {
buyOrder = orders[orderIndex]
} else {
sellOrder = orders[orderIndex]
}
}
var realProfit = currTotalEq - totalEq
if (exchange.GetName() == "Futures_Binance") {
_.each(pos, function(p) {
realProfit += parseFloat(p.Info.unRealizedProfit)
})
}
var t = exchange.GetTicker()
tbl.rows.push([currTotalEq, realProfit, t ? t.Last : "--", (buyOrder.Price + "/" + buyOrder.Amount), (sellOrder.Price + "/" + sellOrder.Amount)])
553行附近的代码是:
var t = exchange.GetTicker()
tbl.rows.push([currTotalEq, realProfit, t ? t.Last : "--", (buyOrder.Price + "/" + buyOrder.Amount), (sellOrder.Price + "/" + sellOrder.Amount)])
是否是没取到ticker数据,那改为var t = _C(exchange.GetTicker()),是否就可以了。
没有下单的情况:改了price,还得改amount,但是尝试了
tbl.rows.push([currTotalEq, realProfit, t ? t.Last : "--", (buyOrder ? buyOrder.Price : "--" + "/" + buyOrder ? buyOrder.Amount :"--"), (sellOrder ? sellOrder.Price : "--" + "/" + sellOrder ? sellOrder.Amount : "--")])
还是报TypeError: cannot read property 'Amount' of null at main (FILE:554),是代码没更新吗?还是哪里有错?
tbl.rows.push([currTotalEq, realProfit, t ? t.Last : "--", (buyOrder ? buyOrder.Price : "--") + "/" + (buyOrder ? buyOrder.Amount :"--"), (sellOrder ? sellOrder.Price : "--") + "/" + (sellOrder ? sellOrder.Amount : "--")])
问题总之就是,让buyOrder是null的时候,不要去访问buyOrder.Amount 或者 buyOrder.Price 就不会报错了。
- 1

