Class: Honeymaker::Clients::BitMart

Inherits:
Honeymaker::Client show all
Defined in:
lib/honeymaker/clients/bitmart.rb

Constant Summary collapse

URL =
"https://api-cloud.bitmart.com"
RATE_LIMITS =
{ default: 100, orders: 200 }.freeze

Constants inherited from Honeymaker::Client

Honeymaker::Client::OPTIONS

Instance Attribute Summary collapse

Attributes inherited from Honeymaker::Client

#api_key, #api_secret

Instance Method Summary collapse

Methods inherited from Honeymaker::Client

rate_limits, #validate

Constructor Details

#initialize(api_key: nil, api_secret: nil, memo: nil, proxy: nil, logger: nil) ⇒ BitMart

Returns a new instance of BitMart.



11
12
13
14
# File 'lib/honeymaker/clients/bitmart.rb', line 11

def initialize(api_key: nil, api_secret: nil, memo: nil, proxy: nil, logger: nil)
  super(api_key: api_key, api_secret: api_secret, proxy: proxy, logger: logger)
  @memo = memo
end

Instance Attribute Details

#memoObject (readonly)

Returns the value of attribute memo.



9
10
11
# File 'lib/honeymaker/clients/bitmart.rb', line 9

def memo
  @memo
end

Instance Method Details

#cancel_order(symbol:, order_id: nil, client_order_id: nil) ⇒ Object



84
85
86
87
88
# File 'lib/honeymaker/clients/bitmart.rb', line 84

def cancel_order(symbol:, order_id: nil, client_order_id: nil)
  post_signed("/spot/v3/cancel_order", {
    symbol: symbol, order_id: order_id, client_order_id: client_order_id
  })
end

#deposit_list(currency: nil, n: nil, status: nil) ⇒ Object



97
98
99
100
101
# File 'lib/honeymaker/clients/bitmart.rb', line 97

def deposit_list(currency: nil, n: nil, status: nil)
  get_signed("/account/v1/deposit-withdraw/detail", {
    currency: currency, N: n, type: "deposit", operation_type: "deposit", status: status
  })
end

#futures_trades(symbol:, start_time: nil, end_time: nil, page_num: nil, page_size: nil) ⇒ Object



144
145
146
147
148
149
# File 'lib/honeymaker/clients/bitmart.rb', line 144

def futures_trades(symbol:, start_time: nil, end_time: nil, page_num: nil, page_size: nil)
  get_signed("/contract/private/trades", {
    symbol: symbol, start_time: start_time, end_time: end_time,
    page_num: page_num, page_size: page_size
  })
end

#futures_transaction_history(start_time: nil, end_time: nil, page_num: nil, page_size: nil, flow_type: nil) ⇒ Object

— Futures —



137
138
139
140
141
142
# File 'lib/honeymaker/clients/bitmart.rb', line 137

def futures_transaction_history(start_time: nil, end_time: nil, page_num: nil, page_size: nil, flow_type: nil)
  get_signed("/contract/private/transaction-history", {
    start_time: start_time, end_time: end_time,
    page_num: page_num, page_size: page_size, flow_type: flow_type
  })
end

#get_balancesObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/honeymaker/clients/bitmart.rb', line 42

def get_balances
  result = get_wallet
  return result if result.failure?

  return Result::Failure.new("BitMart API error") unless result.data["code"] == 1000

  balances = {}
  (result.data.dig("data", "wallet") || []).each do |wallet|
    symbol = wallet["id"]
    free = BigDecimal((wallet["available"] || "0").to_s)
    locked = BigDecimal((wallet["frozen"] || "0").to_s)
    next if free.zero? && locked.zero?
    balances[symbol] = { free: free, locked: locked }
  end

  Result::Success.new(balances)
end

#get_currenciesObject



20
21
22
# File 'lib/honeymaker/clients/bitmart.rb', line 20

def get_currencies
  get_public("/account/v1/currencies")
end

#get_depth(symbol:, limit: nil) ⇒ Object



28
29
30
# File 'lib/honeymaker/clients/bitmart.rb', line 28

def get_depth(symbol:, limit: nil)
  get_public("/spot/quotation/v3/books", { symbol: symbol, limit: limit })
end

#get_klines(symbol:, step:, before: nil, after_time: nil, limit: nil) ⇒ Object



32
33
34
35
36
# File 'lib/honeymaker/clients/bitmart.rb', line 32

def get_klines(symbol:, step:, before: nil, after_time: nil, limit: nil)
  get_public("/spot/quotation/v3/lite-klines", {
    symbol: symbol, step: step, before: before, after: after_time, limit: limit
  })
end

#get_order(order_id:) ⇒ Object



73
74
75
76
77
78
79
80
81
82
# File 'lib/honeymaker/clients/bitmart.rb', line 73

def get_order(order_id:)
  result = post_signed("/spot/v2/order_detail", { orderId: order_id })
  return result if result.failure?
  return Result::Failure.new("BitMart API error") unless result.data["code"] == 1000

  raw = result.data["data"]
  return Result::Failure.new("Order not found") unless raw

  Result::Success.new(normalize_order(order_id.to_s, raw))
end

#get_symbols_detailsObject



16
17
18
# File 'lib/honeymaker/clients/bitmart.rb', line 16

def get_symbols_details
  get_public("/spot/v1/symbols/details")
end

#get_ticker(symbol: nil) ⇒ Object



24
25
26
# File 'lib/honeymaker/clients/bitmart.rb', line 24

def get_ticker(symbol: nil)
  get_public("/spot/quotation/v3/ticker", { symbol: symbol })
end

#get_trades(symbol:, order_mode: nil, start_time: nil, end_time: nil, limit: nil, recv_window: nil) ⇒ Object



90
91
92
93
94
95
# File 'lib/honeymaker/clients/bitmart.rb', line 90

def get_trades(symbol:, order_mode: nil, start_time: nil, end_time: nil, limit: nil, recv_window: nil)
  get_signed("/spot/v2/trades", {
    symbol: symbol, orderMode: order_mode,
    startTime: start_time, endTime: end_time, N: limit, recvWindow: recv_window
  })
end

#get_walletObject



38
39
40
# File 'lib/honeymaker/clients/bitmart.rb', line 38

def get_wallet
  get_signed("/spot/v1/wallet")
end

#get_withdraw_addressesObject



109
110
111
# File 'lib/honeymaker/clients/bitmart.rb', line 109

def get_withdraw_addresses
  get_signed("/account/v1/withdraw/address/list")
end

#margin_borrow_records(symbol: nil, borrow_id: nil, start_time: nil, end_time: nil, n: nil) ⇒ Object

— Margin —



123
124
125
126
127
# File 'lib/honeymaker/clients/bitmart.rb', line 123

def margin_borrow_records(symbol: nil, borrow_id: nil, start_time: nil, end_time: nil, n: nil)
  get_signed("/spot/v1/margin/isolated/borrow_record", {
    symbol: symbol, borrow_id: borrow_id, start_time: start_time, end_time: end_time, N: n
  })
end

#margin_repay_records(symbol: nil, repay_id: nil, currency: nil, start_time: nil, end_time: nil, n: nil) ⇒ Object



129
130
131
132
133
# File 'lib/honeymaker/clients/bitmart.rb', line 129

def margin_repay_records(symbol: nil, repay_id: nil, currency: nil, start_time: nil, end_time: nil, n: nil)
  get_signed("/spot/v1/margin/isolated/repay_record", {
    symbol: symbol, repay_id: repay_id, currency: currency, start_time: start_time, end_time: end_time, N: n
  })
end

#submit_order(symbol:, side:, type:, size: nil, notional: nil, price: nil, client_order_id: nil) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/honeymaker/clients/bitmart.rb', line 60

def submit_order(symbol:, side:, type:, size: nil, notional: nil, price: nil, client_order_id: nil)
  result = post_signed("/spot/v2/submit_order", {
    symbol: symbol, side: side, type: type,
    size: size, notional: notional, price: price,
    client_order_id: client_order_id
  })
  return result if result.failure?
  return Result::Failure.new("BitMart API error") unless result.data["code"] == 1000

  order_id = result.data.dig("data", "order_id")
  Result::Success.new({ order_id: order_id.to_s, raw: result.data })
end

#withdraw(currency:, amount:, address:, address_memo: nil, destination: nil) ⇒ Object



113
114
115
116
117
118
119
# File 'lib/honeymaker/clients/bitmart.rb', line 113

def withdraw(currency:, amount:, address:, address_memo: nil, destination: nil)
  post_signed("/account/v1/withdraw/apply", {
    currency: currency, amount: amount,
    destination: destination || "To Digital Address",
    address: address, address_memo: address_memo
  })
end

#withdraw_list(currency: nil, n: nil, status: nil) ⇒ Object



103
104
105
106
107
# File 'lib/honeymaker/clients/bitmart.rb', line 103

def withdraw_list(currency: nil, n: nil, status: nil)
  get_signed("/account/v1/deposit-withdraw/detail", {
    currency: currency, N: n, type: "withdraw", operation_type: "withdraw", status: status
  })
end