atlasats 1.0.4 → 1.0.5

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.
Files changed (3) hide show
  1. checksums.yaml +8 -8
  2. data/lib/atlasats.rb +98 -96
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OTNlMWU0OGQ3MDAxOTg3ZmUzOGFiOTRiMjQ2ZDhhZmJmYzExN2IyMA==
4
+ ZDVhNTY0NWY4MWU3MjE2ZjdjNzFkMjU0ZmY0MzZmOTI2NTI4ZWI1MA==
5
5
  data.tar.gz: !binary |-
6
- NDcyOWYyMDllYmNiYmYxNDFmY2UwZmQ2ZDNjNzRiNWUwZjA5NDI0NA==
6
+ N2Y1ZWEzOWNhNzUyNjRlMzE4MTA5OTZhOTk5ZTBkMjljZmNjY2FjOQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NTJlYmZiZDZlYzhhYzllM2ZhYjBjMGQ1MGYzMmY3ZTNjNjcxMjViMDc2MGZi
10
- M2MzOWI5NTM3Mzg3NjBiOTFiNmVjYzdhNTdmODkyNjJjNGY4MDgwMjFmODRj
11
- MGE2YjIyZmIyNTJhY2M4MWJkYWY1ZDk4MDEzYWY5OGE3MDg2NjA=
9
+ NDg4ZjA5YjVkOGVhMzQ2OTcwZTYxYTQ1ODEwZGY5YjlhNzBlZDI3ZjkzYzhj
10
+ YWFmMzMyODdkNTFhMjlhODVkNGVmZjhjYmU5OTg3ODcxMTNmYWE3NzY3MjM5
11
+ YjdiODNlOTczMzFiOTlmODdlOTY3YmY3YzAyZWRjZGIwOTk2ZmI=
12
12
  data.tar.gz: !binary |-
13
- ZTUzOTdkZjFmY2M1ZmNlMjhhNWRhNGE1NzNmZjgwMWEzY2U0MTM4MTRjZGVj
14
- MWJjYmViZjc4OGI5MGU0NjFkZTJkODI0ZWI2OTAwMjlhNzIxZmJjZGFjZWE3
15
- Y2Q4ZTc4MzljNGI2MzU5ZGU4YWU3OGI2MjEzZDhiOTA2YWRhZjA=
13
+ NDYwNWE2NzhmM2VlYWMzODlkYjI4YzViMmMwZGFhZjAyOTRlNTQ3ZmFjNTU1
14
+ Y2U4MjY5MTIxNzFlZmM4YmFkYWExMWQwZGU1NTQ1ZDAzYWE5NGY1ZmQ2ZGFi
15
+ ZmEwNzU0NmFhNjUxNjhjZWVmOGZkMWExNmNmZDU0Nzg3MDQ5MWY=
data/lib/atlasats.rb CHANGED
@@ -4,105 +4,107 @@ require 'eventmachine'
4
4
  require 'httparty'
5
5
  require 'faye'
6
6
  require 'json'
7
+ require 'time'
7
8
 
8
9
  class AtlasClient
9
- include HTTParty
10
-
11
- def initialize(buri, apikey)
10
+ include HTTParty
11
+
12
+ def initialize(buri, apikey)
12
13
  @baseuri = buri
13
- @options = { :headers => { "Authorization" => "Token token=\"#{apikey}\"" }, :base_uri => HTTParty.normalize_base_uri(@baseuri) }
14
- end
15
-
16
- def with_auth(body=nil, &block)
17
- r = block.call(body.nil? ? @options : @options.merge(:body => body))
14
+ @options = { :headers => { "Authorization" => "Token token=\"#{apikey}\"" }, :base_uri => HTTParty.normalize_base_uri(@baseuri) }
15
+ end
16
+
17
+ def with_auth(body=nil, &block)
18
+ r = block.call(body.nil? ? @options : @options.merge(:body => body))
18
19
  r.parsed_response
19
- end
20
-
21
- def place_market_order(side, quantity)
22
- with_auth :side => side, :quantity => quantity, :type => "market" do |options|
23
- self.class.post("/api/v1/orders", options)
24
- end
25
- end
26
-
27
- def place_limit_order(item, currency, side, quantity, price)
28
- with_auth :item => item, :currency => currency, :side => side, :quantity => quantity, :type => "limit", :price => price do |options|
29
- self.class.post("/api/v1/orders", options)
30
- end
31
- end
32
-
33
- def order_info(orderid)
34
- with_auth nil do |options|
35
- self.class.get("/api/v1/orders/#{orderid}", options)
36
- end
37
- end
38
-
39
- def cancel_order(orderid)
40
- with_auth nil do |options|
41
- self.class.delete("/api/v1/orders/#{orderid}", options)
42
- end
43
- end
44
-
45
- # account
46
- def account_info()
47
- with_auth nil do |options|
48
- self.class.get('/api/v1/account', options)
49
- end
50
- end
51
-
52
- # market data
53
- def subscribe_quotes(&block)
54
- Thread.new do
55
- EM.run {
56
- client = Faye::Client.new("https://#{@baseuri}:4000/api")
57
- client.subscribe("/quotes") do |msg|
58
- block.call(msg)
59
- end
60
- }
61
- end
62
- end
63
-
64
- def subscribe_trades(&block)
65
- Thread.new do
66
- EM.run {
67
- client = Faye::Client.new("https://#{@baseuri}:4000/api")
68
- client.subscribe("/trades") do |msg|
69
- begin
70
- pmsg = JSON.parse(msg)
71
- block.call(msg)
72
- rescue Exception
73
- block.call({ :error => "Unable to parse message", :raw => msg })
74
- end
75
- end
76
- }
77
- end
78
- end
79
-
80
- def subscribe_book_updates(item, currency, &block)
81
- Thread.new do
82
- EM.run {
83
- client = Faye::Client.new("https://#{@baseuri}:4000/api")
84
- client.subscribe("/market/#{item}/#{currency}") do |msg|
85
- pmsg = nil
86
- begin
87
- pmsg = JSON.parse(msg)
88
- block.call(pmsg)
89
- rescue Exception
90
- block.call({ :error => "Unable to parse message", :raw => msg })
91
- end
92
- end
93
- }
94
- end
95
- end
96
- end
97
-
98
- class AtlasAdvancedClient < AtlasClient
99
- def cancel_all_orders()
100
- account = account_info
101
- orders = account["orders"]
102
- orders.each do |order|
103
- cancel_order(order)
104
- end
105
- end
106
- end
20
+ end
21
+
22
+ def place_market_order(item, currency, side, quantity)
23
+ with_auth :item => item, :currency => currency, :side => side, :quantity => quantity, :type => "market" do |options|
24
+ self.class.post("/api/v1/orders", options)
25
+ end
26
+ end
27
+
28
+ def place_limit_order(item, currency, side, quantity, price)
29
+ with_auth :item => item, :currency => currency, :side => side, :quantity => quantity, :type => "limit", :price => price do |options|
30
+ self.class.post("/api/v1/orders", options)
31
+ end
32
+ end
33
+
34
+ def order_info(orderid)
35
+ with_auth nil do |options|
36
+ self.class.get("/api/v1/orders/#{orderid}", options)
37
+ end
38
+ end
39
+
40
+ def cancel_order(orderid)
41
+ with_auth nil do |options|
42
+ self.class.delete("/api/v1/orders/#{orderid}", options)
43
+ end
44
+ end
45
+
46
+ # account
47
+ def account_info()
48
+ with_auth nil do |options|
49
+ self.class.get('/api/v1/account', options)
50
+ end
51
+ end
107
52
 
53
+ # market data
54
+ def book(item, currency)
55
+ with_auth :item => item, :currency => currency do
56
+ self.class.get('/api/v1/market/book')
57
+ end
58
+ end
108
59
 
60
+ def recent_trades(item, currency)
61
+ with_auth :item => item, :currency => currency do
62
+ self.class.get('/api/v1/market/trades/recent')
63
+ end
64
+ end
65
+
66
+ # market data
67
+ def subscribe_quotes(&block)
68
+ Thread.new do
69
+ EM.run {
70
+ client = Faye::Client.new("https://#{@baseuri}:4000/api")
71
+ client.subscribe("/quotes") do |msg|
72
+ block.call(msg)
73
+ end
74
+ }
75
+ end
76
+ end
77
+
78
+ def subscribe_trades(&block)
79
+ Thread.new do
80
+ EM.run {
81
+ client = Faye::Client.new("https://#{@baseuri}:4000/api")
82
+ client.subscribe("/trades") do |msg|
83
+ begin
84
+ pmsg = JSON.parse(msg)
85
+ block.call(msg)
86
+ rescue Exception
87
+ block.call({ :error => "Unable to parse message", :raw => msg })
88
+ end
89
+ end
90
+ }
91
+ end
92
+ end
93
+
94
+ def subscribe_book_updates(item, currency, &block)
95
+ Thread.new do
96
+ EM.run {
97
+ client = Faye::Client.new("https://#{@baseuri}:4000/api")
98
+ client.subscribe("/market/#{item}/#{currency}") do |msg|
99
+ pmsg = nil
100
+ begin
101
+ pmsg = JSON.parse(msg)
102
+ block.call(pmsg)
103
+ rescue Exception
104
+ block.call({ :error => "Unable to parse message", :raw => msg })
105
+ end
106
+ end
107
+ }
108
+ end
109
+ end
110
+ 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.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Habeel Ahmed