ib-symbols 1.0 → 1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5dcaabf70cf9ccf59300a44e3bea6b4f3bb71a29530a2487f25a3abfb3d5e7f3
4
- data.tar.gz: cbb25b2f3a24baab903fdf98fd2591f849048e280d819b7c17b8b1838318470f
3
+ metadata.gz: 93d49cee4065b18e73400f1b50aa3e00916b6a45b7ab3f771527133c6f29f0cc
4
+ data.tar.gz: 6eba3b4925ccdf65ab725099038a84163375ead601854a7cb42281f68fa7d555
5
5
  SHA512:
6
- metadata.gz: 6b66ab926b8322dfbf3e19a85c21f7e8e7a57784fbc85774b92afaf1813e84f8f83c0ab94c0537ff0952aa53e7719dce8e2f9e3ffe5efaca1cb55a4ba22e96d7
7
- data.tar.gz: ba673e891a08a3f8b1adc82b9ff955007ffdb61ab69d3e5b64bad0d8aed444cb2a9e6f6b8525d53f17fe8b0d7900c62eaedc8b8022fdebf16056ee2c1983623e
6
+ metadata.gz: 72ea734bd5c525f6740b5062d300f584f7565c2ec817117a914fca465d0f4e094226d4da226016e8c2985918933e45f7218c650a02a3220246048bda8bc27aa7
7
+ data.tar.gz: 0e191f18cf53cd6cb88fc728dabf97c3d395218ffecea485d104940b03f4e055e9fe0c250f42344d096d5ca44b073ad4cdd52ee6213588efc5280db416a4b606
data/README.md CHANGED
@@ -1,11 +1,18 @@
1
- # ib-symbols
1
+ # IB-Symbols
2
2
 
3
- Predefined symbols and watchlists for contracts
3
+ ---
4
+ __Documentation: [https://ib-ruby.github.io/ib-doc/](https://ib-ruby.github.io/ib-doc/)__
5
+
6
+ __Questions, Contributions, Remarks: [Discussions are opened in ib-api](https://github.com/ib-ruby/ib-api/discussions)__
7
+
8
+ ---
9
+
10
+ __Predefined symbols and watchlists for contracts__
4
11
 
5
- to activate use
12
+ To activate use
6
13
 
7
14
  ```
8
- gem 'ib-symbols', git: 'https://github.com/ib-ruby/ib-symbols.git'
15
+ gem 'ib-symbols'
9
16
  ```
10
17
  in the Gemfile and
11
18
  ```
data/ib-symbols.gemspec CHANGED
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
27
27
  spec.require_paths = ["lib"]
28
28
 
29
29
  spec.add_dependency "ib-api"
30
- spec.add_dependency "ox"
30
+ # spec.add_dependency "ox"
31
31
  spec.add_development_dependency "bundler", "~> 2.0"
32
32
  spec.add_development_dependency "rspec", "~> 3.0"
33
33
  spec.add_development_dependency 'rspec-collection_matchers'
@@ -1,23 +1,22 @@
1
1
  module IB
2
2
 
3
3
  # reopen the contract-class and add yml_file
4
- class Contract
4
+ class Contract
5
5
 
6
6
  # Reading Contract-Defaults
7
- #
7
+ #
8
8
  # by default, the yml-file in the base-directory (ib-ruby) is used.
9
9
  # This method can be overloaded to include a file from a different location
10
- #
10
+ #
11
11
  # IB::Symbols::Stocks.wfc.yml_file
12
12
  # => "/home/ubuntu/workspace/ib-ruby/contract_config.yml"
13
13
  #
14
- def yml_file
15
- File.expand_path('../../../../contract_config.yml',__FILE__ )
16
- end
17
- end
18
-
14
+ def yml_file
15
+ File.expand_path('../../../../contract_config.yml',__FILE__ )
16
+ end
17
+ end
19
18
 
20
- module Symbols
19
+ module Symbols
21
20
 
22
21
  =begin
23
22
  Creates a Class and associates it with a filename
@@ -26,45 +25,45 @@ raises an IB::Error in case of a conflict with existing class-names
26
25
  =end
27
26
 
28
27
  # set the Pathname to "ib-api/symbols" by default
29
- @@dir= Pathname.new File.expand_path("../../../../symbols/", __FILE__ )
30
- def self.set_origin directory
31
- p = Pathname.new directory
32
- @@dir = p if p.directory?
33
- rescue Errno::ENOENT
34
- error "Setting up origin for symbol-files --> Directory (#{directory}) does not exist"
35
- end
28
+ @@dir= Pathname.new File.expand_path("../../../../symbols/", __FILE__ )
29
+ def self.set_origin directory
30
+ p = Pathname.new directory
31
+ @@dir = p if p.directory?
32
+ rescue Errno::ENOENT
33
+ error "Setting up origin for symbol-files --> Directory (#{directory}) does not exist"
34
+ end
36
35
 
37
- def self.allocate_collection name # name might be a string or a symbol
38
- symbol_table = Module.new do
39
- extend Symbols
40
- extend Enumerable
41
- def self.yml_file
42
- @@dir + name.to_s.downcase.split("::").last.concat( ".yml" )
43
- end
44
-
45
- def self.each &b
46
- contracts.values.each &b
47
- end
48
- end # module new
49
- name = name.to_s.camelize.to_sym
50
- the_collection = if Symbols.send :const_defined?, name
51
- Symbols.send :const_get, name
52
- else
53
- Symbols.const_set name, symbol_table
54
- end
55
- if the_collection.is_a? Symbols
56
- the_collection.send :read_collection if the_collection.all.empty?
57
- the_collection # return_value
58
- else
59
- error "#{the_collection} is already a Class"
60
- nil
36
+ def self.allocate_collection name # name might be a string or a symbol
37
+ symbol_table = Module.new do
38
+ extend Symbols
39
+ extend Enumerable
40
+ def self.yml_file
41
+ @@dir + name.to_s.downcase.split("::").last.concat( ".yml" )
61
42
  end
62
- end
63
43
 
64
- def purge_collection
65
- yml_file.delete
66
- @contracts = nil
44
+ def self.each &b
45
+ contracts.values.each &b
46
+ end
47
+ end # module new
48
+ name = name.to_s.camelize.to_sym
49
+ the_collection = if Symbols.send :const_defined?, name
50
+ Symbols.send :const_get, name
51
+ else
52
+ Symbols.const_set name, symbol_table
53
+ end
54
+ if the_collection.is_a? Symbols
55
+ the_collection.send :read_collection if the_collection.all.empty?
56
+ the_collection # return_value
57
+ else
58
+ error "#{the_collection} is already a Class"
59
+ nil
67
60
  end
61
+ end
62
+
63
+ def purge_collection
64
+ yml_file.delete
65
+ @contracts = nil
66
+ end
68
67
 
69
68
  =begin
70
69
  cuts the Collection in `bunch_count` pieces. Each bunch is delivered to the block.
@@ -73,65 +72,65 @@ Sleeps for `sleeping time` between processing bunches
73
72
 
74
73
  Returns count of created bunches
75
74
  =end
76
- def bunch( bunch_count = 50 , sleeping_time = 1)
77
- en = self.each
78
- the_size = en.size
79
- i = 0
80
- loop do
81
- the_start = i * bunch_count
82
- the_end = the_start + bunch_count
83
- the_end = the_size -1 if the_end >= the_size
84
- it = the_start .. the_end
85
- yield it.map{|x| en.next rescue nil}.compact
86
- break if the_end == the_size -1
87
- i+=1
88
- sleep sleeping_time
89
- end
90
- i -1 # return counts of bunches
91
- end
75
+ def bunch( bunch_count = 50 , sleeping_time = 1)
76
+ en = self.each
77
+ the_size = en.size
78
+ i = 0
79
+ loop do
80
+ the_start = i * bunch_count
81
+ the_end = the_start + bunch_count
82
+ the_end = the_size -1 if the_end >= the_size
83
+ it = the_start .. the_end
84
+ yield it.map{|x| en.next rescue nil}.compact
85
+ break if the_end == the_size -1
86
+ i+=1
87
+ sleep sleeping_time
88
+ end
89
+ i -1 # return counts of bunches
90
+ end
92
91
 
93
- def read_collection
94
- if yml_file.exist?
95
- contracts.merge! YAML.load_file yml_file rescue contracts
96
- else
92
+ def read_collection
93
+ if yml_file.exist?
94
+ contracts.merge! YAML.load_file yml_file rescue contracts
95
+ else
97
96
  yml_file.open( "w"){}
98
- end
99
97
  end
98
+ end
100
99
 
101
- def store_collection
102
- yml_file.open( 'w' ){|f| f.write @contracts.to_yaml}
103
- end
100
+ def store_collection
101
+ yml_file.open( 'w' ){|f| f.write @contracts.to_yaml}
102
+ end
104
103
 
105
- def add_contract symbol, contract
106
- if symbol.is_a? String
107
- symbol.to_sym
108
- elsif symbol.is_a? Symbol
109
- symbol
110
- else
111
- symbol.to_i
112
- end
113
- # ensure that evey Sybmol::xxx.yyy entry has a description
114
- contract.description = contract.to_human[1..-2] if contract.description.nil?
115
- # overwrite contract if existing
116
- contracts[ symbol ] = contract.essential
117
- store_collection
104
+ def add_contract symbol, contract
105
+ if symbol.is_a? String
106
+ symbol.to_sym
107
+ elsif symbol.is_a? Symbol
108
+ symbol
109
+ else
110
+ symbol.to_i
118
111
  end
112
+ # ensure that evey Sybmol::xxx.yyy entry has a description
113
+ contract.description = contract.to_human[1..-2] if contract.description.nil?
114
+ # overwrite contract if existing
115
+ contracts[ symbol ] = contract.essential
116
+ store_collection
117
+ end
119
118
 
120
- def remove_contract symbol
121
- @contracts.delete symbol
122
- store_collection
123
- end
119
+ def remove_contract symbol
120
+ @contracts.delete symbol
121
+ store_collection
122
+ end
124
123
 
125
124
 
126
- def to_human
127
- self.to_s.split("::").last
128
- end
125
+ def to_human
126
+ self.to_s.split("::").last
127
+ end
129
128
 
130
129
 
131
130
 
132
- module Unspecified
133
- extend Symbols
134
- end
131
+ module Unspecified
132
+ extend Symbols
133
+ end
135
134
 
136
- end # module Symbols
135
+ end # module Symbols
137
136
  end # module IB
@@ -73,6 +73,18 @@ module IB
73
73
  :currency => "USD",
74
74
  :multiplier => 50,
75
75
  :description => "E-Mini S&P 500 future"),
76
+ :micro_es => IB::Future.new(:symbol => "MES",
77
+ :expiry => next_expiry,
78
+ :exchange => "GLOBEX",
79
+ :currency => "USD",
80
+ :multiplier => 5,
81
+ :description => "Micro E-Mini S&P 500 future"),
82
+ :micro_russell => IB::Future.new(:symbol => "M2K",
83
+ :expiry => next_expiry,
84
+ :exchange => "GLOBEX",
85
+ :currency => "USD",
86
+ :multiplier => 5,
87
+ :description => "Micro E-Mini Russell 2000 future"),
76
88
  :zn => IB::Future.new( symbol: 'ZN',
77
89
  expiry: next_expiry,
78
90
  currency: 'USD',
@@ -1,5 +1,5 @@
1
1
  module IB
2
2
  module Symbols
3
- VERSION = "1.0"
3
+ VERSION = "1.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ib-symbols
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.0'
4
+ version: '1.1'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hartmut Bischoff
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-11-04 00:00:00.000000000 Z
11
+ date: 2021-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ib-api
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: ox
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: bundler
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -142,17 +128,6 @@ files:
142
128
  - bin/console.yml
143
129
  - bin/setup
144
130
  - build.md
145
- - examples/contract_details
146
- - examples/contract_sample_details
147
- - examples/contract_samples.rb
148
- - examples/depth_of_market
149
- - examples/head_time_stamp
150
- - examples/historic_data
151
- - examples/market_data
152
- - examples/option_data
153
- - examples/real_time_data
154
- - examples/snapshot_market_data
155
- - examples/time_and_sales
156
131
  - ib-symbols.gemspec
157
132
  - lib/ib/symbols.rb
158
133
  - lib/ib/symbols/abstract.rb
@@ -189,7 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
189
164
  - !ruby/object:Gem::Version
190
165
  version: '0'
191
166
  requirements: []
192
- rubygems_version: 3.0.4
167
+ rubygems_version: 3.2.3
193
168
  signing_key:
194
169
  specification_version: 4
195
170
  summary: Predefined symbols and watchlist, part of ib-ruby
@@ -1,71 +0,0 @@
1
- #!/usr/bin/env ruby
2
- #
3
- # This script gets details for specific contract from IB
4
-
5
- require 'bundler/setup'
6
- # load predefined symbols
7
- require 'ib/symbols'
8
-
9
- include IB
10
- # Definition of what we want market data for. We have to keep track of what ticker id
11
- # corresponds to what symbol ourselves, because the ticks don't include any other
12
- # identifying information. The choice of ticker ids is, as far as I can tell, arbitrary.
13
- #
14
- # I. Selected Contracts
15
- contracts = [ IB::Symbols::Stocks.wfc,
16
- IB::Symbols::Stocks.vxx,
17
- IB::Symbols::Futures.vix,
18
- IB::Symbols::Futures.ym,
19
- IB::Symbols::Options.ge,
20
- ### OSI-Notation is broken
21
- # IB::Symbols::Options[:vix20],
22
- # IB::Symbols::Options[:spy270],
23
- # IB::Symbols::Options[:vxx40],
24
- IB::Symbols::Forex.eurusd,
25
- ### Bonds are not actually not supported
26
- # 8 => IB::Symbols::Bonds[:wag],
27
- IB::Symbols::Stocks.wrong ]
28
- # or
29
- # II. Use predefined Contracts
30
- stock_contracts = Symbols::Stocks.all.map{|x| Symbols::Stocks.send x }
31
- future_contracts = Symbols::Futures.all.map{|x| Symbols::Futures.send x }
32
- option_contracts = Symbols::Options.all.map{|x| Symbols::Options.send x }
33
- cfd_contracts = Symbols::CFD.all.map{|x| Symbols::CFD.send x }
34
- index_contracts = Symbols::Index.all.map{|x| Symbols::Index.send x }
35
-
36
- ## comment if you want to display selected contracts ( I. )
37
- contracts = stock_contracts + future_contracts + option_contracts + cfd_contracts + index_contracts
38
-
39
-
40
- # Connect to IB TWS.
41
- ib = Connection.new :client_id => 11912 do | gw| # , port: 7497 do | gw | # TWS
42
- # Subscribe to TWS alerts/errors and contract data end marker
43
- gw.subscribe(:Alert, :ContractDataEnd) { |msg| puts msg.to_human }
44
-
45
- # Now, subscribe to ContractData incoming events. The code passed in the block
46
- # will be executed when a message of that type is received, with the received
47
- # message as its argument. In this case, we just print out the data.
48
- gw.subscribe(:ContractData, :BondContractData) do |msg|
49
- puts msg.contract.to_human + "\n"
50
- puts "Attributes: "
51
- puts "\t"+ msg.contract.attributes.map{ |k,v| "#{k} : #{v}" unless v.blank? || (v.is_a?(Numeric) && v.zero?) }.join("\n\t")
52
- end
53
-
54
- # Set log level
55
- gw.logger.level = Logger::FATAL
56
- end
57
-
58
- ib.wait_for :NextValidOrderId
59
-
60
-
61
- contracts.each do |contract|
62
- puts "\nRequesting contract data for #{contract.description}"
63
-
64
- # Request Contract details for the symbols we're interested in. TWS will
65
- # respond with ContractData messages, which will be processed by the code above.
66
- ib.send_message :RequestContractData, :contract => contract
67
-
68
- # Wait for IB to respond to our request
69
- ib.wait_for :ContractDataEnd, 5 #sec
70
- ib.clear_received :ContractDataEnd
71
- end
@@ -1,50 +0,0 @@
1
- #!/usr/bin/env ruby
2
- #
3
- # This script gets details for specific contract from IB
4
-
5
- require 'bundler/setup'
6
- require 'ib/symbols'
7
- require './contract_samples'
8
- include IB
9
- # Definition of what we want market data for. We have to keep track of what ticker id
10
- # corresponds to what symbol ourselves, because the ticks don't include any other
11
- # identifying information. The choice of ticker ids is, as far as I can tell, arbitrary.
12
- contract_definitions = ContractSamples.public_instance_methods
13
-
14
- # get contracts from contract_samples db
15
- include ContractSamples
16
- the_contracts = contract_definitions.map{ | method | self.send( method )}
17
-
18
-
19
- # Connect to IB TWS.
20
- ib = Connection.new( :client_id => 11912, :port => 4002 ) do | gw| # 7496 # TWS
21
- # subscribe to TWS alerts/errors and contract data end marker
22
- gw.subscribe(:Alert, :ContractDataEnd) { |msg| puts msg.to_human }
23
-
24
- # subscribe to ContractData incoming events. The code passed in the block
25
- # will be executed when a message of that type is received, with the received
26
- # message as its argument. In this case, we just print out the data.
27
- gw.subscribe(:ContractData, :BondContractData) do |msg|
28
- puts "------------------> Recieved Contract Confirmation <----------------------------"
29
- puts msg.contract.to_human + "\n"
30
- puts "Attributes: "
31
- puts "\t"+ msg.contract.attributes.map{ |k,v| "#{k} : #{v}" unless v.blank? }.join("\n\t")
32
- end
33
- # Set log level
34
- gw.logger.level = Logger::DEBUG #FATAL
35
- end
36
-
37
- ib.wait_for :NextValidOrderId
38
-
39
-
40
- the_contracts.each do | contract|
41
- puts "\nRequesting contract data: #{contract_definitions}: #{contract.to_human}"
42
-
43
- # Request Contract details for the symbols we're interested in. TWS will
44
- # respond with ContractData messages, which will be processed by the code above.
45
- ib.send_message :RequestContractData, contract: contract
46
-
47
- # Wait for IB to respond to our request
48
- ib.wait_for :ContractDataEnd, 1 #sec
49
- ib.clear_received :ContractDataEnd
50
- end