alphapoint 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +6 -0
- data/README.md +43 -0
- data/lib/alphapoint.rb +71 -0
- data/lib/alphapoint/configuration.rb +14 -0
- data/lib/alphapoint/get_quotes.rb +32 -0
- data/lib/alphapoint/version.rb +3 -0
- data/lib/alphapoint/web_socket.rb +105 -0
- metadata +200 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ab8940b218436b9659bc40f42b9067ec91b82798
|
4
|
+
data.tar.gz: 3173cff1946b7680a95496b1fb3bf836e9c6df78
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 821bf5ae725f4b7d7b4de14030f2a12ada9cdf32af07d926a406481cc8e9e7971eb6ed21398c1c2c954c0aac7fec5806c2d68e9f4dbf83bfd91b2e12f84d455b
|
7
|
+
data.tar.gz: 34e7fd356199c03f46ebe8d2aab474c8736322efcbc6e3932b8c368bdd0f7e4fdf765d7890545af48000694d47423cb838aec9fc34077ea8f17088f228aadd61
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# Alphapoint
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/alphapoint`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'alphapoint'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install alphapoint
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/alphapoint. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
40
|
+
|
41
|
+
## Code of Conduct
|
42
|
+
|
43
|
+
Everyone interacting in the Alphapoint project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/alphapoint/blob/master/CODE_OF_CONDUCT.md).
|
data/lib/alphapoint.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'alphapoint/version'
|
2
|
+
require 'faye/websocket'
|
3
|
+
require 'eventmachine'
|
4
|
+
require 'yaml'
|
5
|
+
require 'active_support/all'
|
6
|
+
|
7
|
+
require 'alphapoint/configuration'
|
8
|
+
require 'alphapoint/web_socket'
|
9
|
+
require 'alphapoint/get_quotes'
|
10
|
+
|
11
|
+
module Alphapoint
|
12
|
+
|
13
|
+
module Call
|
14
|
+
REQUEST = 0
|
15
|
+
REPLY = 1
|
16
|
+
SUBSCRIBE = 2
|
17
|
+
EVENT = 3
|
18
|
+
UNSUBSCRIBE = 4
|
19
|
+
ERROR = 5
|
20
|
+
end
|
21
|
+
|
22
|
+
class AlphapointError < StandardError
|
23
|
+
|
24
|
+
def initialize(msg="Alphapoint error and conection failed")
|
25
|
+
super
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.response_of(type)
|
31
|
+
if type == REQUEST
|
32
|
+
REPLY
|
33
|
+
elsif type == SUBSCRIBE
|
34
|
+
EVENT
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
class << self
|
39
|
+
attr_accessor :configuration
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.configuration
|
43
|
+
@configuration ||= Configuration.new
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.reset
|
47
|
+
@configuration = Configuration.new
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.configure
|
51
|
+
yield(configuration)
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.configure_with(path_to_yaml_file)
|
55
|
+
configure do |configuration|
|
56
|
+
begin
|
57
|
+
config = YAML.load(IO.read(path_to_yaml_file))
|
58
|
+
|
59
|
+
configuration.address = config.address
|
60
|
+
configuration.user = config.user
|
61
|
+
configuration.password = config.password
|
62
|
+
|
63
|
+
rescue Errno::ENOENT
|
64
|
+
# log(:warning, "YAML configuration file couldn't be found. Using defaults."); return
|
65
|
+
rescue Psych::SyntaxError
|
66
|
+
# log(:warning, "YAML configuration file contains invalid syntax. Using defaults."); return
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Alphapoint
|
2
|
+
|
3
|
+
class GetQuotes
|
4
|
+
|
5
|
+
def initialize(ws)
|
6
|
+
@ws = ws
|
7
|
+
|
8
|
+
@data = []
|
9
|
+
@instruments_number = -1
|
10
|
+
@count = 0
|
11
|
+
end
|
12
|
+
|
13
|
+
def execute(payload, &block)
|
14
|
+
@ws.get_instruments(payload) do |res|
|
15
|
+
|
16
|
+
res.each do |inst|
|
17
|
+
payloadSub = payload.merge({ InstrumentId: inst['InstrumentId'] })
|
18
|
+
@ws.subscribe_level1(payloadSub) do |ticker|
|
19
|
+
if res.size == @count + 1
|
20
|
+
block.call(@data)
|
21
|
+
else
|
22
|
+
@data << ticker.merge(inst)
|
23
|
+
@count += 1
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module Alphapoint
|
4
|
+
|
5
|
+
class WebSocket
|
6
|
+
|
7
|
+
attr_accessor :address
|
8
|
+
|
9
|
+
def initialize(address = nil)
|
10
|
+
if Alphapoint.configuration.nil? ||
|
11
|
+
Alphapoint.configuration.address.nil? ||
|
12
|
+
Alphapoint.configuration.address.empty?
|
13
|
+
raise AlphapointError, "Pass or configure an address to conect on WebSocket"
|
14
|
+
end
|
15
|
+
|
16
|
+
@ws = nil
|
17
|
+
@address = address || Alphapoint.configuration.address
|
18
|
+
@nextIValue = 2
|
19
|
+
@avaliable_functions = [
|
20
|
+
"GetInstrument",
|
21
|
+
"GetInstruments",
|
22
|
+
"GetProduct",
|
23
|
+
"GetProducts",
|
24
|
+
"SendOrder",
|
25
|
+
"SubscribeLevel1",
|
26
|
+
"WebAuthenticateUser"
|
27
|
+
]
|
28
|
+
@response = {}
|
29
|
+
|
30
|
+
@unsub_actions = []
|
31
|
+
|
32
|
+
alpha_self = self
|
33
|
+
|
34
|
+
@thread = Thread.new do
|
35
|
+
EM.run do
|
36
|
+
@ws = Faye::WebSocket::Client.new(@address)
|
37
|
+
|
38
|
+
@ws.on :open do |event|
|
39
|
+
p [:open, "Websocket connected to #{@address}"]
|
40
|
+
end
|
41
|
+
|
42
|
+
@ws.on :message do |event|
|
43
|
+
alpha_self.delegate_message(JSON.parse(event.data).with_indifferent_access)
|
44
|
+
end
|
45
|
+
|
46
|
+
@ws.on :close do |event|
|
47
|
+
p [:close, event.code, event.reason]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def build_request(function_name, payload,type = 0, &block)
|
54
|
+
frame = {
|
55
|
+
'm': type,
|
56
|
+
'i': @nextIValue,
|
57
|
+
'n': function_name,
|
58
|
+
'o': JSON.generate(payload)
|
59
|
+
}
|
60
|
+
|
61
|
+
@response[@nextIValue] = block
|
62
|
+
@nextIValue += 2
|
63
|
+
@ws.send(JSON.generate(frame))
|
64
|
+
end
|
65
|
+
|
66
|
+
# Finds the action responsible for the received message
|
67
|
+
def delegate_message(data)
|
68
|
+
received_action = @response[data['i']]
|
69
|
+
|
70
|
+
if !received_action.nil? && received_action.is_a?(Proc)
|
71
|
+
received_action.call(JSON.parse(data['o']))
|
72
|
+
@response[data['i']] = nil
|
73
|
+
else
|
74
|
+
raise "Error: Received message has no correspondent id"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def get_quotes(payload = { OMSId: 1 }, &block)
|
79
|
+
quotes = Alphapoint::GetQuotes.new(self)
|
80
|
+
|
81
|
+
quotes.execute(payload) do |res|
|
82
|
+
block.call(res)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def method_missing(m, *args, &block)
|
87
|
+
function_name = m.to_s.camelcase
|
88
|
+
respond_action = @avaliable_functions.select{ |func| func == function_name }
|
89
|
+
if respond_action.size > 0
|
90
|
+
puts "Delegating to action: #{m}"
|
91
|
+
|
92
|
+
payload = args[0] || {}
|
93
|
+
type = args[1].to_i || 0
|
94
|
+
|
95
|
+
build_request(function_name, payload, type) do |response|
|
96
|
+
block.call(response)
|
97
|
+
end
|
98
|
+
else
|
99
|
+
raise "Method #{m} not implemented yet"
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
end # End Class
|
104
|
+
|
105
|
+
end # End Module
|
metadata
ADDED
@@ -0,0 +1,200 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: alphapoint
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Miguel Corti
|
8
|
+
- Fabiano Martins
|
9
|
+
- Lucas Pérez
|
10
|
+
autorequire:
|
11
|
+
bindir: exe
|
12
|
+
cert_chain: []
|
13
|
+
date: 2019-01-03 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: activesupport
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - "~>"
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 5.1.6
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 5.1.6
|
25
|
+
type: :runtime
|
26
|
+
prerelease: false
|
27
|
+
version_requirements: !ruby/object:Gem::Requirement
|
28
|
+
requirements:
|
29
|
+
- - "~>"
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: 5.1.6
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 5.1.6
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: eventmachine
|
37
|
+
requirement: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 1.2.7
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: 1.2.7
|
45
|
+
type: :runtime
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - "~>"
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: 1.2.7
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.2.7
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: faye-websocket
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.10.7
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: 0.10.7
|
65
|
+
type: :runtime
|
66
|
+
prerelease: false
|
67
|
+
version_requirements: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - "~>"
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: 0.10.7
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 0.10.7
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: bundler
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '1.17'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '1.17'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: rake
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '10.0'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '10.0'
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: rspec
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - "~>"
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '3.0'
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - "~>"
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '3.0'
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: pry
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - "~>"
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: 0.12.2
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: 0.12.2
|
127
|
+
type: :development
|
128
|
+
prerelease: false
|
129
|
+
version_requirements: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - "~>"
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: 0.12.2
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: 0.12.2
|
137
|
+
- !ruby/object:Gem::Dependency
|
138
|
+
name: guard-rspec
|
139
|
+
requirement: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - "~>"
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: 4.7.3
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: 4.7.3
|
147
|
+
type: :development
|
148
|
+
prerelease: false
|
149
|
+
version_requirements: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - "~>"
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: 4.7.3
|
154
|
+
- - ">="
|
155
|
+
- !ruby/object:Gem::Version
|
156
|
+
version: 4.7.3
|
157
|
+
description: Alphapoint websocket DSL is to easy request and listen event
|
158
|
+
email:
|
159
|
+
- miguelszcorti@gmail.com
|
160
|
+
- fabiano.paula.martins@gmail.com
|
161
|
+
- lucas@blockchainstudio.com.br
|
162
|
+
executables: []
|
163
|
+
extensions: []
|
164
|
+
extra_rdoc_files: []
|
165
|
+
files:
|
166
|
+
- Gemfile
|
167
|
+
- README.md
|
168
|
+
- lib/alphapoint.rb
|
169
|
+
- lib/alphapoint/configuration.rb
|
170
|
+
- lib/alphapoint/get_quotes.rb
|
171
|
+
- lib/alphapoint/version.rb
|
172
|
+
- lib/alphapoint/web_socket.rb
|
173
|
+
homepage: https://github.com/blockchain-studio-br/alphapoint
|
174
|
+
licenses:
|
175
|
+
- MIT
|
176
|
+
metadata:
|
177
|
+
homepage_uri: https://github.com/blockchain-studio-br/alphapoint
|
178
|
+
source_code_uri: https://github.com/blockchain-studio-br/alphapoint
|
179
|
+
changelog_uri: https://github.com/blockchain-studio-br/alphapoint
|
180
|
+
post_install_message:
|
181
|
+
rdoc_options: []
|
182
|
+
require_paths:
|
183
|
+
- lib
|
184
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
185
|
+
requirements:
|
186
|
+
- - ">="
|
187
|
+
- !ruby/object:Gem::Version
|
188
|
+
version: '0'
|
189
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
190
|
+
requirements:
|
191
|
+
- - ">="
|
192
|
+
- !ruby/object:Gem::Version
|
193
|
+
version: '0'
|
194
|
+
requirements: []
|
195
|
+
rubyforge_project:
|
196
|
+
rubygems_version: 2.6.11
|
197
|
+
signing_key:
|
198
|
+
specification_version: 4
|
199
|
+
summary: Alphapoint websocket DSL
|
200
|
+
test_files: []
|