class Mexbt::Account
Public Class Methods
new(credentials={})
click to toggle source
# 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
Public Instance Methods
cancel_all_orders(currency_pair: Mexbt.currency_pair)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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()
click to toggle source
# 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)
click to toggle source
# 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?()
click to toggle source
# File lib/mexbt/account.rb, line 16 def private? true end
sandbox()
click to toggle source
# File lib/mexbt/account.rb, line 20 def sandbox @sandbox || Mexbt.sandbox end
withdraw(amount:, address:, currency: :btc)
click to toggle source
# 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
Private Instance Methods
format_amount(amount)
click to toggle source
# File lib/mexbt/account.rb, line 95 def format_amount(amount) # Horribly hack because sandbox only accepts 6 decimal places thanks to AP BigDecimal.new(amount, 15).round(sandbox ? 6 : 8).to_s end