Rilcon42 Rilcon42 - 1 year ago 71
Ruby Question

passing result of method as global value

Can someone explain what I am doing wrong here? I am attempting to avoid having to type and re-declare all the variables for an account inside the method.

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: "

OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE #bad practice...anyone who copies this code dont do this!

$client =, $acct_token)
$account = client.account($acct_id).get



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: ...

Answer Source

This part of the code is invalid


If you write $client., then the next thing that Ruby expects to see is the name of a method, and method names cannot begin with $ so $account is invalid. Try removing the dollar sign from $account there.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download