atlasats 1.1.2 → 1.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/lib/atlasats.rb +5 -5
- data/lib/atlasatsrt.rb +134 -0
- metadata +26 -7
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NDcyMzY4NjY2NmMwNmYwNDkwMzJlNDFkYzFlMTA5OTk1ZTJlYjg5NA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MjZjN2IzMmU0ZDZiZDUwMzY2MWQ1MTg4N2RiNzRiOGJjMmFkNjc1NQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MGNjODM0MDk3NTY2ZTU4ZjdmYTE3NGIxN2NhNGFkYTgwMmI1YWMxNDdlMGNj
|
10
|
+
MjRlMGVjMjJiMjU1YTdmN2M0M2JkYzljNzBhMTMyNDFmMTE1MzY0YmM1NmM1
|
11
|
+
ZGViODI4YzkxZGIzODEwOTlkZjI3NjQ1MzFjM2E2YTg3ZDBmYTY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NDE0Njk2NDdkZWE2NDA4N2UyMjAyMzU3ZjRlYzIyMzFjYTMxYzI4NGMxNzhj
|
14
|
+
NTMzNDdlOTRlYzg3YzVlMmQ1YjI3M2M1MDg2ZDJmN2U0Yjc4Y2E3ZDgwNWY3
|
15
|
+
OTUzNjJkZjc2ZWQyNmY4YmVmZjVjODZlZDZhOTQwODgyY2Q4NTg=
|
data/lib/atlasats.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
orequire 'rubygems'
|
2
2
|
require 'bundler/setup'
|
3
3
|
require 'eventmachine'
|
4
4
|
require 'httparty'
|
@@ -59,9 +59,9 @@ class AtlasClient
|
|
59
59
|
# For most accounts this will return todays orders both (open, cancelled and done except rejects)
|
60
60
|
# but for some users who do alot of orders you can only rely on it to give you open orders
|
61
61
|
def recent_orders()
|
62
|
-
|
63
|
-
|
64
|
-
|
62
|
+
with_auth nil do |options|
|
63
|
+
self.class.get("/api/v1/orders", options)
|
64
|
+
end
|
65
65
|
end
|
66
66
|
|
67
67
|
# account
|
@@ -111,7 +111,7 @@ class AtlasClient
|
|
111
111
|
def subscribe_all_trades(&block)
|
112
112
|
Thread.new do
|
113
113
|
EM.run {
|
114
|
-
client = Faye::Client.new("#{@baseuri}
|
114
|
+
client = Faye::Client.new("#{@baseuri}/api/v1/streaming")
|
115
115
|
client.subscribe("/trades") do |msg|
|
116
116
|
begin
|
117
117
|
pmsg = JSON.parse(msg)
|
data/lib/atlasatsrt.rb
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
require 'eventmachine'
|
4
|
+
require 'faye'
|
5
|
+
require 'json'
|
6
|
+
require 'time'
|
7
|
+
|
8
|
+
class HmacAuthExt
|
9
|
+
def initialize(key, secret)
|
10
|
+
@key = key
|
11
|
+
@secret = secret
|
12
|
+
end
|
13
|
+
|
14
|
+
def outgoing(message, callback)
|
15
|
+
path = message['channel']
|
16
|
+
|
17
|
+
ident = generate_ident(path, message['data'])
|
18
|
+
|
19
|
+
# todo:
|
20
|
+
message['ext'] ||= {}
|
21
|
+
message['ext']['ident'] = ident
|
22
|
+
|
23
|
+
callback.call(message)
|
24
|
+
end
|
25
|
+
|
26
|
+
def incoming(message, callback)
|
27
|
+
callback.call(message)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def generate_ident(path, body)
|
33
|
+
nounce = generate_nounce
|
34
|
+
signature = generate_signature(nounce, path, body)
|
35
|
+
ident = {
|
36
|
+
"key" => @key,
|
37
|
+
"signature" => signature,
|
38
|
+
"nounce" => nounce
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
def generate_signature(nounce, path, body)
|
43
|
+
raw_signature = "#{@key}:#{nounce}:#{path}:#{body}"
|
44
|
+
|
45
|
+
return OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), @secret, raw_signature)
|
46
|
+
end
|
47
|
+
|
48
|
+
def generate_nounce
|
49
|
+
Time.now.to_i
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
class AtlasRealtimeClient
|
55
|
+
def initialize(url, key, secret, account_id)
|
56
|
+
@url = url
|
57
|
+
@key = key
|
58
|
+
@secret = secret
|
59
|
+
@account_id = account_id
|
60
|
+
|
61
|
+
@client = Faye::Client.new(@url)
|
62
|
+
@client.add_extension(HmacAuthExt.new(@key, @secret))
|
63
|
+
end
|
64
|
+
|
65
|
+
# symbols = nil for all symbols, otherwise please provide array
|
66
|
+
def request_spinup
|
67
|
+
# account
|
68
|
+
# -> account params
|
69
|
+
request_spinup_accountinfo
|
70
|
+
# -> recent orders
|
71
|
+
request_spinup_orders
|
72
|
+
# market data
|
73
|
+
request_spinup_book
|
74
|
+
end
|
75
|
+
|
76
|
+
def subscribe_orders(&block)
|
77
|
+
@client.subscribe "/account/#{@account_id}/orders" do |message|
|
78
|
+
order = JSON.parse(message)
|
79
|
+
block.call(order)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def subscribe_trades(&block)
|
84
|
+
@client.subscribe "/trades" do |message|
|
85
|
+
trade = JSON.parse(message)
|
86
|
+
block.call(trade)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def subscribe_book(&block)
|
91
|
+
@client.subscribe "/market" do |message|
|
92
|
+
book = JSON.parse(message)
|
93
|
+
block.call(book)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def place_limit_order(client_order_id, item, currency, side, quantity, price)
|
98
|
+
send_action(:action => "order:create", :item => item, :currency => currency, :side => side, :quantity => quantity, :type => "limit", :price => price, :clid => client_order_id)
|
99
|
+
end
|
100
|
+
|
101
|
+
def place_market_order(client_order_id, item, currency, side, quantity)
|
102
|
+
send_action(:action => "order:create", :item => item, :currency => currency, :side => side, :quantity => quantity, :type => "market", :clid => client_order_id)
|
103
|
+
end
|
104
|
+
|
105
|
+
def cancel_order(orderid)
|
106
|
+
send_action(:action => "order:cancel", :oid => orderid)
|
107
|
+
end
|
108
|
+
|
109
|
+
private
|
110
|
+
|
111
|
+
def send_action(obj)
|
112
|
+
@client.publish("/actions", to_message(obj))
|
113
|
+
end
|
114
|
+
|
115
|
+
def request_spinup_accountinfo
|
116
|
+
create_request!(:type => "account")
|
117
|
+
end
|
118
|
+
|
119
|
+
def request_spinup_orders
|
120
|
+
create_request!(:type => "orders")
|
121
|
+
end
|
122
|
+
|
123
|
+
def request_spinup_book
|
124
|
+
create_request!(:type => "book")
|
125
|
+
end
|
126
|
+
|
127
|
+
def create_request!(obj)
|
128
|
+
@client.publish("/requests/#{@account_id}", to_message(obj))
|
129
|
+
end
|
130
|
+
|
131
|
+
def to_message(obj)
|
132
|
+
obj.to_json
|
133
|
+
end
|
134
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: atlasats
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Habeel Ahmed
|
@@ -14,42 +14,60 @@ dependencies:
|
|
14
14
|
name: eventmachine
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
- - ! '>='
|
18
21
|
- !ruby/object:Gem::Version
|
19
22
|
version: 1.0.3
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- -
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.0'
|
30
|
+
- - ! '>='
|
25
31
|
- !ruby/object:Gem::Version
|
26
32
|
version: 1.0.3
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: httparty
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
30
36
|
requirements:
|
31
|
-
- -
|
37
|
+
- - ~>
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0.11'
|
40
|
+
- - ! '>='
|
32
41
|
- !ruby/object:Gem::Version
|
33
42
|
version: 0.11.0
|
34
43
|
type: :runtime
|
35
44
|
prerelease: false
|
36
45
|
version_requirements: !ruby/object:Gem::Requirement
|
37
46
|
requirements:
|
38
|
-
- -
|
47
|
+
- - ~>
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0.11'
|
50
|
+
- - ! '>='
|
39
51
|
- !ruby/object:Gem::Version
|
40
52
|
version: 0.11.0
|
41
53
|
- !ruby/object:Gem::Dependency
|
42
54
|
name: faye
|
43
55
|
requirement: !ruby/object:Gem::Requirement
|
44
56
|
requirements:
|
45
|
-
- -
|
57
|
+
- - ~>
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '1.0'
|
60
|
+
- - ! '>='
|
46
61
|
- !ruby/object:Gem::Version
|
47
62
|
version: 1.0.0
|
48
63
|
type: :runtime
|
49
64
|
prerelease: false
|
50
65
|
version_requirements: !ruby/object:Gem::Requirement
|
51
66
|
requirements:
|
52
|
-
- -
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '1.0'
|
70
|
+
- - ! '>='
|
53
71
|
- !ruby/object:Gem::Version
|
54
72
|
version: 1.0.0
|
55
73
|
description: Atlas ATS ruby library. Gives access to order placement and market data.
|
@@ -59,6 +77,7 @@ extensions: []
|
|
59
77
|
extra_rdoc_files: []
|
60
78
|
files:
|
61
79
|
- lib/atlasats.rb
|
80
|
+
- lib/atlasatsrt.rb
|
62
81
|
homepage: http://rubygems.org/gems/atlasats
|
63
82
|
licenses:
|
64
83
|
- MIT
|