atlasats 1.0.1
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.
- data/lib/atlasats.rb +85 -0
- metadata +46 -0
data/lib/atlasats.rb
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
require 'eventmachine'
|
4
|
+
require 'httparty'
|
5
|
+
require 'faye'
|
6
|
+
|
7
|
+
class AtlasClient
|
8
|
+
include HTTParty
|
9
|
+
|
10
|
+
def initialize(buri, apikey)
|
11
|
+
@baseuri = buri
|
12
|
+
@options = { :headers => { "Authorization" => "Token token=\"#{apikey}\"" }, :base_uri => HTTParty.normalize_base_uri(@baseuri) }
|
13
|
+
end
|
14
|
+
|
15
|
+
def with_auth(body=nil, &block)
|
16
|
+
r = block.call(body.nil? ? @options : @options.merge(:body => body))
|
17
|
+
r.parsed_response
|
18
|
+
end
|
19
|
+
|
20
|
+
def place_market_order(side, quantity)
|
21
|
+
with_auth :side => side, :quantity => quantity, :type => "market" do |options|
|
22
|
+
self.class.post("/api/v1/orders", options)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def place_limit_order(item, currency, side, quantity, price)
|
27
|
+
with_auth :item => item, :currency => currency, :side => side, :quantity => quantity, :type => "limit", :price => price do |options|
|
28
|
+
self.class.post("/api/v1/orders", options)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def order_info(orderid)
|
33
|
+
with_auth nil do |options|
|
34
|
+
self.class.get("/api/v1/orders/#{orderid}", options)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def cancel_order(orderid)
|
39
|
+
with_auth nil do |options|
|
40
|
+
self.class.delete("/api/v1/orders/#{orderid}", options)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# account
|
45
|
+
def account_info()
|
46
|
+
with_auth nil do |options|
|
47
|
+
self.class.get('/api/v1/account', options)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# market data
|
52
|
+
def subscribe_quotes(&block)
|
53
|
+
Thread.new do
|
54
|
+
EM.run {
|
55
|
+
client = Faye::Client.new("http://data.#{@baseuri}/api")
|
56
|
+
client.subscribe("/quotes") do |msg|
|
57
|
+
block.call(msg)
|
58
|
+
end
|
59
|
+
}
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def subscribe_trades(&block)
|
64
|
+
Thread.new do
|
65
|
+
EM.run {
|
66
|
+
client = Faye::Client.new("http://data.#{@baseuri}/api")
|
67
|
+
client.subscribe("/trades") do |msg|
|
68
|
+
block.call(msg)
|
69
|
+
end
|
70
|
+
}
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
class AtlasAdvancedClient < AtlasClient
|
76
|
+
def cancel_all_orders()
|
77
|
+
account = account_info
|
78
|
+
orders = account["orders"]
|
79
|
+
orders.each do |order|
|
80
|
+
cancel_order(order)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: atlasats
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Habeel Ahmed
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-08-07 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Atlas ATS ruby library. Gives access to order placement and market data.
|
15
|
+
email: habeel@atlasats.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/atlasats.rb
|
21
|
+
homepage: http://rubygems.org/gems/atlasats
|
22
|
+
licenses:
|
23
|
+
- MIT
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
none: false
|
36
|
+
requirements:
|
37
|
+
- - ! '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubyforge_project:
|
42
|
+
rubygems_version: 1.8.24
|
43
|
+
signing_key:
|
44
|
+
specification_version: 3
|
45
|
+
summary: Atlas ATS ruby library.
|
46
|
+
test_files: []
|