forked from ib-ruby/ib-ruby
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Connection API modified, unsubscribe added
- Loading branch information
Showing
12 changed files
with
108 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
require File.join(File.dirname(__FILE__), %w[.. spec_helper]) | ||
|
||
describe IB::Connection do | ||
|
||
context "new" do | ||
context 'connected by default' do | ||
# THIS depends on TWS|Gateway connectivity | ||
before(:all) { @ib = IB::Connection.new } | ||
after(:all) { @ib.close } | ||
subject { @ib } | ||
|
||
it { should_not be_nil } | ||
it { should be_connected } | ||
its (:server) {should be_a Hash} | ||
its (:subscribers) {should have_at_least(1).listener} # :NextValidID and empty Hashes | ||
its (:next_order_id) {should be_a Fixnum} # Not before :NextValidID arrives | ||
end | ||
|
||
context 'passing :open => false' do | ||
subject { IB::Connection.new :open => false } | ||
|
||
it { should_not be_nil } | ||
it { should_not be_connected } | ||
its (:server) {should be_a Hash} | ||
its (:subscribers) {should be_empty} | ||
its (:next_order_id) {should be_nil} | ||
end | ||
end #instantiation | ||
|
||
context "subscriptions" do | ||
# THIS depends on TWS|Gateway connectivity | ||
before(:all) { @ib = IB::Connection.new } | ||
after(:all) { @ib.close } | ||
|
||
it 'adds (multiple) subscribers' do | ||
@subscriber_id = @ib.subscribe(:Alert, :AccountValue) do | ||
puts "oooooooooo" | ||
end | ||
|
||
@ib.subscribers.should have_key(IB::Messages::Incoming::Alert) | ||
@ib.subscribers.should have_key(IB::Messages::Incoming::AccountValue) | ||
@ib.subscribers[IB::Messages::Incoming::Alert].should have_key(@subscriber_id) | ||
@ib.subscribers[IB::Messages::Incoming::AccountValue].should have_key(@subscriber_id) | ||
@ib.subscribers[IB::Messages::Incoming::Alert][@subscriber_id].should be_a Proc | ||
@ib.subscribers[IB::Messages::Incoming::AccountValue][@subscriber_id].should be_a Proc | ||
end | ||
|
||
it 'removes all subscribers' do | ||
@subscriber_id = @ib.unsubscribe(@subscriber_id) | ||
|
||
@ib.subscribers[IB::Messages::Incoming::Alert].should_not have_key(@subscriber_id) | ||
@ib.subscribers[IB::Messages::Incoming::AccountValue].should_not have_key(@subscriber_id) | ||
end | ||
|
||
end #subscriptions | ||
end # describe IB::Connection |