class Trader::SurbtcBackend
Constants
- API_PREFIX
- COP_MARKET
- MAIN_MARKET
- STATUS_MAP
- TYPE_MAP
Public Class Methods
new()
click to toggle source
Calls superclass method
Trader::BaseBackend::new
# File lib/trade-o-matic/adapters/surbtc_backend.rb, line 46 def initialize super :surbtc end
Public Instance Methods
cancel_order(_session, _order_id)
click to toggle source
# File lib/trade-o-matic/adapters/surbtc_backend.rb, line 89 def cancel_order(_session, _order_id) res = resource_for "orders/#{_order_id}", _session raw_order = postprocess res.put({ state: 'canceling' }, :content_type => 'application/json') while raw_order['order']['state'] == 'canceling' raw_order = postprocess res.get end SurbtcOrder.new raw_order['order'] end
create_order(_session, _pair, _volume, _price, _instruction)
click to toggle source
# File lib/trade-o-matic/adapters/surbtc_backend.rb, line 72 def create_order(_session, _pair, _volume, _price, _instruction) res = resource_for "markets/#{market_code_for(_pair)}/orders", _session raw_order = postprocess res.post({ order: build_order_json(_price, _volume, _instruction) }, :content_type => 'application/json') SurbtcOrder.new raw_order['order'] end
fetch_order(_session, _order_id)
click to toggle source
# File lib/trade-o-matic/adapters/surbtc_backend.rb, line 82 def fetch_order(_session, _order_id) res = resource_for "orders/#{_order_id}", _session raw_order = postprocess res.get SurbtcOrder.new raw_order['order'] end
get_available_markets()
click to toggle source
# File lib/trade-o-matic/adapters/surbtc_backend.rb, line 50 def get_available_markets [MAIN_MARKET, COP_MARKET] end
get_balance(_session, _currency)
click to toggle source
# File lib/trade-o-matic/adapters/surbtc_backend.rb, line 54 def get_balance(_session, _currency) res = resource_for "balances/#{currency_code_for(_currency)}", _session raw_balance = postprocess res.get if _currency == MAIN_MARKET.base SurbtcBalanceBTC.new raw_balance['balance'] else SurbtcBalance.new raw_balance['balance'] end end
get_orders(_session, _pair)
click to toggle source
# File lib/trade-o-matic/adapters/surbtc_backend.rb, line 65 def get_orders(_session, _pair) res = resource_for "markets/#{market_code_for(_pair)}/orders", _session raw_orders = postprocess res.get raw_orders['orders'].map { |o| SurbtcOrder.new o } end
Private Instance Methods
build_order_json(_price, _volume, _instruction)
click to toggle source
# File lib/trade-o-matic/adapters/surbtc_backend.rb, line 127 def build_order_json(_price, _volume, _instruction) if _price.nil? { amount: _volume.to_i, type: _instruction == Order::BID ? 'bid' : 'ask', price_type: 'market' } else { limit: _price.to_i, amount: _volume.to_i, type: _instruction == Order::BID ? 'bid' : 'ask', price_type: 'limit' } end end
currency_code_for(_currency)
click to toggle source
# File lib/trade-o-matic/adapters/surbtc_backend.rb, line 116 def currency_code_for(_currency) return 'clp' if _currency.code == :CLP_CENT return 'cop' if _currency.code == :COP_CENT return 'btc' if _currency.code == :SATOSHI _currency.to_s.downcase end
market_code_for(_pair)
click to toggle source
# File lib/trade-o-matic/adapters/surbtc_backend.rb, line 123 def market_code_for(_pair) "#{currency_code_for(_pair.base)}-#{currency_code_for(_pair.quote)}" end
postprocess(_response)
click to toggle source
# File lib/trade-o-matic/adapters/surbtc_backend.rb, line 111 def postprocess(_response) # TODO: handle error responses JSON.parse _response end
resource_for(_url, _session=nil)
click to toggle source
# File lib/trade-o-matic/adapters/surbtc_backend.rb, line 105 def resource_for(_url, _session=nil) res = RestClient::Resource.new "#{API_PREFIX}/#{_url}" res.options[:headers] = { params: { 'api_key' => _session[:api_key] } } if _session res end