class AtlasClient

Public Class Methods

new(buri, apikey) click to toggle source
# File lib/atlasats.rb, line 12
def initialize(buri, apikey)
        # strip out 'http://' or 'https://' since it's no longer the user's choice
        cleanuri = buri.gsub(/http:\/\/|https:\/\//, '')
        ## Only production environments require HTTPS
        # Use HTTP if the base URI matches either:
        # - 'test.*' OR
        # - 'dev.*'
        prefix = /^test\.|^dev\./.match(cleanuri).nil? ? 'https://' : 'http://'
        # produce the correct @baseuri
        @baseuri = prefix + cleanuri
        @options = { :headers => { "Authorization" => "Token token=\"#{apikey}\"" }, :base_uri => HTTParty.normalize_base_uri(@baseuri) }
end

Public Instance Methods

account_info() click to toggle source

account

# File lib/atlasats.rb, line 68
def account_info()
        with_auth_query nil do |options|
                self.class.get('/api/v1/account', options)
        end
end
book(item, currency) click to toggle source
# File lib/atlasats.rb, line 98
def book(item, currency)
        with_auth_query :item => item, :currency => currency do |options|
                self.class.get('/api/v1/market/book', options)
        end
end
cancel_order(orderid) click to toggle source
# File lib/atlasats.rb, line 53
def cancel_order(orderid)
        with_auth nil do |options|
                self.class.delete("/api/v1/orders/#{orderid}", options)
        end
end
coins() click to toggle source

get all crypto-currency/coins

# File lib/atlasats.rb, line 75
def coins ()
        res = with_auth_query nil do |options|
                self.class.get('/api/v1/market/symbols', options)
        end
        coins = []
        res.each do |symbol|
                coins.push symbol if symbol["market_id"] == 0
        end
        coins
end
options() click to toggle source

get all option contracts

# File lib/atlasats.rb, line 87
def options ()
        res = with_auth_query nil do |options|
                self.class.get('/api/v1/market/symbols', options)
        end
        contracts = []
        res.each do |symbol|
                contracts.push symbol if symbol["exp"]
        end
        contracts
end
order_info(orderid) click to toggle source
# File lib/atlasats.rb, line 47
def order_info(orderid)
        with_auth_query nil do |options|
                self.class.get("/api/v1/orders/#{orderid}", options)
        end
end
place_limit_order(item, currency, side, quantity, price) click to toggle source
# File lib/atlasats.rb, line 41
def place_limit_order(item, currency, side, quantity, price)
        with_auth :item => item, :currency => currency, :side => side, :quantity => quantity, :type => "limit", :price => price do |options|
                self.class.post("/api/v1/orders", options)
        end
end
place_market_order(item, currency, side, quantity) click to toggle source
# File lib/atlasats.rb, line 35
def place_market_order(item, currency, side, quantity)
        with_auth :item => item, :currency => currency, :side => side, :quantity => quantity, :type => "market" do |options|
                self.class.post("/api/v1/orders", options)
        end
end
recent_orders() click to toggle source

For most accounts this will return todays orders both (open, cancelled and done except rejects) but for some users who do alot of orders you can only rely on it to give you open orders

# File lib/atlasats.rb, line 61
def recent_orders()
        with_auth nil do |options|
                self.class.get("/api/v1/orders", options)
end
end
recent_trades(item, currency) click to toggle source
# File lib/atlasats.rb, line 104
def recent_trades(item, currency)
        with_auth_query :item => item, :currency => currency do |options|
                self.class.get('/api/v1/market/trades/recent', options)
        end
end
subscribe_all_trades(&block) click to toggle source

market data

# File lib/atlasats.rb, line 111
def subscribe_all_trades(&block)
        Thread.new do
                EM.run {
                        client = Faye::Client.new("#{@baseuri}/api/v1/streaming")
                        client.subscribe("/trades") do |msg|
                                begin
                                        pmsg = JSON.parse(msg)
                                        block.call(msg)
                                rescue Exception
                                        block.call({ :error => "Unable to parse message", :raw => msg })
                                end
                        end
                }
        end
end
subscribe_book_updates(item, currency, &block) click to toggle source
# File lib/atlasats.rb, line 145
def subscribe_book_updates(item, currency, &block)
        Thread.new do
                EM.run {
                        client = Faye::Client.new("#{@baseuri}/api/v1/streaming")
                        client.subscribe("/market") do |msg|
                                pmsg = nil
                                begin
                                        pmsg = JSON.parse(msg)
                                        if pmsg["symbol"] == item and pmsg["currency"] == currency
                                                block.call(pmsg)
                                        end
                                rescue Exception
                                        block.call({ :error => "Unable to parse message", :raw => msg })
                                end
                        end
                }
        end
end
subscribe_trades(item, currency, &block) click to toggle source
# File lib/atlasats.rb, line 127
def subscribe_trades(item, currency, &block)
        Thread.new do
                EM.run {
                        client = Faye::Client.new("#{@baseuri}/api/v1/streaming")
                        client.subscribe("/trades") do |msg|
                                begin
                                        pmsg = JSON.parse(msg)
                                        if pmsg["symbol"] == item and pmsg["currency"] == currency
                                                block.call(msg)
                                        end
                                rescue Exception
                                        block.call({ :error => "Unable to parse message", :raw => msg })
                                end
                        end
                }
        end
end
with_auth(body=nil, &block) click to toggle source
# File lib/atlasats.rb, line 25
def with_auth(body=nil, &block)
        r = block.call(body.nil? ? @options : @options.merge(:body => body))
        r.parsed_response
end
with_auth_query(body=nil, &block) click to toggle source
# File lib/atlasats.rb, line 30
def with_auth_query(body=nil, &block)
        r = block.call(body.nil? ? @options : @options.merge(:query => body))
        r.parsed_response
end