Class: Trader::SurbtcBackend
- Inherits:
-
Object
- Object
- Trader::SurbtcBackend
show all
- Defined in:
- lib/trade-o-matic/adapters/surbtc_backend.rb
Defined Under Namespace
Classes: SurbtcBalance, SurbtcBalanceBTC, SurbtcOrder
Constant Summary
collapse
- API_PREFIX =
'https://www.surbtc.com/api/v1'
- TYPE_MAP =
{
'ask' => Order::ASK,
'bid' => Order::BID
}
- STATUS_MAP =
{
'received' => AccountOrder::PENDING,
'pending' => AccountOrder::OPEN,
'traded' => AccountOrder::CLOSED,
'canceling' => AccountOrder::OPEN,
'canceled' => AccountOrder::CANCELED
}
- MAIN_MARKET =
CurrencyPair.new(:SATOSHI, :SURBTC_CLP)
Instance Method Summary
collapse
Instance Method Details
#cancel_order(_session, _order_id) ⇒ Object
95
96
97
98
99
100
101
102
103
104
105
106
107
|
# File 'lib/trade-o-matic/adapters/surbtc_backend.rb', line 95
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) ⇒ Object
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/trade-o-matic/adapters/surbtc_backend.rb', line 76
def create_order(_session, _pair, _volume, _price, _instruction)
raise 'market not supported' unless _pair == MAIN_MARKET
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) ⇒ Object
88
89
90
91
92
93
|
# File 'lib/trade-o-matic/adapters/surbtc_backend.rb', line 88
def fetch_order(_session, _order_id)
res = resource_for "orders/#{_order_id}", _session
raw_order = postprocess res.get
SurbtcOrder.new raw_order['order']
end
|
#fill_book(_book) ⇒ Object
50
51
52
|
# File 'lib/trade-o-matic/adapters/surbtc_backend.rb', line 50
def fill_book(_book)
end
|
#get_available_markets ⇒ Object
46
47
48
|
# File 'lib/trade-o-matic/adapters/surbtc_backend.rb', line 46
def get_available_markets
[MAIN_MARKET]
end
|
#get_balance(_session, _currency) ⇒ Object
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/trade-o-matic/adapters/surbtc_backend.rb', line 58
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) ⇒ Object
69
70
71
72
73
74
|
# File 'lib/trade-o-matic/adapters/surbtc_backend.rb', line 69
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
|
#get_session(_credentials) ⇒ Object
54
55
56
|
# File 'lib/trade-o-matic/adapters/surbtc_backend.rb', line 54
def get_session(_credentials)
_credentials
end
|