Class: Honeymaker::Clients::BingX
- Inherits:
-
Honeymaker::Client
- Object
- Honeymaker::Client
- Honeymaker::Clients::BingX
- Defined in:
- lib/honeymaker/clients/bingx.rb
Constant Summary collapse
- URL =
"https://open-api.bingx.com"- RATE_LIMITS =
{ default: 100, orders: 200 }.freeze
Constants inherited from Honeymaker::Client
Instance Attribute Summary
Attributes inherited from Honeymaker::Client
Instance Method Summary collapse
- #cancel_order(symbol:, order_id: nil, client_order_id: nil) ⇒ Object
- #deposit_history(coin: nil, status: nil, start_time: nil, end_time: nil, offset: nil, limit: nil) ⇒ Object
-
#futures_income(symbol: nil, income_type: nil, start_time: nil, end_time: nil, limit: nil) ⇒ Object
— Futures —.
- #get_all_coins_info ⇒ Object
- #get_balances ⇒ Object
- #get_depth(symbol:, limit: nil) ⇒ Object
- #get_klines(symbol:, interval:, start_time: nil, end_time: nil, limit: nil) ⇒ Object
- #get_order(symbol:, order_id: nil, client_order_id: nil) ⇒ Object
- #get_raw_balances ⇒ Object
- #get_symbols ⇒ Object
- #get_ticker(symbol: nil) ⇒ Object
- #get_trade_fills(symbol: nil, order_id: nil, start_time: nil, end_time: nil, from_id: nil, limit: nil) ⇒ Object
- #place_order(symbol:, side:, type:, quantity: nil, quote_order_qty: nil, price: nil, time_in_force: nil, client_order_id: nil) ⇒ Object
- #withdraw(coin:, address:, amount:, network: nil, wallet_type: nil, tag: nil) ⇒ Object
- #withdraw_history(coin: nil, status: nil, start_time: nil, end_time: nil, offset: nil, limit: nil, id: nil) ⇒ Object
Methods inherited from Honeymaker::Client
#initialize, rate_limits, #validate
Constructor Details
This class inherits a constructor from Honeymaker::Client
Instance Method Details
#cancel_order(symbol:, order_id: nil, client_order_id: nil) ⇒ Object
74 75 76 77 78 |
# File 'lib/honeymaker/clients/bingx.rb', line 74 def cancel_order(symbol:, order_id: nil, client_order_id: nil) post_signed("/openApi/spot/v1/trade/cancel", { symbol: symbol, orderId: order_id, clientOrderID: client_order_id }) end |
#deposit_history(coin: nil, status: nil, start_time: nil, end_time: nil, offset: nil, limit: nil) ⇒ Object
91 92 93 94 95 96 |
# File 'lib/honeymaker/clients/bingx.rb', line 91 def deposit_history(coin: nil, status: nil, start_time: nil, end_time: nil, offset: nil, limit: nil) get_signed("/openApi/wallets/v1/capital/deposit/hisrec", { coin: coin, status: status, startTime: start_time, endTime: end_time, offset: offset, limit: limit }) end |
#futures_income(symbol: nil, income_type: nil, start_time: nil, end_time: nil, limit: nil) ⇒ Object
— Futures —
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/honeymaker/clients/bingx.rb', line 114 def futures_income(symbol: nil, income_type: nil, start_time: nil, end_time: nil, limit: nil) with_rescue do params = { symbol: symbol, incomeType: income_type, startTime: start_time, endTime: end_time, limit: limit, timestamp: }.compact params[:signature] = hmac_sha256(@api_secret, Faraday::Utils.build_query(params)) response = futures_connection.get do |req| req.url "/openApi/swap/v2/user/income" req.headers = { "X-BX-APIKEY": @api_key } req.params = params end response.body end end |
#get_all_coins_info ⇒ Object
80 81 82 |
# File 'lib/honeymaker/clients/bingx.rb', line 80 def get_all_coins_info get_signed("/openApi/wallets/v1/capital/config/getall") end |
#get_balances ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/honeymaker/clients/bingx.rb', line 32 def get_balances result = get_raw_balances return result if result.failure? balances = {} raw_balances = result.data.dig("data", "balances") || [] raw_balances.each do |balance| symbol = balance["asset"] free = BigDecimal((balance["free"] || "0").to_s) locked = BigDecimal((balance["locked"] || "0").to_s) next if free.zero? && locked.zero? balances[symbol] = { free: free, locked: locked } end Result::Success.new(balances) end |
#get_depth(symbol:, limit: nil) ⇒ Object
17 18 19 |
# File 'lib/honeymaker/clients/bingx.rb', line 17 def get_depth(symbol:, limit: nil) get_public("/openApi/spot/v1/market/depth", { symbol: symbol, limit: limit }) end |
#get_klines(symbol:, interval:, start_time: nil, end_time: nil, limit: nil) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/honeymaker/clients/bingx.rb', line 21 def get_klines(symbol:, interval:, start_time: nil, end_time: nil, limit: nil) get_public("/openApi/spot/v1/market/kline", { symbol: symbol, interval: interval, startTime: start_time, endTime: end_time, limit: limit }) end |
#get_order(symbol:, order_id: nil, client_order_id: nil) ⇒ Object
64 65 66 67 68 69 70 71 72 |
# File 'lib/honeymaker/clients/bingx.rb', line 64 def get_order(symbol:, order_id: nil, client_order_id: nil) result = get_signed("/openApi/spot/v1/trade/query", { symbol: symbol, orderId: order_id, clientOrderID: client_order_id }) return result if result.failure? raw = result.data.is_a?(Hash) && result.data.key?("data") ? result.data["data"] : result.data Result::Success.new(normalize_order("#{symbol}-#{raw['orderId']}", raw)) end |
#get_raw_balances ⇒ Object
28 29 30 |
# File 'lib/honeymaker/clients/bingx.rb', line 28 def get_raw_balances get_signed("/openApi/spot/v1/account/balance") end |
#get_symbols ⇒ Object
9 10 11 |
# File 'lib/honeymaker/clients/bingx.rb', line 9 def get_symbols get_public("/openApi/spot/v1/common/symbols") end |
#get_ticker(symbol: nil) ⇒ Object
13 14 15 |
# File 'lib/honeymaker/clients/bingx.rb', line 13 def get_ticker(symbol: nil) get_public("/openApi/spot/v2/market/ticker", { symbol: symbol }) end |
#get_trade_fills(symbol: nil, order_id: nil, start_time: nil, end_time: nil, from_id: nil, limit: nil) ⇒ Object
84 85 86 87 88 89 |
# File 'lib/honeymaker/clients/bingx.rb', line 84 def get_trade_fills(symbol: nil, order_id: nil, start_time: nil, end_time: nil, from_id: nil, limit: nil) get_signed("/openApi/spot/v1/trade/fills", { symbol: symbol, orderId: order_id, startTime: start_time, endTime: end_time, fromId: from_id, limit: limit }) end |
#place_order(symbol:, side:, type:, quantity: nil, quote_order_qty: nil, price: nil, time_in_force: nil, client_order_id: nil) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/honeymaker/clients/bingx.rb', line 49 def place_order(symbol:, side:, type:, quantity: nil, quote_order_qty: nil, price: nil, time_in_force: nil, client_order_id: nil) result = post_signed("/openApi/spot/v1/trade/order", { symbol: symbol, side: side, type: type, quantity: quantity, quoteOrderQty: quote_order_qty, price: price, timeInForce: time_in_force, newClientOrderId: client_order_id }) return result if result.failure? raw = result.data order_id = raw.dig("data", "orderId") || raw.dig("data", "data", "orderId") Result::Success.new({ order_id: "#{symbol}-#{order_id}", raw: raw }) end |
#withdraw(coin:, address:, amount:, network: nil, wallet_type: nil, tag: nil) ⇒ Object
105 106 107 108 109 110 |
# File 'lib/honeymaker/clients/bingx.rb', line 105 def withdraw(coin:, address:, amount:, network: nil, wallet_type: nil, tag: nil) post_signed("/openApi/wallets/v1/capital/withdraw/apply", { coin: coin, address: address, amount: amount, network: network, walletType: wallet_type, tag: tag }) end |
#withdraw_history(coin: nil, status: nil, start_time: nil, end_time: nil, offset: nil, limit: nil, id: nil) ⇒ Object
98 99 100 101 102 103 |
# File 'lib/honeymaker/clients/bingx.rb', line 98 def withdraw_history(coin: nil, status: nil, start_time: nil, end_time: nil, offset: nil, limit: nil, id: nil) get_signed("/openApi/wallets/v1/capital/withdraw/history", { coin: coin, status: status, startTime: start_time, endTime: end_time, offset: offset, limit: limit, id: id }) end |