有人可以解释我在这里做错了吗?我试图避免在方法内键入并重新声明帐户的所有变量。
#https://github.com/nukeproof/oanda_api
require 'oanda_api'
#require 'rsruby'
require 'indicators'
def createOrder(instrument="EUR_USD",type="market",units)
order = $client.$account($acct_id).order(instrument: "EUR_USD",type: "market",side: type,units: units).create
puts "time: "+order.time+"\nprice: "+order.price+"\nid: "+order.trade_opened.id
return(order.trade_opened.id)
end
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE #bad practice...anyone who copies this code dont do this!
$acct_id=123456
$acct_token="abcd"
$client = OandaAPI::Client::TokenClient.new(:practice, $acct_token)
$account = client.account($acct_id).get
createOrder(units:1000)
错误
C:\Users\king\Desktop\_REPOS\misc\stock_analysis\forex\oanda\ruby>ruby basicnukeproof.rb
basicnukeproof.rb:7: syntax error, unexpected tGVAR, expecting '('
order = $client.$account($acct_id).order(instrument: ...
答案 0 :(得分:0)
这部分代码无效
$client.$account(...)
如果您编写$client.
,那么Ruby希望看到的下一件事是方法的名称,方法名称不能以$
开头,因此$account
无效。尝试从$account
那里删除美元符号。