iqfeed 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +29 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +42 -0
- data/Rakefile +2 -0
- data/TODO +4 -0
- data/iqfeed.gemspec +23 -0
- data/lib/iqfeed.rb +4 -0
- data/lib/iqfeed/history_client.rb +187 -0
- data/lib/iqfeed/level1_client.rb +95 -0
- data/lib/iqfeed/version.rb +3 -0
- data/sample/fileclient.rb +8 -0
- data/sample/history_daily_range.rb +8 -0
- data/sample/history_ohlc_range.rb +7 -0
- data/sample/history_tick_range.rb +8 -0
- data/sample/level1_online.rb +8 -0
- data/sample/range_bar.rb +8 -0
- data/sample/volume_bar.rb +8 -0
- data/tools/history.rb +129 -0
- metadata +91 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ab00bbc36a39e1ba9ae4380e9b8350d4efe7f4a2
|
4
|
+
data.tar.gz: 0b21acd28f6586eb632fa9ac4cb7d112d87a0525
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3b71dcce8162cd538433502c2960431863aab7dea2c2aa7920b487f9eacde9bc739822b2eb1d0db06d6d2cb5c865d95d81b144d620eb5303d6215f00eee45389
|
7
|
+
data.tar.gz: 4f3d054e0c6d8facb36bcbad5512109ee5e2f4158d977eaf89407252d10a09631b174fefc66884472da93ae554132d9649cbc3313759ef75693f0e487ca60993
|
data/.gitignore
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
/.bundle/
|
2
|
+
/.yardoc
|
3
|
+
/Gemfile.lock
|
4
|
+
/_yardoc/
|
5
|
+
/coverage/
|
6
|
+
/doc/
|
7
|
+
/pkg/
|
8
|
+
/spec/reports/
|
9
|
+
/tmp/
|
10
|
+
*.bundle
|
11
|
+
*.so
|
12
|
+
*.o
|
13
|
+
*.a
|
14
|
+
mkmf.log
|
15
|
+
*.gem
|
16
|
+
*.rbc
|
17
|
+
/.config
|
18
|
+
/coverage/
|
19
|
+
/InstalledFiles
|
20
|
+
/pkg/
|
21
|
+
/spec/reports/
|
22
|
+
/test/tmp/
|
23
|
+
/test/version_tmp/
|
24
|
+
/tmp/
|
25
|
+
|
26
|
+
## Specific to RubyMotion:
|
27
|
+
.dat*
|
28
|
+
.repl_history
|
29
|
+
build/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Tim
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
<<<<<<< HEAD
|
2
|
+
# Iqfeed
|
3
|
+
|
4
|
+
TODO: Write a gem description
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'iqfeed'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install iqfeed
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
TODO: Write usage instructions here
|
25
|
+
|
26
|
+
## Contributing
|
27
|
+
|
28
|
+
1. Fork it ( https://github.com/[my-github-username]/iqfeed/fork )
|
29
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
30
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
31
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
32
|
+
5. Create a new Pull Request
|
33
|
+
=======
|
34
|
+
ruby-iqfeed
|
35
|
+
===========
|
36
|
+
|
37
|
+
Ruby IQfeed client
|
38
|
+
|
39
|
+
Requirements:
|
40
|
+
- Install iqfeed-client
|
41
|
+
- Start IQLink-launcher
|
42
|
+
>>>>>>> origin/master
|
data/Rakefile
ADDED
data/TODO
ADDED
data/iqfeed.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'iqfeed/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "iqfeed"
|
8
|
+
spec.version = Iqfeed::VERSION
|
9
|
+
spec.authors = ["Tim"]
|
10
|
+
spec.email = ["dev@adigamov.ca"]
|
11
|
+
spec.summary = %q{IQfeed client for ruby}
|
12
|
+
spec.description = %q{IQfeed client for ruby. Supports history and online (level1) mode.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
end
|
data/lib/iqfeed.rb
ADDED
@@ -0,0 +1,187 @@
|
|
1
|
+
require 'socket'
|
2
|
+
require 'observer'
|
3
|
+
|
4
|
+
module Iqfeed
|
5
|
+
class NoDataError < StandardError
|
6
|
+
attr_reader :object
|
7
|
+
|
8
|
+
def initialize(object)
|
9
|
+
@object = object
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class HistoryObserver
|
14
|
+
def initialize()
|
15
|
+
end
|
16
|
+
|
17
|
+
def update(tick)
|
18
|
+
puts tick.to_s
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class Tick
|
23
|
+
attr_accessor :time_stamp, :last_price, :last_size, :total_volume, :bid, :ask, :tick_id
|
24
|
+
|
25
|
+
def self.parse(line)
|
26
|
+
tick = Tick.new
|
27
|
+
fields = line.split(',')
|
28
|
+
tick.time_stamp = fields[0].to_s
|
29
|
+
tick.last_price = fields[1].to_f
|
30
|
+
tick.last_size = fields[2].to_i
|
31
|
+
tick.total_volume = fields[3].to_i
|
32
|
+
tick.bid = fields[4].to_f
|
33
|
+
tick.ask = fields[5].to_f
|
34
|
+
tick
|
35
|
+
end
|
36
|
+
|
37
|
+
def to_s
|
38
|
+
"Timestamp:#{@time_stamp} LastPrice:#{@last_price} LastSize:#{@last_size} TotalVolume:#{@total_volume} Bid:#{@bid} Ask:#{@ask}"
|
39
|
+
end
|
40
|
+
|
41
|
+
def to_csv
|
42
|
+
[@time_stamp, @last_price, @last_size, @total_volume, @bid, @ask].join(';')
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class OHLC
|
47
|
+
attr_accessor :time_stamp, :high, :low, :open, :close, :total_volume, :period_volume
|
48
|
+
|
49
|
+
def self.parse(line)
|
50
|
+
ohlc = OHLC.new
|
51
|
+
fields = line.split(',')
|
52
|
+
ohlc.time_stamp = fields[0]
|
53
|
+
ohlc.high = fields[1]
|
54
|
+
ohlc.low = fields[2]
|
55
|
+
ohlc.open = fields[3]
|
56
|
+
ohlc.close = fields[4]
|
57
|
+
ohlc.total_volume = fields[5]
|
58
|
+
ohlc.period_volume = fields[6]
|
59
|
+
ohlc
|
60
|
+
end
|
61
|
+
|
62
|
+
def to_s
|
63
|
+
"Timestamp:#{@time_stamp} High:#{@high} Low:#{@low} Open:#{@open} Close:#{@close} TotalVolume:#{@total_volume} PeriodVolume:#{@period_volume}"
|
64
|
+
end
|
65
|
+
|
66
|
+
def to_csv
|
67
|
+
[@time_stamp, @open, @high, @low, @close, @total_volume, @period_volume].join(';')
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
class DWM # day, week, month
|
72
|
+
attr_accessor :time_stamp, :high, :low, :open, :close, :period_volume, :open_interest
|
73
|
+
|
74
|
+
def self.parse(line)
|
75
|
+
dwm = DWM.new
|
76
|
+
fields = line.split(',')
|
77
|
+
dwm.time_stamp = fields[0]
|
78
|
+
dwm.high = fields[1]
|
79
|
+
dwm.low = fields[2]
|
80
|
+
dwm.open = fields[3]
|
81
|
+
dwm.close = fields[4]
|
82
|
+
dwm.period_volume = fields[5]
|
83
|
+
dwm.open_interest = fields[6]
|
84
|
+
dwm
|
85
|
+
end
|
86
|
+
|
87
|
+
def to_s
|
88
|
+
"Timestamp:#{@time_stamp} High:#{@high} Low:#{@low} Open:#{@open} Close:#{@close} PeriodVolume:#{@period_volume} OpenInterest:#{@open_interest}"
|
89
|
+
end
|
90
|
+
|
91
|
+
def to_csv
|
92
|
+
[@time_stamp, @high, @low, @open, @close, @period_volume, @open_interest].join(';')
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
class HistoryClient
|
97
|
+
include Observable
|
98
|
+
attr_accessor :max_tick_number, :start_session, :end_session, :old_to_new, :ticks_per_send
|
99
|
+
|
100
|
+
def initialize(options = {})
|
101
|
+
parse_options(options)
|
102
|
+
@request_id = 0
|
103
|
+
end
|
104
|
+
|
105
|
+
def parse_options(options)
|
106
|
+
@host = options[:host] || 'localhost'
|
107
|
+
@port = options[:port] || 9100
|
108
|
+
@name = options[:name] || 'DEMO'
|
109
|
+
@max_tick_number = options[:max_tick_number] || 5000000
|
110
|
+
@start_session = options[:start_session] || '000000'
|
111
|
+
@end_session = options[:end_session] || '235959'
|
112
|
+
@old_to_new = options[:old_to_new] || 1
|
113
|
+
@ticks_per_send = options[:ticks_per_send] || 500
|
114
|
+
end
|
115
|
+
|
116
|
+
def open
|
117
|
+
@socket = TCPSocket.open @host, @port
|
118
|
+
@socket.puts "S,SET CLIENT NAME," + @name
|
119
|
+
end
|
120
|
+
|
121
|
+
def process_request
|
122
|
+
procs = []
|
123
|
+
exception = nil
|
124
|
+
|
125
|
+
procs[0] = Proc.new{|line| IQ::Tick.parse(line)}
|
126
|
+
procs[1] = Proc.new{|line| IQ::OHLC.parse(line)}
|
127
|
+
procs[2] = Proc.new{|line| IQ::DWM.parse(line)}
|
128
|
+
|
129
|
+
while line = @socket.gets
|
130
|
+
fields = line.match(/^([^,]+),(.*)/)
|
131
|
+
line = fields[2]
|
132
|
+
if line =~ /^E,/
|
133
|
+
exception = 'No Data'
|
134
|
+
elsif line =~ /!ENDMSG!,/
|
135
|
+
break
|
136
|
+
end
|
137
|
+
yield procs[fields[1][0].to_i].call(line)
|
138
|
+
end
|
139
|
+
if exception
|
140
|
+
raise NoDataError.new("No Data")
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
def format_request_id(type)
|
145
|
+
type.to_s + @request_id.to_s.rjust(7, '0')
|
146
|
+
end
|
147
|
+
|
148
|
+
def run
|
149
|
+
process_request do |line|
|
150
|
+
changed
|
151
|
+
notify_observers(line)
|
152
|
+
end
|
153
|
+
@request_id = @request_id + 1
|
154
|
+
end
|
155
|
+
|
156
|
+
def get_tick_range(options, observer)
|
157
|
+
printf "HTT,%s,%s,%s,%07d,%s,%s,%d,0%07d,%07d\r\n",
|
158
|
+
options[:symbol], options[:from].strftime("%Y%m%d %H%M%S"), options[:to].strftime("%Y%m%d %H%M%S"),
|
159
|
+
@max_tick_number, @start_session, @end_session, @old_to_new, @request_id, @ticks_per_send
|
160
|
+
@socket.printf "HTT,%s,%s,%s,%07d,%s,%s,%d,0%07d,%07d\r\n",
|
161
|
+
options[:symbol], options[:from].strftime("%Y%m%d %H%M%S"), options[:to].strftime("%Y%m%d %H%M%S"),
|
162
|
+
@max_tick_number, @start_session, @end_session, @old_to_new, @request_id, @ticks_per_send
|
163
|
+
add_observer(observer)
|
164
|
+
end
|
165
|
+
|
166
|
+
def get_daily_range(options, observer)
|
167
|
+
@socket.printf "HDT,%s,%s,%s,%07d,%d,2%07d,%07d\r\n",
|
168
|
+
options[:symbol], options[:from].strftime("%Y%m%d %H%M%S"), options[:to].strftime("%Y%m%d %H%M%S"),
|
169
|
+
@max_tick_number, @old_to_new, @request_id, @ticks_per_send
|
170
|
+
add_observer(observer)
|
171
|
+
end
|
172
|
+
|
173
|
+
def get_ohlc_range(options, observer)
|
174
|
+
printf "HIT,%s,%07d,%s,%s,%07d,%s,%s,%d,1%07d,%07d\r\n",
|
175
|
+
options[:symbol], options[:duration], options[:from].strftime("%Y%m%d %H%M%S"), options[:to].strftime("%Y%m%d %H%M%S"),
|
176
|
+
@max_tick_number, @start_session, @end_session, @old_to_new, @request_id, @ticks_per_send
|
177
|
+
@socket.printf "HIT,%s,%07d,%s,%s,%07d,%s,%s,%d,1%07d,%07d\r\n",
|
178
|
+
options[:symbol], options[:duration], options[:from].strftime("%Y%m%d %H%M%S"), options[:to].strftime("%Y%m%d %H%M%S"),
|
179
|
+
@max_tick_number, @start_session, @end_session, @old_to_new, @request_id, @ticks_per_send
|
180
|
+
add_observer(observer)
|
181
|
+
end
|
182
|
+
|
183
|
+
def close
|
184
|
+
@socket.close
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'socket'
|
2
|
+
require 'observer'
|
3
|
+
|
4
|
+
module Iqfeed
|
5
|
+
class Level1Observer
|
6
|
+
attr_accessor :symbol
|
7
|
+
|
8
|
+
def initialize(symbol)
|
9
|
+
@symbol = symbol
|
10
|
+
end
|
11
|
+
|
12
|
+
def update(tick)
|
13
|
+
puts tick.to_s
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class Level1Tick
|
18
|
+
attr_accessor :type, :time_stamp, :last_price, :total_volume, :last_size, :bid, :ask
|
19
|
+
def self.parse(line)
|
20
|
+
fields = line.split(',')
|
21
|
+
tick = Level1Tick.new
|
22
|
+
tick.type = fields[17]
|
23
|
+
tick.bid = fields[10]
|
24
|
+
tick.ask = fields[11]
|
25
|
+
tick.last_price = fields[3]
|
26
|
+
tick.last_size = fields[7]
|
27
|
+
tick.total_volume = fields[6]
|
28
|
+
tick.time_stamp = fields[65]
|
29
|
+
tick.type =~ /t/ ? tick : nil
|
30
|
+
end
|
31
|
+
|
32
|
+
def to_s
|
33
|
+
# if (@type =~ /b/)
|
34
|
+
# "Bid: #{@bid_size}@#{@bid}"
|
35
|
+
# elsif (@type =~ /a/)
|
36
|
+
# "Ask: #{@ask_size}@#{@ask}"
|
37
|
+
if (@type =~ /t/)
|
38
|
+
"Timestamp:#{@time_stamp} LastPrice:#{@last_price} LastSize:#{@last_size} TotalVolume:#{@total_volume} Bid:#{@bid} Ask:#{@ask}"
|
39
|
+
# elsif (@type =~ /T/)
|
40
|
+
# "extendedTrade"
|
41
|
+
# elsif !@type.nil?
|
42
|
+
# "other"
|
43
|
+
# else
|
44
|
+
# nil
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
class Level1Client
|
50
|
+
include Observable
|
51
|
+
|
52
|
+
def initialize(options = {})
|
53
|
+
parse_options(options)
|
54
|
+
end
|
55
|
+
|
56
|
+
def parse_options(options)
|
57
|
+
@host = options[:host] || 'localhost'
|
58
|
+
@port = options[:port] || 5009
|
59
|
+
@name = options[:name] || 'DEMO'
|
60
|
+
end
|
61
|
+
|
62
|
+
def open
|
63
|
+
@socket = TCPSocket.open @host, @port
|
64
|
+
@socket.puts "S,CONNECT"
|
65
|
+
@socket.puts "S,SET CLIENT NAME," + @name
|
66
|
+
end
|
67
|
+
|
68
|
+
def add(observer)
|
69
|
+
@socket.puts "w" + observer.symbol
|
70
|
+
add_observer(observer)
|
71
|
+
end
|
72
|
+
|
73
|
+
def remove(symbol)
|
74
|
+
@socket.puts "r" + symbol;
|
75
|
+
end
|
76
|
+
|
77
|
+
def run
|
78
|
+
exception = nil
|
79
|
+
while line = @socket.gets
|
80
|
+
if line =~ /^E,/
|
81
|
+
exception = 'No Data'
|
82
|
+
elsif line =~ /!ENDMSG!,/
|
83
|
+
break
|
84
|
+
end
|
85
|
+
tick = Level1Tick.parse(line)
|
86
|
+
next if tick.nil?
|
87
|
+
changed
|
88
|
+
notify_observers(tick)
|
89
|
+
end
|
90
|
+
if exception
|
91
|
+
raise exception
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
data/sample/range_bar.rb
ADDED
data/tools/history.rb
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'ostruct'
|
3
|
+
require 'pp'
|
4
|
+
require 'date'
|
5
|
+
require '../lib/history_client'
|
6
|
+
|
7
|
+
MONTHS=['F','G','H','J','K','M','N','Q','U','V','X','Z']
|
8
|
+
|
9
|
+
class FileObserver
|
10
|
+
def initialize(file)
|
11
|
+
@file = file
|
12
|
+
end
|
13
|
+
def update(tick)
|
14
|
+
@file.puts tick.to_csv
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def client_proxy(iq_client, options, o)
|
19
|
+
iq_client.send(options[:method], options, o)
|
20
|
+
end
|
21
|
+
|
22
|
+
def get_valid_codes(today, months)
|
23
|
+
current_month = today.month
|
24
|
+
valid_months = months.map{|m| MONTHS.index(m) + 1}.select{|m| m >= current_month}.map{|m| "#{MONTHS[m-1]}#{today.year-2000}"}.slice(0,2)
|
25
|
+
valid_months = valid_months + months.slice(0, 2 - valid_months.length).map{|m| m + "#{today.year-2000+1}"} if valid_months.length < 2
|
26
|
+
valid_months
|
27
|
+
end
|
28
|
+
|
29
|
+
options = {}
|
30
|
+
|
31
|
+
opts = OptionParser.new do |opts|
|
32
|
+
opts.banner = "Usage: history.rb [options]"
|
33
|
+
|
34
|
+
opts.on("-s", "--symbol SYMBOL", "Symbol for history request") do |s|
|
35
|
+
options[:symbol] = s
|
36
|
+
end
|
37
|
+
|
38
|
+
opts.on("-f", "--from DATE", "Start date for history request") do |from|
|
39
|
+
options[:from] = DateTime.parse(from) #Time.new(d.year, d.month, d.day, 0, 0, 0)
|
40
|
+
end
|
41
|
+
|
42
|
+
opts.on("-t", "--to DATE", "End date for history request") do |to|
|
43
|
+
options[:to] = DateTime.parse(to) #Time.new(d.year, d.month, d.day, 23, 59, 59)
|
44
|
+
end
|
45
|
+
|
46
|
+
opts.on("-o", "--output FILE", "Output file for history data") do |output|
|
47
|
+
options[:output] = output
|
48
|
+
end
|
49
|
+
|
50
|
+
opts.on("-i", "--input FILE", "Input file with list of future contracts") do |input|
|
51
|
+
options[:input] = input
|
52
|
+
end
|
53
|
+
|
54
|
+
opts.on("-t", "--type [TYPE]", [:tick, :ohlc, :dwm], "Select data type (tick, ohlc, dwm)") do |type|
|
55
|
+
if type == :ohlc
|
56
|
+
options[:method] = :get_ohlc_range
|
57
|
+
elsif type == :dwm
|
58
|
+
options[:method] = :get_daily_range
|
59
|
+
else
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
opts.on("-d", "--duration [SECONDS]", "Candle duration in seconds for OHLC type") do |duration|
|
65
|
+
options[:duration] = duration
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
begin
|
70
|
+
opts.parse!
|
71
|
+
mandatory = [:from, :to]
|
72
|
+
missing = mandatory.select{ |param| options[param].nil? }
|
73
|
+
#TODO fix
|
74
|
+
if not missing.empty? || (options[:input].nil? && options[:symbol].nil?)
|
75
|
+
puts "Missing options: #{missing.join(', ')}"
|
76
|
+
puts opts
|
77
|
+
exit
|
78
|
+
end
|
79
|
+
rescue OptionParser::InvalidOption, OptionParser::MissingArgument
|
80
|
+
puts $!.to_s
|
81
|
+
puts optparse
|
82
|
+
exit
|
83
|
+
end
|
84
|
+
|
85
|
+
options[:method] ||= :get_tick_range
|
86
|
+
options[:duration] ||= 300 if options[:type] == :ohlc
|
87
|
+
|
88
|
+
contracts = {}
|
89
|
+
if options[:input].nil?
|
90
|
+
contracts[options[:symbol]] = nil
|
91
|
+
else
|
92
|
+
contracts_file = File.open(options[:input])
|
93
|
+
contracts_file.each do |line|
|
94
|
+
line.chomp!
|
95
|
+
f = line.split(';')
|
96
|
+
contracts[f[0]] = f[3].split(',')
|
97
|
+
end
|
98
|
+
end
|
99
|
+
from_date = options[:from]
|
100
|
+
to_date = options[:to]
|
101
|
+
while from_date <= to_date
|
102
|
+
contracts.keys.each do |contract|
|
103
|
+
codes = []
|
104
|
+
if contracts[contract].nil?
|
105
|
+
codes = [contract]
|
106
|
+
else
|
107
|
+
codes = get_valid_codes(from_date, contracts[contract]).map{|c| "#{contract}#{c}"}
|
108
|
+
end
|
109
|
+
codes.each do |code|
|
110
|
+
output_file = File.new(code.gsub("@","")+"_" + ("%04d" % from_date.year) + ("%02d" % from_date.month) + ("%02d" % from_date.day) + ".csv", "w")
|
111
|
+
options[:symbol] = code
|
112
|
+
options[:from] = Time.new(from_date.year, from_date.month, from_date.day, 0, 0, 0)
|
113
|
+
options[:to] = Time.new(from_date.year, from_date.month, from_date.day, 23, 59, 59)
|
114
|
+
o = FileObserver.new(output_file)
|
115
|
+
iq_client = IQ::HistoryClient.new
|
116
|
+
iq_client.open
|
117
|
+
client_proxy(iq_client, options, o)
|
118
|
+
begin
|
119
|
+
iq_client.run
|
120
|
+
rescue IQ::NoDataError => e
|
121
|
+
output_file.close
|
122
|
+
File.delete(output_file)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
from_date = from_date.next
|
127
|
+
end
|
128
|
+
|
129
|
+
# options[:output] ||= options[:symbol].gsub(/[@\$\^#]/,'') + '.csv'
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: iqfeed
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tim
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: IQfeed client for ruby. Supports history and online (level1) mode.
|
42
|
+
email:
|
43
|
+
- dev@adigamov.ca
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- TODO
|
54
|
+
- iqfeed.gemspec
|
55
|
+
- lib/iqfeed.rb
|
56
|
+
- lib/iqfeed/history_client.rb
|
57
|
+
- lib/iqfeed/level1_client.rb
|
58
|
+
- lib/iqfeed/version.rb
|
59
|
+
- sample/fileclient.rb
|
60
|
+
- sample/history_daily_range.rb
|
61
|
+
- sample/history_ohlc_range.rb
|
62
|
+
- sample/history_tick_range.rb
|
63
|
+
- sample/level1_online.rb
|
64
|
+
- sample/range_bar.rb
|
65
|
+
- sample/volume_bar.rb
|
66
|
+
- tools/history.rb
|
67
|
+
homepage: ''
|
68
|
+
licenses:
|
69
|
+
- MIT
|
70
|
+
metadata: {}
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options: []
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
requirements: []
|
86
|
+
rubyforge_project:
|
87
|
+
rubygems_version: 2.2.2
|
88
|
+
signing_key:
|
89
|
+
specification_version: 4
|
90
|
+
summary: IQfeed client for ruby
|
91
|
+
test_files: []
|