Class: Mexbt::Account
Constant Summary
Constants included
from Client
Client::SSL_VERSION
Instance Method Summary
collapse
Methods included from Client
#auth_params, #call, #call_data, #private_key, #public_key, #url, #user_id
Methods included from Common
#trades
Constructor Details
#initialize(credentials = {}) ⇒ Account
Returns a new instance of Account.
8
9
10
11
12
13
14
|
# File 'lib/mexbt/account.rb', line 8
def initialize(credentials={})
recognized_credentials = [:public_key, :private_key, :user_id, :currency_pair, :sandbox]
recognized_credentials.each do |k|
credential = credentials[k] || Mexbt.send(k)
instance_variable_set(:"@#{k}", credentials[k])
end
end
|
Instance Method Details
#cancel_all_orders(currency_pair: Mexbt.currency_pair) ⇒ Object
76
77
78
|
# File 'lib/mexbt/account.rb', line 76
def cancel_all_orders(currency_pair: Mexbt.currency_pair)
call("orders/cancel-all", { ins: currency_pair } )
end
|
#cancel_order(id:, currency_pair: Mexbt.currency_pair) ⇒ Object
72
73
74
|
# File 'lib/mexbt/account.rb', line 72
def cancel_order(id:, currency_pair: Mexbt.currency_pair)
call("orders/cancel", { ins: currency_pair, serverOrderId: id })
end
|
#create_order(amount:, price: nil, currency_pair: Mexbt.currency_pair, side: :buy, type: :market) ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/mexbt/account.rb', line 51
def create_order(amount:, price: nil, currency_pair: Mexbt.currency_pair, side: :buy, type: :market)
amount = format_amount(amount)
type =
case type
when :market, 1
1
when :limit, 0
0
else
raise "Unknown order type '#{type}'"
end
params = {
ins: currency_pair,
side: side,
orderType: type,
qty: amount
}
params[:px] = price if price
call("orders/create", params)
end
|
#endpoint ⇒ Object
24
25
26
|
# File 'lib/mexbt/account.rb', line 24
def endpoint
"https://private-api#{sandbox ? '-sandbox' : nil}.mexbt.com"
end
|
#modify_order(id:, action:, currency_pair: Mexbt.currency_pair) ⇒ Object
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/mexbt/account.rb', line 80
def modify_order(id:, action:, currency_pair: Mexbt.currency_pair)
action =
case action
when :move_to_top, 0
0
when :execute_now, 1
1
else
raise "Action must be one of: :move_to_top, :execute_now"
end
call("orders/modify", { ins: currency_pair, serverOrderId: id, modifyAction: action } )
end
|
#private? ⇒ Boolean
16
17
18
|
# File 'lib/mexbt/account.rb', line 16
def private?
true
end
|
#sandbox ⇒ Object
20
21
22
|
# File 'lib/mexbt/account.rb', line 20
def sandbox
@sandbox || Mexbt.sandbox
end
|
#withdraw(amount:, address:, currency: :btc) ⇒ Object
41
42
43
44
45
46
47
48
49
|
# File 'lib/mexbt/account.rb', line 41
def withdraw(amount:, address:, currency: :btc)
call("withdraw", { ins: currency, amount: format_amount(amount), sendToAddress: address })
rescue RuntimeError => e
if sandbox
puts "Withdrawals do not yet work on the sandbox :( Let's pretend..."
else
raise e
end
end
|