The resource loading... loading...

Please teach me to dream

Author: Neo1898, Created: 2022-02-25 08:04:50, Updated: 2022-02-25 08:52:20

TypeError: cannot read property Price of null at main (FILEI'm going to change var pos = exchange.GetPosition (() to var pos = _C (((exchange.GetPosition)))), can this be solved?

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)])

More

Neo1898Change var pos = exchange.GetPosition (() to var pos = _C ((exchange.GetPosition (())), see if this can be solved, take the value and go down.

Neo1898The code near the 553 line is: var t = exchange.GetTicker ()) tbl.rows.push (([currTotalEq, realProfit, t? t.Last : "--", (buyOrder.Price + "/" + buyOrder.Amount), (sellOrder.Price + "/" + sellOrder.Amount))) If the ticker data is not taken, it is changed to var t = _C (exchange.GetTicker)) and can be done.

Neo1898Thank you, dream!

Inventors quantify - small dreamsWhat's up? tbl.rows.push (([currTotalEq, realProfit, t? t.Last : "--", (buyOrder? buyOrder.Price : "--") + "/" + (buyOrder? buyOrder.Amount :"--"), (sellOrder? sellOrder.Price "--") + "/" + (sellOrder? sellOrder.Amount : "--"))) What's up? The problem is that when buyOrder is null, don't go to buyOrder.Amount or buyOrder.Price.

Neo1898Even if there is an order, the price is numerical, but Amount always has no data and no error reports, which is strange, where is the problem?

Neo1898The situation is not ordered: change the price, change the amount, but try. tbl.rows.push (([currTotalEq, realProfit, t? t.Last : "--", (buyOrder? buyOrder.Price : "--" + "/" + buyOrder? buyOrder.Amount :"--"), (sellOrder? sellOrder.Price "--" + "/" + sellOrder? sellOrder.Amount : "--") Or TypeError: cannot read property 'Amount' of null at main (__FILE__:554), is the code not updated?

Inventors quantify - small dreamsWhen you access a property of a variable, you can decide whether the variable is null or not.

Neo1898tbl.rows.push (([currTotalEq, realProfit, t? t.Last : "--", (buyOrder? buyOrder.Price : "--" + "/" + buyOrder.Amount), (sellOrder? sellOrder.Price : "--" + "/" + sellOrder.Amount) ] It's like that up there, right?

Inventors quantify - small dreamsBuyOrder?buyOrder.Price : "--" This is done.

Inventors quantify - small dreamsIt can be passed to an empty string.

Neo1898Thank you, that's right, I didn't order some of the steps, so the order message is null, you have to allow the null input, what should I do?

Light clouds var t = _C(exchange.GetTicker)

Light cloudsThe default is var pos = _C (exchange.GetPosition).

Neo1898 tbl.rows.push,是这个不允许传入null值是吗?我有些步骤是没有下单的,所以订单信息为null,必须允许传入null,应该要怎么改呢,谢谢梦总!

Neo1898So I'm not going to order, and I'm not going to order, and I'm not going to order, and I'm not going to order, and I'm not going to order, and I'm going to order, and I'm going to order, and I'm going to order, and I'm going to order, and I'm going to order, and I'm going to order, and I'm going to order, and I'm going to order.

Inventors quantify - small dreamsIt may be that buyOrder or sellOrder is null, you can print and check.