【问题标题】:ReferenceError: handle is not defined at vm.js:1:1 (I have absolutely no clue)ReferenceError: handle is not defined at vm.js:1:1 (我完全不知道)
【发布时间】:2019-11-04 05:37:52
【问题描述】:

我完全被卡住了。我需要一双额外的眼睛。我试着看看这个,我只是不知所措。我应该做些什么?我会在 cryptotrader 寻求帮助,但他们会表现得好像我很愚蠢,因为我没有神奇地知道答案。是我打错字还是怎么的?另外,我需要继续输入,这样我才能发帖,因为它认为它主要是代码。

trading = require "trading"
params = require "params"
talib = require "talib"

invest = params.add "Invest Amount in asset",.001
distance = params.add "Price change in asset",50
fees = params.add "Percentage of fees",.0025

init: ->
handle: ->
    instrument=data.instruments[0]
    asset = @portfolios[instrument.market].positions[instrument.asset()].amount
    base = @portfolios[instrument.market].positions[instrument.base()].amount/_.last(instrument.close)
    InsClose=_.last(instrument.close)
    balance=(base+asset)*InsClose
    storage.price?=InsClose
    if InsClose>(storage.price+distance)
        if asset/(1-fees)>=invest
            trading.sell(instrument,'limit',invest,InsClose)
            storage.price=storage.price+distance
            debug “Balance #{balance}”
    if InsClose<(storage.price-distance)
        if base/(1-fees)>=invest
            trading.buy(instrument,'limit',invest,InsClose)
            storage.price=storage.price-distance
            debug “Balance #{balance}”
    sellprice=storage.price+distance
    buyprice=storage.price-distance
    plot:
        sellprice:sellprice
        buyprice:buyprice

【问题讨论】:

    标签: coffeescript referenceerror


    【解决方案1】:

    该错误可能是因为您使用 init 和 handle 方法定义了一个匿名对象,现在任何其他代码都无法访问该对象:

    init: ->
    handle: ->
    

    编译为:

    ({
      init: function() {},
      handle: function() {}
    });
    

    你可能想要这个:

    init = ->
    handle = ->
    

    编译为:

    var handle, init;
    
    init = function() {};
    handle = function() {};
    

    如果这没有帮助,请在您调用句柄方法的地方发布代码。如果它在不同的文件中,请包括您如何导出和导入/需要其他文件。

    【讨论】:

      【解决方案2】:

      实际上,我忘记定义订单在到期前需要生效多长时间。这里写的是trading.buy或trading.sell,我需要在括号中多加一个参数。

      【讨论】:

        猜你喜欢
        • 2017-09-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-12-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-01-15
        相关资源
        最近更新 更多