Class: Honeymaker::Clients::Bitget
- Inherits:
-
Honeymaker::Client
- Object
- Honeymaker::Client
- Honeymaker::Clients::Bitget
- Defined in:
- lib/honeymaker/clients/bitget.rb
Constant Summary collapse
- URL =
"https://api.bitget.com"- RATE_LIMITS =
{ default: 100, orders: 200 }.freeze
Constants inherited from Honeymaker::Client
Instance Attribute Summary collapse
-
#passphrase ⇒ Object
readonly
Returns the value of attribute passphrase.
Attributes inherited from Honeymaker::Client
Instance Method Summary collapse
- #cancel_order(symbol:, order_id: nil, client_oid: nil) ⇒ Object
- #deposit_list(coin: nil, start_time: nil, end_time: nil, limit: nil, id_less_than: nil) ⇒ Object
-
#earn_savings_assets(coin: nil, filter: nil) ⇒ Object
— Earn —.
- #earn_savings_redeem_result(coin: nil, start_time: nil, end_time: nil, limit: nil, id_less_than: nil) ⇒ Object
- #earn_savings_subscribe_result(coin: nil, start_time: nil, end_time: nil, limit: nil, id_less_than: nil) ⇒ Object
-
#futures_account_bills(product_type:, coin: nil, business: nil, start_time: nil, end_time: nil, limit: nil, id_less_than: nil) ⇒ Object
— Futures —.
- #futures_fills_history(product_type:, symbol: nil, order_id: nil, start_time: nil, end_time: nil, limit: nil, id_less_than: nil) ⇒ Object
- #get_account_assets(coin: nil) ⇒ Object
- #get_balances ⇒ Object
- #get_candles(symbol:, granularity:, start_time: nil, end_time: nil, limit: nil) ⇒ Object
- #get_coins ⇒ Object
- #get_fills(symbol: nil, order_id: nil, start_time: nil, end_time: nil, limit: nil, id_less_than: nil) ⇒ Object
- #get_order(order_id: nil, client_oid: nil) ⇒ Object
- #get_orderbook(symbol:, limit: nil) ⇒ Object
- #get_symbols ⇒ Object
- #get_tickers(symbol: nil) ⇒ Object
-
#initialize(api_key: nil, api_secret: nil, passphrase: nil, proxy: nil, logger: nil) ⇒ Bitget
constructor
A new instance of Bitget.
-
#margin_crossed_borrow_history(loan_id: nil, coin: nil, start_time: nil, end_time: nil, limit: nil, id_less_than: nil) ⇒ Object
— Margin (Cross) —.
- #margin_crossed_interest_history(coin: nil, start_time: nil, end_time: nil, limit: nil, id_less_than: nil) ⇒ Object
- #margin_crossed_liquidation_history(start_time: nil, end_time: nil, limit: nil, id_less_than: nil) ⇒ Object
- #margin_crossed_repay_history(repay_id: nil, coin: nil, start_time: nil, end_time: nil, limit: nil, id_less_than: nil) ⇒ Object
-
#margin_isolated_borrow_history(symbol: nil, loan_id: nil, coin: nil, start_time: nil, end_time: nil, limit: nil, id_less_than: nil) ⇒ Object
— Margin (Isolated) —.
- #margin_isolated_interest_history(symbol: nil, coin: nil, start_time: nil, end_time: nil, limit: nil, id_less_than: nil) ⇒ Object
- #margin_isolated_liquidation_history(symbol: nil, start_time: nil, end_time: nil, limit: nil, id_less_than: nil) ⇒ Object
- #margin_isolated_repay_history(symbol: nil, repay_id: nil, coin: nil, start_time: nil, end_time: nil, limit: nil, id_less_than: nil) ⇒ Object
- #place_order(symbol:, side:, order_type:, size: nil, quote_size: nil, price: nil, force: nil, client_oid: nil) ⇒ Object
- #withdraw(coin:, address:, size:, transfer_type: nil, chain: nil, tag: nil, client_oid: nil) ⇒ Object
- #withdrawal_list(coin: nil, start_time: nil, end_time: nil, limit: nil, id_less_than: nil) ⇒ Object
Methods inherited from Honeymaker::Client
Constructor Details
#initialize(api_key: nil, api_secret: nil, passphrase: nil, proxy: nil, logger: nil) ⇒ Bitget
Returns a new instance of Bitget.
11 12 13 14 |
# File 'lib/honeymaker/clients/bitget.rb', line 11 def initialize(api_key: nil, api_secret: nil, passphrase: nil, proxy: nil, logger: nil) super(api_key: api_key, api_secret: api_secret, proxy: proxy, logger: logger) @passphrase = passphrase end |
Instance Attribute Details
#passphrase ⇒ Object (readonly)
Returns the value of attribute passphrase.
9 10 11 |
# File 'lib/honeymaker/clients/bitget.rb', line 9 def passphrase @passphrase end |
Instance Method Details
#cancel_order(symbol:, order_id: nil, client_oid: nil) ⇒ Object
85 86 87 88 89 |
# File 'lib/honeymaker/clients/bitget.rb', line 85 def cancel_order(symbol:, order_id: nil, client_oid: nil) post_signed("/api/v2/spot/trade/cancel-order", { symbol: symbol, orderId: order_id, clientOid: client_oid }) end |
#deposit_list(coin: nil, start_time: nil, end_time: nil, limit: nil, id_less_than: nil) ⇒ Object
98 99 100 101 102 |
# File 'lib/honeymaker/clients/bitget.rb', line 98 def deposit_list(coin: nil, start_time: nil, end_time: nil, limit: nil, id_less_than: nil) get_signed("/api/v2/spot/wallet/deposit-records", { coin: coin, startTime: start_time, endTime: end_time, limit: limit, idLessThan: id_less_than }) end |
#earn_savings_assets(coin: nil, filter: nil) ⇒ Object
— Earn —
192 193 194 |
# File 'lib/honeymaker/clients/bitget.rb', line 192 def earn_savings_assets(coin: nil, filter: nil) get_signed("/api/v2/earn/savings/assets", { coin: coin, filter: filter }) end |
#earn_savings_redeem_result(coin: nil, start_time: nil, end_time: nil, limit: nil, id_less_than: nil) ⇒ Object
202 203 204 205 206 |
# File 'lib/honeymaker/clients/bitget.rb', line 202 def earn_savings_redeem_result(coin: nil, start_time: nil, end_time: nil, limit: nil, id_less_than: nil) get_signed("/api/v2/earn/savings/redeem-result", { coin: coin, startTime: start_time, endTime: end_time, limit: limit, idLessThan: id_less_than }) end |
#earn_savings_subscribe_result(coin: nil, start_time: nil, end_time: nil, limit: nil, id_less_than: nil) ⇒ Object
196 197 198 199 200 |
# File 'lib/honeymaker/clients/bitget.rb', line 196 def earn_savings_subscribe_result(coin: nil, start_time: nil, end_time: nil, limit: nil, id_less_than: nil) get_signed("/api/v2/earn/savings/subscribe-result", { coin: coin, startTime: start_time, endTime: end_time, limit: limit, idLessThan: id_less_than }) end |
#futures_account_bills(product_type:, coin: nil, business: nil, start_time: nil, end_time: nil, limit: nil, id_less_than: nil) ⇒ Object
— Futures —
176 177 178 179 180 181 |
# File 'lib/honeymaker/clients/bitget.rb', line 176 def futures_account_bills(product_type:, coin: nil, business: nil, start_time: nil, end_time: nil, limit: nil, id_less_than: nil) get_signed("/api/v2/mix/account/bill", { productType: product_type, coin: coin, business: business, startTime: start_time, endTime: end_time, limit: limit, idLessThan: id_less_than }) end |
#futures_fills_history(product_type:, symbol: nil, order_id: nil, start_time: nil, end_time: nil, limit: nil, id_less_than: nil) ⇒ Object
183 184 185 186 187 188 |
# File 'lib/honeymaker/clients/bitget.rb', line 183 def futures_fills_history(product_type:, symbol: nil, order_id: nil, start_time: nil, end_time: nil, limit: nil, id_less_than: nil) get_signed("/api/v2/mix/order/fills-history", { productType: product_type, symbol: symbol, orderId: order_id, startTime: start_time, endTime: end_time, limit: limit, idLessThan: id_less_than }) end |
#get_account_assets(coin: nil) ⇒ Object
39 40 41 |
# File 'lib/honeymaker/clients/bitget.rb', line 39 def get_account_assets(coin: nil) get_signed("/api/v2/spot/account/assets", { coin: coin }) end |
#get_balances ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/honeymaker/clients/bitget.rb', line 43 def get_balances result = get_account_assets return result if result.failure? return Result::Failure.new("Bitget API error") unless result.data["code"] == "00000" balances = {} (result.data["data"] || []).each do |asset| symbol = asset["coin"] free = BigDecimal((asset["available"] || "0").to_s) locked = BigDecimal((asset["frozen"] || "0").to_s) next if free.zero? && locked.zero? balances[symbol] = { free: free, locked: locked } end Result::Success.new(balances) end |
#get_candles(symbol:, granularity:, start_time: nil, end_time: nil, limit: nil) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/honeymaker/clients/bitget.rb', line 32 def get_candles(symbol:, granularity:, start_time: nil, end_time: nil, limit: nil) get_public("/api/v2/spot/market/candles", { symbol: symbol, granularity: granularity, startTime: start_time, endTime: end_time, limit: limit }) end |
#get_coins ⇒ Object
16 17 18 |
# File 'lib/honeymaker/clients/bitget.rb', line 16 def get_coins get_public("/api/v2/spot/public/coins") end |
#get_fills(symbol: nil, order_id: nil, start_time: nil, end_time: nil, limit: nil, id_less_than: nil) ⇒ Object
91 92 93 94 95 96 |
# File 'lib/honeymaker/clients/bitget.rb', line 91 def get_fills(symbol: nil, order_id: nil, start_time: nil, end_time: nil, limit: nil, id_less_than: nil) get_signed("/api/v2/spot/trade/fills", { symbol: symbol, orderId: order_id, startTime: start_time, endTime: end_time, limit: limit, idLessThan: id_less_than }) end |
#get_order(order_id: nil, client_oid: nil) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/honeymaker/clients/bitget.rb', line 73 def get_order(order_id: nil, client_oid: nil) result = get_signed("/api/v2/spot/trade/orderInfo", { orderId: order_id, clientOid: client_oid }) return result if result.failure? return Result::Failure.new("Bitget API error") unless result.data["code"] == "00000" order_list = result.data["data"] raw = order_list.is_a?(Array) ? order_list.first : order_list return Result::Failure.new("Order not found") unless raw Result::Success.new(normalize_order(raw["orderId"] || order_id, raw)) end |
#get_orderbook(symbol:, limit: nil) ⇒ Object
28 29 30 |
# File 'lib/honeymaker/clients/bitget.rb', line 28 def get_orderbook(symbol:, limit: nil) get_public("/api/v2/spot/market/orderbook", { symbol: symbol, limit: limit }) end |
#get_symbols ⇒ Object
20 21 22 |
# File 'lib/honeymaker/clients/bitget.rb', line 20 def get_symbols get_public("/api/v2/spot/public/symbols") end |
#get_tickers(symbol: nil) ⇒ Object
24 25 26 |
# File 'lib/honeymaker/clients/bitget.rb', line 24 def get_tickers(symbol: nil) get_public("/api/v2/spot/market/tickers", { symbol: symbol }) end |
#margin_crossed_borrow_history(loan_id: nil, coin: nil, start_time: nil, end_time: nil, limit: nil, id_less_than: nil) ⇒ Object
— Margin (Cross) —
119 120 121 122 123 124 |
# File 'lib/honeymaker/clients/bitget.rb', line 119 def margin_crossed_borrow_history(loan_id: nil, coin: nil, start_time: nil, end_time: nil, limit: nil, id_less_than: nil) get_signed("/api/v2/margin/crossed/borrow-history", { loanId: loan_id, coin: coin, startTime: start_time, endTime: end_time, limit: limit, idLessThan: id_less_than }) end |
#margin_crossed_interest_history(coin: nil, start_time: nil, end_time: nil, limit: nil, id_less_than: nil) ⇒ Object
133 134 135 136 137 |
# File 'lib/honeymaker/clients/bitget.rb', line 133 def margin_crossed_interest_history(coin: nil, start_time: nil, end_time: nil, limit: nil, id_less_than: nil) get_signed("/api/v2/margin/crossed/interest-history", { coin: coin, startTime: start_time, endTime: end_time, limit: limit, idLessThan: id_less_than }) end |
#margin_crossed_liquidation_history(start_time: nil, end_time: nil, limit: nil, id_less_than: nil) ⇒ Object
139 140 141 142 143 |
# File 'lib/honeymaker/clients/bitget.rb', line 139 def margin_crossed_liquidation_history(start_time: nil, end_time: nil, limit: nil, id_less_than: nil) get_signed("/api/v2/margin/crossed/liquidation-history", { startTime: start_time, endTime: end_time, limit: limit, idLessThan: id_less_than }) end |
#margin_crossed_repay_history(repay_id: nil, coin: nil, start_time: nil, end_time: nil, limit: nil, id_less_than: nil) ⇒ Object
126 127 128 129 130 131 |
# File 'lib/honeymaker/clients/bitget.rb', line 126 def margin_crossed_repay_history(repay_id: nil, coin: nil, start_time: nil, end_time: nil, limit: nil, id_less_than: nil) get_signed("/api/v2/margin/crossed/repay-history", { repayId: repay_id, coin: coin, startTime: start_time, endTime: end_time, limit: limit, idLessThan: id_less_than }) end |
#margin_isolated_borrow_history(symbol: nil, loan_id: nil, coin: nil, start_time: nil, end_time: nil, limit: nil, id_less_than: nil) ⇒ Object
— Margin (Isolated) —
147 148 149 150 151 152 |
# File 'lib/honeymaker/clients/bitget.rb', line 147 def margin_isolated_borrow_history(symbol: nil, loan_id: nil, coin: nil, start_time: nil, end_time: nil, limit: nil, id_less_than: nil) get_signed("/api/v2/margin/isolated/borrow-history", { symbol: symbol, loanId: loan_id, coin: coin, startTime: start_time, endTime: end_time, limit: limit, idLessThan: id_less_than }) end |
#margin_isolated_interest_history(symbol: nil, coin: nil, start_time: nil, end_time: nil, limit: nil, id_less_than: nil) ⇒ Object
161 162 163 164 165 166 |
# File 'lib/honeymaker/clients/bitget.rb', line 161 def margin_isolated_interest_history(symbol: nil, coin: nil, start_time: nil, end_time: nil, limit: nil, id_less_than: nil) get_signed("/api/v2/margin/isolated/interest-history", { symbol: symbol, coin: coin, startTime: start_time, endTime: end_time, limit: limit, idLessThan: id_less_than }) end |
#margin_isolated_liquidation_history(symbol: nil, start_time: nil, end_time: nil, limit: nil, id_less_than: nil) ⇒ Object
168 169 170 171 172 |
# File 'lib/honeymaker/clients/bitget.rb', line 168 def margin_isolated_liquidation_history(symbol: nil, start_time: nil, end_time: nil, limit: nil, id_less_than: nil) get_signed("/api/v2/margin/isolated/liquidation-history", { symbol: symbol, startTime: start_time, endTime: end_time, limit: limit, idLessThan: id_less_than }) end |
#margin_isolated_repay_history(symbol: nil, repay_id: nil, coin: nil, start_time: nil, end_time: nil, limit: nil, id_less_than: nil) ⇒ Object
154 155 156 157 158 159 |
# File 'lib/honeymaker/clients/bitget.rb', line 154 def margin_isolated_repay_history(symbol: nil, repay_id: nil, coin: nil, start_time: nil, end_time: nil, limit: nil, id_less_than: nil) get_signed("/api/v2/margin/isolated/repay-history", { symbol: symbol, repayId: repay_id, coin: coin, startTime: start_time, endTime: end_time, limit: limit, idLessThan: id_less_than }) end |
#place_order(symbol:, side:, order_type:, size: nil, quote_size: nil, price: nil, force: nil, client_oid: nil) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/honeymaker/clients/bitget.rb', line 61 def place_order(symbol:, side:, order_type:, size: nil, quote_size: nil, price: nil, force: nil, client_oid: nil) result = post_signed("/api/v2/spot/trade/place-order", { symbol: symbol, side: side, orderType: order_type, size: size, quoteSize: quote_size, price: price, force: force, clientOid: client_oid }) return result if result.failure? return Result::Failure.new("Bitget API error") unless result.data["code"] == "00000" order_id = result.data.dig("data", "orderId") Result::Success.new({ order_id: "#{symbol}-#{order_id}", raw: result.data }) end |
#withdraw(coin:, address:, size:, transfer_type: nil, chain: nil, tag: nil, client_oid: nil) ⇒ Object
110 111 112 113 114 115 |
# File 'lib/honeymaker/clients/bitget.rb', line 110 def withdraw(coin:, address:, size:, transfer_type: nil, chain: nil, tag: nil, client_oid: nil) post_signed("/api/v2/spot/wallet/withdrawal", { coin: coin, transferType: transfer_type, address: address, size: size, chain: chain, tag: tag, clientOid: client_oid }) end |
#withdrawal_list(coin: nil, start_time: nil, end_time: nil, limit: nil, id_less_than: nil) ⇒ Object
104 105 106 107 108 |
# File 'lib/honeymaker/clients/bitget.rb', line 104 def withdrawal_list(coin: nil, start_time: nil, end_time: nil, limit: nil, id_less_than: nil) get_signed("/api/v2/spot/wallet/withdrawal-records", { coin: coin, startTime: start_time, endTime: end_time, limit: limit, idLessThan: id_less_than }) end |