Permalink
Browse files
More specific SymbolError handling
- Loading branch information...
Showing
with
14 additions
and
16 deletions.
-
+5
−11
lib/ib/symbols.rb
-
+9
−5
spec/ib/symbols/symbols_spec.rb
|
@@ -10,7 +10,7 @@ |
|
|
# it as IB::Symbols::Stock[:wfc] anywhere you need it.
|
|
|
#
|
|
|
# Note that the :description field is local to ib-ruby, and is NOT part of the standard TWS API.
|
|
|
-# It is never transmitted to IB. It's purely used clientside, and you can store any arbitrary
|
|
|
+# It is never transmitted to IB. It's purely used clientside, and you can store any arbitrary
|
|
|
# string that you may find useful there.
|
|
|
|
|
|
module IB
|
|
@@ -19,15 +19,10 @@ def [] symbol |
|
|
if contracts[symbol]
|
|
|
return contracts[symbol]
|
|
|
else
|
|
|
- # symbol probably has not been predefined; tell user about it!
|
|
|
- msg = <<-MSG_END
|
|
|
- \n
|
|
|
- *******************************************
|
|
|
- SYMBOL ':#{symbol.to_s}' is probably not defined.
|
|
|
- Please define it in lib/ib/symbols/
|
|
|
- *******************************************
|
|
|
- MSG_END
|
|
|
- raise RuntimeError, msg
|
|
|
+ # symbol probably has not been predefined, tell user about it
|
|
|
+ file = self.to_s.split(/::/).last.downcase
|
|
|
+ msg = "Unknown symbol :#{symbol}, please pre-define it in lib/ib/symbols/#{file}.rb"
|
|
|
+ error msg, :symbol
|
|
|
end
|
|
|
end
|
|
|
end
|
|
@@ -37,4 +32,3 @@ def [] symbol |
|
|
require 'ib/symbols/futures'
|
|
|
require 'ib/symbols/stocks'
|
|
|
require 'ib/symbols/options'
|
|
|
-
|
|
@@ -45,11 +45,15 @@ |
|
|
fx.description.should == "British Pounds"
|
|
|
end
|
|
|
|
|
|
- it 'raises an error if contract symbol is not defined' do
|
|
|
- lambda{stk = IB::Symbols::Stocks[:xyz]}.should raise_error RuntimeError
|
|
|
- lambda{opt = IB::Symbols::Options[:xyz20]}.should raise_error RuntimeError
|
|
|
- lambda{fx = IB::Symbols::Forex[:abcdef]}.should raise_error RuntimeError
|
|
|
- lambda{fut = IB::Symbols::Futures[:abc]}.should raise_error RuntimeError
|
|
|
+ it 'raises an error if requested contract symbol is not defined' do
|
|
|
+ expect {stk = IB::Symbols::Stocks[:xyz]}.
|
|
|
+ to raise_error "Unknown symbol :xyz, please pre-define it in lib/ib/symbols/stocks.rb"
|
|
|
+ expect {opt = IB::Symbols::Options[:xyz20]}.
|
|
|
+ to raise_error "Unknown symbol :xyz20, please pre-define it in lib/ib/symbols/options.rb"
|
|
|
+ expect {fx = IB::Symbols::Forex[:abcdef]}.
|
|
|
+ to raise_error "Unknown symbol :abcdef, please pre-define it in lib/ib/symbols/forex.rb"
|
|
|
+ expect {fut = IB::Symbols::Futures[:abc]}.
|
|
|
+ to raise_error "Unknown symbol :abc, please pre-define it in lib/ib/symbols/futures.rb"
|
|
|
end
|
|
|
|
|
|
end # describe IB::Symbols
|
0 comments on commit
c88e6e1