Sha256: 949c244348b406f728345d377a64d02a5f77f01df3a93a738da9a841c5d518f4

Contents?: true

Size: 1.91 KB

Versions: 4

Compression:

Stored size: 1.91 KB

Contents

require 'spec_helper'

describe IB::Models::Execution do

  let(:properties) do
    {:account_name => "DU111110",
     :average_price => 1.31075,
     :client_id => 1111,
     :cumulative_quantity => 20000,
     :exchange => "IDEALPRO",
     :exec_id => "0001f4e8.4f5d48f1.01.01",
     :liquidation => 0,
     :order_id => 373,
     :perm_id => 1695693613,
     :price => 1.31075,
     :shares => 20000,
     :side => :buy,
     :time => "20120312  15:41:09"
    }
  end

  context "instantiation" do
    context 'empty without properties' do
      subject { IB::Models::Execution.new }

      it { should_not be_nil }
      its(:order_id) { should == 0 }
      its(:client_id) { should == 0 }
      its(:perm_id) { should == 0 }
      its(:shares) { should == 0 }
      its(:price) { should == 0 }
      its(:liquidation) { should == 0 }
      its(:created_at) { should be_a Time }
    end

    context 'with properties' do
      subject { IB::Models::Execution.new properties }

      it 'sets properties right' do
        properties.each do |name, value|
          subject.send(name).should == value
        end
      end
    end
  end #instantiation

  context "properties" do

    it 'allows setting properties' do
      expect {
        x = IB::Models::Execution.new
        properties.each do |name, value|
          subject.send("#{name}=", value)
          subject.send(name).should == value
        end
      }.to_not raise_error
    end

    it 'sets side as directed by its setter' do
      @x = IB::Models::Execution.new
      ['BOT', 'BUY', 'Buy', 'buy', :BUY, :BOT, :Buy, :buy, 'B', :b].each do |val|
        expect { @x.side = val }.to_not raise_error
        @x.side.should == :buy
      end

      ['SELL', 'SLD', 'Sel', 'sell', :SELL, :SLD, :Sell, :sell, 'S', :S].each do |val|
        expect { @x.side = val }.to_not raise_error
        @x.side.should == :sell
      end
    end
  end # properties

end # describe IB::Models::Contract

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ib-ruby-0.7.3 spec/ib-ruby/models/execution_spec.rb
ib-ruby-0.7.2 spec/ib-ruby/models/execution_spec.rb
ib-ruby-0.7.0 spec/ib-ruby/models/execution_spec.rb
ib-ruby-0.6.1 spec/ib-ruby/models/execution_spec.rb