Photon Ruby Scripting...bid event object.

2 messages Options
Embed this post
Permalink
rivercode

Photon Ruby Scripting...bid event object.

Reply Threaded More More options
Print post
Permalink
In order_sender.rb:

def on_bid(bid)

puts "Bid Size" + bid.getSize  # fails

puts "Bid Size" + bid.size # good

What am I missing ???

bid is is of type org.marketcetera.event.BidEvent.

While I am new to Ruby, I cannot figure out why bid.size works (where I can not find any "size" method) but bid.getSize fails...what am I msising ?

Thanks.
toli

Re: Photon Ruby Scripting...bid event object.

Reply Threaded More More options
Print post
Permalink
Hi,

What you are encountering is an artifact of Ruby vs. JRuby.

We are using JRuby, which gives you Ruby-like access to any Java
method, ie you can access everything that's in the form getXYZ() as
just XYZ, although getXYZ and getXYZ() works as well.  Hence the
magical "size" function instead of 'getSize'

The problem that you've encountered is that Ruby by default doesn't
call its equivalent of toString() on all objects when you print them.
BidEvent.getSize() returns you a BigDecimal - the right way to add a
.to_s at the end:
> puts "Bid Size" + bid.getSize.to_s

Otherwise, I get the following error:
15:24:48,831  WARN - Error executing RUBY Strategy
MarketData(metc:strategy:system:strategyMarketData3) in on_bid: can't
convert Java::JavaMath::BigDecimal into String :1:in `on_bid':1

Note that Ruby has another nifty feature that lets you access
variables directly from within a printed string using the #{varname}
semantics. In that case, it seems that it calls .to_s on the object
for you:

puts "Bid Size is #{bid.getSize}" or
puts "Bid Size #{bid.size}"

Hope this clarifies things a bit.

On Fri, Jan 2, 2009 at 2:59 PM, rivercode <[hidden email]> wrote:

>
> In order_sender.rb:
>
> def on_bid(bid)
>
> puts "Bid Size" + bid.getSize  # fails
>
> puts "Bid Size" + bid.size # good
>
> What am I missing ???
>
> bid is is of type org.marketcetera.event.BidEvent.
>
> While I am new to Ruby, I cannot figure out why bid.size works (where I can
> not find any "size" method) but bid.getSize fails...what am I msising ?
>
> Thanks.
>
> --
> View this message in context: http://n2.nabble.com/Photon-Ruby-Scripting...bid-event-object.-tp2103706p2103706.html
> Sent from the m-etc-dev mailing list archive at Nabble.com.
>
>
> _______________________________________________
> m-etc-dev mailing list
> [hidden email]
> http://lists.marketcetera.org/mailman/listinfo/m-etc-dev_lists.marketcetera.org
>



--
Toli Kuznets
http://www.marketcetera.com: Open-Source Trading Platform
download.run.trade.

_______________________________________________
m-etc-dev mailing list
[hidden email]
http://lists.marketcetera.org/mailman/listinfo/m-etc-dev_lists.marketcetera.org