bybit-connector-ruby 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1042,6 +1042,37 @@ module Bybit
1042
1042
  params = Bybit::Utils::WireKeys.camelize(params)
1043
1043
  @session.sign_request(method: :post, path: '/v5/earn/fixed-term/position/auto-invest', body: params)
1044
1044
  end
1045
+
1046
+ # Get Auto Savings Settings
1047
+ #
1048
+ # GET /v5/earn/flexible-saving/auto-savings
1049
+ #
1050
+ # @option kwargs [Array] :coins Coin names to query, for example `coins=BTC&coins=ETH`. Omit for all supported coins.
1051
+ # @return [Hash] Bybit V5 ApiResponse envelope (retCode / retMsg / result / retExtInfo / time).
1052
+ # @see https://bybit-exchange.github.io/docs/v5/finance/earn/flexible-saving/auto-savings
1053
+ def list_auto_savings(**kwargs)
1054
+ coins = kwargs[:coins]
1055
+ if coins.is_a?(Array) && coins.length > 50
1056
+ raise Bybit::ConfigurationError,
1057
+ 'coins supports at most 50 values'
1058
+ end
1059
+ params = Bybit::Utils::WireKeys.camelize(kwargs)
1060
+ @session.sign_request(method: :get, path: '/v5/earn/flexible-saving/auto-savings', params: params)
1061
+ end
1062
+
1063
+ # Edit Auto Savings Settings
1064
+ #
1065
+ # POST /v5/earn/flexible-saving/auto-savings
1066
+ #
1067
+ # @param is_selected [Boolean] Whether to enable auto savings
1068
+ # @option kwargs [String] :coin Coin to change; omit or pass an empty string to change the global setting
1069
+ # @option kwargs [Boolean] :purchase_immediately When enabling, asynchronously attempt to subscribe the available Funding Account balance; ignored when disabling
1070
+ # @return [Hash] Bybit V5 ApiResponse envelope (retCode / retMsg / result / retExtInfo / time).
1071
+ # @see https://bybit-exchange.github.io/docs/v5/finance/earn/flexible-saving/auto-savings
1072
+ def edit_earn_auto_savings(is_selected:, **kwargs)
1073
+ params = Bybit::Utils::WireKeys.camelize(kwargs.merge(isSelected: is_selected))
1074
+ @session.sign_request(method: :post, path: '/v5/earn/flexible-saving/auto-savings', body: params)
1075
+ end
1045
1076
  end
1046
1077
  end
1047
1078
  end
@@ -0,0 +1,92 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bybit
4
+ module RestApi
5
+ class EventService < BaseService
6
+ # Get Event Contract Order History
7
+ #
8
+ # GET /v5/event/order-list
9
+ #
10
+ # @option kwargs [String] :symbol Symbol name, e.g. `BTCUSDT-EC`
11
+ # @option kwargs [String] :order_id Order ID
12
+ # @option kwargs [String] :order_link_id User-defined order ID
13
+ # @option kwargs [Integer] :start_time Start time in milliseconds. Default: 7 days ago
14
+ # @option kwargs [Integer] :end_time End time in milliseconds. Default: now
15
+ # @option kwargs [Integer] :limit Number of items per page. Default: `50`, Range: [`1`, `100`]
16
+ # @option kwargs [String] :cursor Pagination cursor
17
+ # @return [Hash] Bybit V5 ApiResponse envelope (retCode / retMsg / result / retExtInfo / time).
18
+ # @see https://bybit-exchange.github.io/docs/v5/event/trade/order-list
19
+ def get_ec_order_history(**kwargs)
20
+ params = Bybit::Utils::WireKeys.camelize(kwargs)
21
+ @session.sign_request(method: :get, path: '/v5/event/order-list', params: params)
22
+ end
23
+
24
+ # Get Event Contract Active Orders
25
+ #
26
+ # GET /v5/event/order-realtime
27
+ #
28
+ # @option kwargs [String] :symbol Symbol name, e.g. `BTCUSDT-EC`
29
+ # @option kwargs [String] :order_id Order ID. If both `orderId` and `orderLinkId` are passed, `orderId` takes priority
30
+ # @option kwargs [String] :order_link_id User-defined order ID
31
+ # @option kwargs [Integer] :limit Number of items per page. Default: `20`, Range: [`1`, `50`]
32
+ # @option kwargs [String] :cursor Pagination cursor. Use `nextPageCursor` from the response to retrieve the next page
33
+ # @return [Hash] Bybit V5 ApiResponse envelope (retCode / retMsg / result / retExtInfo / time).
34
+ # @see https://bybit-exchange.github.io/docs/v5/event/trade/open-order
35
+ def get_ec_active_orders(**kwargs)
36
+ params = Bybit::Utils::WireKeys.camelize(kwargs)
37
+ @session.sign_request(method: :get, path: '/v5/event/order-realtime', params: params)
38
+ end
39
+
40
+ # Get Event Contract Position Info
41
+ #
42
+ # GET /v5/event/positions
43
+ #
44
+ # @option kwargs [String] :symbol Symbol name, e.g. `BTCUSDT-EC`. If not passed, returns all EC positions
45
+ # @option kwargs [String] :base_coin Base coin filter, e.g. `BTC`
46
+ # @option kwargs [String] :settle_coin Settle coin filter, e.g. `USDT`
47
+ # @option kwargs [Integer] :limit Number of items per page. Default: `20`, Range: [`1`, `50`]
48
+ # @option kwargs [String] :cursor Pagination cursor. Use `nextPageCursor` from the response to retrieve the next page
49
+ # @return [Hash] Bybit V5 ApiResponse envelope (retCode / retMsg / result / retExtInfo / time).
50
+ # @see https://bybit-exchange.github.io/docs/v5/event/trade/position
51
+ def get_ec_position_info(**kwargs)
52
+ params = Bybit::Utils::WireKeys.camelize(kwargs)
53
+ @session.sign_request(method: :get, path: '/v5/event/positions', params: params)
54
+ end
55
+
56
+ # Get Event Contract Settlement Records
57
+ #
58
+ # GET /v5/event/settlements
59
+ #
60
+ # @param symbol [String] Symbol name, e.g. `BTCUSDT-EC`
61
+ # @option kwargs [String] :order_id Order ID filter
62
+ # @option kwargs [Integer] :start_time Start time in milliseconds. Default: 7 days ago
63
+ # @option kwargs [Integer] :end_time End time in milliseconds. Default: now
64
+ # @option kwargs [Integer] :limit Number of items per page. Default: `50`, Range: [`1`, `100`]
65
+ # @option kwargs [String] :cursor Pagination cursor
66
+ # @return [Hash] Bybit V5 ApiResponse envelope (retCode / retMsg / result / retExtInfo / time).
67
+ # @see https://bybit-exchange.github.io/docs/v5/event/trade/settlement
68
+ def get_ec_settlements(symbol:, **kwargs)
69
+ params = Bybit::Utils::WireKeys.camelize(kwargs.merge(symbol: symbol))
70
+ @session.sign_request(method: :get, path: '/v5/event/settlements', params: params)
71
+ end
72
+
73
+ # Get Event Contract Trade History
74
+ #
75
+ # GET /v5/event/trades
76
+ #
77
+ # @param symbol [String] Symbol name, e.g. `BTCUSDT-EC`
78
+ # @option kwargs [String] :order_id Order ID filter
79
+ # @option kwargs [String] :order_link_id User-defined order ID
80
+ # @option kwargs [Integer] :start_time Start time in milliseconds. Default: 7 days ago
81
+ # @option kwargs [Integer] :end_time End time in milliseconds. Default: now
82
+ # @option kwargs [Integer] :limit Number of items per page. Default: `50`, Range: [`1`, `100`]
83
+ # @option kwargs [String] :cursor Pagination cursor
84
+ # @return [Hash] Bybit V5 ApiResponse envelope (retCode / retMsg / result / retExtInfo / time).
85
+ # @see https://bybit-exchange.github.io/docs/v5/event/trade/execution
86
+ def get_ec_trade_history(symbol:, **kwargs)
87
+ params = Bybit::Utils::WireKeys.camelize(kwargs.merge(symbol: symbol))
88
+ @session.sign_request(method: :get, path: '/v5/event/trades', params: params)
89
+ end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,110 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bybit
4
+ module RestApi
5
+ class FiatService < BaseService
6
+ # Query Account Balance
7
+ #
8
+ # GET /v5/fiat/balance-query
9
+ #
10
+ # @option kwargs [String] :account_category Account type (reserved field)
11
+ # @option kwargs [String] :currency Currency code:
12
+ # - Fiat: ISO 4217 standard code, e.g., EUR, GEL, KZT
13
+ # - Crypto: e.g., USDT, BTC, ETH
14
+ # - Omit to query all balances
15
+ # @return [Hash] Bybit V5 ApiResponse envelope (retCode / retMsg / result / retExtInfo / time).
16
+ # @see https://bybit-exchange.github.io/docs/v5/asset/fiat-convert/balance-query
17
+ def query_balance(**kwargs)
18
+ params = Bybit::Utils::WireKeys.camelize(kwargs)
19
+ @session.sign_request(method: :get, path: '/v5/fiat/balance-query', params: params)
20
+ end
21
+
22
+ # Get Trading Pairs
23
+ #
24
+ # GET /v5/fiat/query-coin-list
25
+ #
26
+ # @option kwargs [Integer] :side Trading direction:
27
+ # - `0`: buy - Buy crypto, sell fiat
28
+ # - `1`: sell - Sell crypto, buy fiat
29
+ # @return [Hash] Bybit V5 ApiResponse envelope (retCode / retMsg / result / retExtInfo / time).
30
+ # @see https://bybit-exchange.github.io/docs/v5/asset/fiat-convert/query-coin-list
31
+ def query_coin_list(**kwargs)
32
+ params = Bybit::Utils::WireKeys.camelize(kwargs)
33
+ @session.sign_request(method: :get, path: '/v5/fiat/query-coin-list', params: params)
34
+ end
35
+
36
+ # Query Trade History
37
+ #
38
+ # GET /v5/fiat/query-trade-history
39
+ #
40
+ # @option kwargs [Integer] :index Page number, starts from 1
41
+ # @option kwargs [Integer] :limit Page size, maximum 100
42
+ # @option kwargs [String] :start_time Query start time (millisecond timestamp)
43
+ # @option kwargs [String] :end_time Query end time (millisecond timestamp)
44
+ # @return [Hash] Bybit V5 ApiResponse envelope (retCode / retMsg / result / retExtInfo / time).
45
+ # @see https://bybit-exchange.github.io/docs/v5/asset/fiat-convert/query-trade-history
46
+ def query_trade_history(**kwargs)
47
+ params = Bybit::Utils::WireKeys.camelize(kwargs)
48
+ @session.sign_request(method: :get, path: '/v5/fiat/query-trade-history', params: params)
49
+ end
50
+
51
+ # Request a Quote
52
+ #
53
+ # POST /v5/fiat/quote-apply
54
+ #
55
+ # @param from_coin [String] Convert from coin (coin to sell)
56
+ # @param from_coin_type [String] From coin type
57
+ # @param to_coin [String] Convert to coin (coin to buy)
58
+ # @param to_coin_type [String] To coin type
59
+ # @param request_amount [String] Request coin amount (the amount you want to sell)
60
+ # @option kwargs [String] :request_coin_type Coin type you want to sell, defaults to fiat
61
+ # @return [Hash] Bybit V5 ApiResponse envelope (retCode / retMsg / result / retExtInfo / time).
62
+ # @see https://bybit-exchange.github.io/docs/v5/asset/fiat-convert/quote-apply
63
+ def apply_quote(from_coin:, from_coin_type:, to_coin:, to_coin_type:, request_amount:, **kwargs)
64
+ params = Bybit::Utils::WireKeys.camelize(kwargs.merge(fromCoin: from_coin, fromCoinType: from_coin_type, toCoin: to_coin, toCoinType: to_coin_type, requestAmount: request_amount))
65
+ @session.sign_request(method: :post, path: '/v5/fiat/quote-apply', body: params)
66
+ end
67
+
68
+ # Get Reference Price
69
+ #
70
+ # GET /v5/fiat/reference-price
71
+ #
72
+ # @param symbol [String] Coin pair, format: "FIAT-CRYPTO", e.g., "EUR-USDT"
73
+ # @option kwargs [String] :payment_method Payment method (reserved field)
74
+ # @return [Hash] Bybit V5 ApiResponse envelope (retCode / retMsg / result / retExtInfo / time).
75
+ # @see https://bybit-exchange.github.io/docs/v5/asset/fiat-convert/reference-price
76
+ def get_reference_price(symbol:, **kwargs)
77
+ params = Bybit::Utils::WireKeys.camelize(kwargs.merge(symbol: symbol))
78
+ @session.sign_request(method: :get, path: '/v5/fiat/reference-price', params: params)
79
+ end
80
+
81
+ # Confirm Quote and Execute Trade
82
+ #
83
+ # POST /v5/fiat/trade-execute
84
+ #
85
+ # @param quote_tx_id [String] Quote transaction ID from the quote request
86
+ # @param sub_user_id [String] The user's sub userId in Bybit
87
+ # @option kwargs [String] :webhook_url Optional webhook URL to receive trade status notifications (max 256 characters)
88
+ # @option kwargs [String] :merchant_request_id Customised request ID (max 36 characters). Generally it is useless, but convenient for internal tracking
89
+ # @return [Hash] Bybit V5 ApiResponse envelope (retCode / retMsg / result / retExtInfo / time).
90
+ # @see https://bybit-exchange.github.io/docs/v5/asset/fiat-convert/confirm-quote
91
+ def confirm_quote(quote_tx_id:, sub_user_id:, **kwargs)
92
+ params = Bybit::Utils::WireKeys.camelize(kwargs.merge(quoteTxId: quote_tx_id, subUserId: sub_user_id))
93
+ @session.sign_request(method: :post, path: '/v5/fiat/trade-execute', body: params)
94
+ end
95
+
96
+ # Query Trade Status
97
+ #
98
+ # GET /v5/fiat/trade-query
99
+ #
100
+ # @option kwargs [String] :trade_no Trade order number (either tradeNo or merchantRequestId must be provided)
101
+ # @option kwargs [String] :merchant_request_id Merchant request ID (either tradeNo or merchantRequestId must be provided)
102
+ # @return [Hash] Bybit V5 ApiResponse envelope (retCode / retMsg / result / retExtInfo / time).
103
+ # @see https://bybit-exchange.github.io/docs/v5/asset/fiat-convert/query-trade
104
+ def query_trade(**kwargs)
105
+ params = Bybit::Utils::WireKeys.camelize(kwargs)
106
+ @session.sign_request(method: :get, path: '/v5/fiat/trade-query', params: params)
107
+ end
108
+ end
109
+ end
110
+ end
@@ -95,12 +95,34 @@ module Bybit
95
95
  # @param order_id [String] Loan order ID to repay
96
96
  # @param amount [String] Repayment amount
97
97
  # @return [Hash] Bybit V5 ApiResponse envelope (retCode / retMsg / result / retExtInfo / time).
98
- # @see https://bybit-exchange.github.io/docs/v5/otc/repay-loan
98
+ # @see https://bybit-exchange.github.io/docs/v5/otc/repay
99
99
  def repay_loan(order_id:, amount:, **kwargs)
100
100
  params = kwargs.merge(order_id: order_id, amount: amount)
101
101
  params = Bybit::Utils::WireKeys.camelize(params)
102
102
  @session.sign_request(method: :post, path: '/v5/ins-loan/repay-loan', body: params)
103
103
  end
104
+
105
+ # Get Coin Delta Amount
106
+ #
107
+ # GET /v5/ins-loan/coin-delta-amount
108
+ #
109
+ # @option kwargs [String] :coin Coin name to filter, uppercase only. e.g. `BTC`. If not passed, returns all coins.
110
+ # @return [Hash] Bybit V5 ApiResponse envelope (retCode / retMsg / result / retExtInfo / time).
111
+ # @see https://bybit-exchange.github.io/docs/v5/otc/coin-delta-amount
112
+ def ins_loan_coin_delta_amount(**kwargs)
113
+ params = Bybit::Utils::WireKeys.camelize(kwargs)
114
+ @session.sign_request(method: :get, path: '/v5/ins-loan/coin-delta-amount', params: params)
115
+ end
116
+
117
+ # Get Delay Liquidation Status
118
+ #
119
+ # GET /v5/ins-loan/delay-liq-status
120
+ #
121
+ # @return [Hash] Bybit V5 ApiResponse envelope (retCode / retMsg / result / retExtInfo / time).
122
+ # @see https://bybit-exchange.github.io/docs/v5/otc/delay-liq-status
123
+ def ins_loan_delay_liq_status
124
+ @session.sign_request(method: :get, path: '/v5/ins-loan/delay-liq-status')
125
+ end
104
126
  end
105
127
  end
106
128
  end
@@ -350,6 +350,23 @@ module Bybit
350
350
  params = Bybit::Utils::WireKeys.camelize(params)
351
351
  @session.public_request(path: '/v5/market/tickers', params: params)
352
352
  end
353
+
354
+ # Get Option Base Coins
355
+ #
356
+ # GET /v5/market/option-base-coins
357
+ #
358
+ # @option kwargs [String] :underlying_type Underlying asset type. Supports comma-separated values, e.g. `0,2`.
359
+ # - `0`: Crypto
360
+ # - `1`: Commodity
361
+ # - `2`: Stock
362
+ # - `3`: Forex
363
+ # - `4`: Oil
364
+ # @return [Hash] Bybit V5 ApiResponse envelope (retCode / retMsg / result / retExtInfo / time).
365
+ # @see https://bybit-exchange.github.io/docs/v5/market/option-base-coins
366
+ def get_option_base_coins(**kwargs)
367
+ params = Bybit::Utils::WireKeys.camelize(kwargs)
368
+ @session.public_request(path: '/v5/market/option-base-coins', params: params)
369
+ end
353
370
  end
354
371
  end
355
372
  end
@@ -197,6 +197,21 @@ module Bybit
197
197
  params = Bybit::Utils::WireKeys.camelize(params)
198
198
  @session.sign_request(method: :post, path: '/v5/position/switch-mode', body: params)
199
199
  end
200
+
201
+ # Get Futures Leverage
202
+ #
203
+ # GET /v5/position/symbol-info
204
+ #
205
+ # @param category [String] Product type:
206
+ # - `linear`: USDT perpetual, USDC contract
207
+ # - `inverse`: Inverse perpetual, Inverse futures
208
+ # @option kwargs [String] :symbol Symbol name, e.g. `BTCUSDT`, uppercase only
209
+ # @return [Hash] Bybit V5 ApiResponse envelope (retCode / retMsg / result / retExtInfo / time).
210
+ # @see https://bybit-exchange.github.io/docs/v5/position/batch-lvg
211
+ def get_symbol_info(category:, **kwargs)
212
+ params = Bybit::Utils::WireKeys.camelize(kwargs.merge(category: category))
213
+ @session.sign_request(method: :get, path: '/v5/position/symbol-info', params: params)
214
+ end
200
215
  end
201
216
  end
202
217
  end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bybit
4
+ module RestApi
5
+ class ReferralService < BaseService
6
+ # Get referral rules and campaign task rewards for the current site
7
+ #
8
+ # POST /v5/referral/campaign/rewards
9
+ #
10
+ # @return [Hash] Bybit V5 ApiResponse envelope (retCode / retMsg / result / retExtInfo / time).
11
+ # @see https://bybit-exchange.github.io/docs/v5/referral/referral-campaign-rewards
12
+ def get_campaign_rewards
13
+ @session.sign_request(method: :post, path: '/v5/referral/campaign/rewards')
14
+ end
15
+
16
+ # Get Referral Commission Records
17
+ #
18
+ # POST /v5/referral/commission/records
19
+ #
20
+ # @option kwargs [Array] :user_id_list Invitee ID list; an empty list does not filter by invitee.
21
+ # @option kwargs [String] :start_time Query start time in YYYY-MM-DD HH:mm:ss format; an invalid value is passed downstream as an empty string, whose handling is unverified.
22
+ # @option kwargs [String] :end_time Query end time in YYYY-MM-DD HH:mm:ss format; an invalid value is passed downstream as an empty string, whose handling is unverified.
23
+ # @option kwargs [Integer] :page One-based page number; 0 is treated as 1.
24
+ # @option kwargs [Integer] :page_size Number of records per page; 0 or a value greater than 200 is treated as 10.
25
+ # @option kwargs [Integer] :product_line Product lines: 0=unknown; 1=spot; 2=contracts; 3=options; 4=USDC perpetual; 6=TradeFi; 9=Alpha. Unrecognized downstream product lines map to 0.
26
+ # @return [Hash] Bybit V5 ApiResponse envelope (retCode / retMsg / result / retExtInfo / time).
27
+ # @see https://bybit-exchange.github.io/docs/v5/referral/referral-commission-records
28
+ def get_commission_records(**kwargs)
29
+ params = Bybit::Utils::WireKeys.camelize(kwargs)
30
+ @session.sign_request(method: :post, path: '/v5/referral/commission/records', body: params)
31
+ end
32
+
33
+ # Get Referral User Identity Profile
34
+ #
35
+ # POST /v5/referral/user/identity-profile
36
+ #
37
+ # @return [Hash] Bybit V5 ApiResponse envelope (retCode / retMsg / result / retExtInfo / time).
38
+ # @see https://bybit-exchange.github.io/docs/v5/referral/referral-user-identity-profile
39
+ def get_user_identity_profile
40
+ @session.sign_request(method: :post, path: '/v5/referral/user/identity-profile')
41
+ end
42
+
43
+ # Get referral user invitations
44
+ #
45
+ # POST /v5/referral/user/invitations
46
+ #
47
+ # @option kwargs [Array] :user_id_list
48
+ # @option kwargs [String] :start_time Recommended format: YYYY-MM-DD HH:mm:ss; invalid or empty values are passed downstream as 0.
49
+ # @option kwargs [String] :end_time Recommended format: YYYY-MM-DD HH:mm:ss; invalid or empty values are passed downstream as 0.
50
+ # @option kwargs [Integer] :page
51
+ # @option kwargs [Integer] :page_size Values 0 and greater than 200 are reset to 10 by the current service implementation.
52
+ # @option kwargs [Integer] :friend_status
53
+ # @return [Hash] Bybit V5 ApiResponse envelope (retCode / retMsg / result / retExtInfo / time).
54
+ # @see https://bybit-exchange.github.io/docs/v5/referral/referral-user-invitations
55
+ def get_user_invitations(**kwargs)
56
+ params = Bybit::Utils::WireKeys.camelize(kwargs)
57
+ @session.sign_request(method: :post, path: '/v5/referral/user/invitations', body: params)
58
+ end
59
+ end
60
+ end
61
+ end
@@ -57,6 +57,264 @@ module Bybit
57
57
  params = Bybit::Utils::WireKeys.camelize(params)
58
58
  @session.public_request(path: '/v5/spot-margin-trade/data', params: params)
59
59
  end
60
+
61
+ # Get Spot Margin Coin State
62
+ #
63
+ # GET /v5/spot-margin-trade/coinstate
64
+ #
65
+ # @option kwargs [String] :currency Coin name, uppercase only. e.g. `BTC`. If not passed, returns all coin states.
66
+ # @return [Hash] Bybit V5 ApiResponse envelope (retCode / retMsg / result / retExtInfo / time).
67
+ # @see https://bybit-exchange.github.io/docs/v5/spot-margin-uta/coinstate
68
+ def get_trade_coin_state(**kwargs)
69
+ params = Bybit::Utils::WireKeys.camelize(kwargs)
70
+ @session.sign_request(method: :get, path: '/v5/spot-margin-trade/coinstate', params: params)
71
+ end
72
+
73
+ # Query Fixed-Rate Available Inventory
74
+ #
75
+ # GET /v5/spot-margin-trade/fixed-available-inventory
76
+ #
77
+ # @param currency [String] Borrow coin name, uppercase only. e.g. `USDT`, `BTC`. **Required.**
78
+ # @param term [String] Loan term in days. e.g. `7`, `14`, `30`, `90`, `180`. **Required.**
79
+ # @param annual_rate [String] Annual interest rate. e.g. `0.02` means 2%. **Required.**
80
+ # @return [Hash] Bybit V5 ApiResponse envelope (retCode / retMsg / result / retExtInfo / time).
81
+ # @see https://bybit-exchange.github.io/docs/v5/spot-margin-uta/fixed-available-inventory
82
+ def query_fixed_available_inventory(currency:, term:, annual_rate:)
83
+ params = Bybit::Utils::WireKeys.camelize({ currency: currency, term: term, annualRate: annual_rate })
84
+ @session.sign_request(method: :get, path: '/v5/spot-margin-trade/fixed-available-inventory', params: params)
85
+ end
86
+
87
+ # Fixed-Rate Borrow
88
+ #
89
+ # POST /v5/spot-margin-trade/fixedborrow
90
+ #
91
+ # @param order_currency [String] Borrow coin name, uppercase only. e.g. `USDT`, `BTC`.
92
+ # @param order_amount [String] Borrow amount.
93
+ # @param annual_rate [String] Annual interest rate. e.g. `0.02` means 2%.
94
+ # @param term [String] Loan term in days. Supported values: `7`, `14`, `30`, `90`, `180`.
95
+ # @option kwargs [String] :repay_type Maturity handling type.
96
+ # - `1`: Auto-repay at maturity (default)
97
+ # - `2`: Convert to flexible-rate (variable-rate) loan at maturity
98
+ # @option kwargs [String] :strategy_type Order strategy.
99
+ # - `PARTIAL`: Partial fill or cancel (immediate-or-cancel)
100
+ # - `FULL`: Fill or kill (all-or-nothing)
101
+ # @return [Hash] Bybit V5 ApiResponse envelope (retCode / retMsg / result / retExtInfo / time).
102
+ # @see https://bybit-exchange.github.io/docs/v5/spot-margin-uta/fixedborrow
103
+ def account_fixed_borrow(order_currency:, order_amount:, annual_rate:, term:, **kwargs)
104
+ params = Bybit::Utils::WireKeys.camelize(kwargs.merge(orderCurrency: order_currency, orderAmount: order_amount, annualRate: annual_rate, term: term))
105
+ @session.sign_request(method: :post, path: '/v5/spot-margin-trade/fixedborrow', body: params)
106
+ end
107
+
108
+ # Query Fixed-Rate Borrow Contracts
109
+ #
110
+ # GET /v5/spot-margin-trade/fixedborrow-contract-info
111
+ #
112
+ # @option kwargs [String] :order_id Filter by borrow order ID.
113
+ # @option kwargs [String] :order_currency Filter by borrow coin name, uppercase only. e.g. `USDT`.
114
+ # @option kwargs [String] :term Filter by loan term in days. e.g. `7`, `14`, `30`, `90`, `180`.
115
+ # @option kwargs [String] :limit Page size. Range: [1, 100]. Default: `10`.
116
+ # @option kwargs [String] :cursor Cursor for pagination. Use `nextPageCursor` from previous response.
117
+ # @return [Hash] Bybit V5 ApiResponse envelope (retCode / retMsg / result / retExtInfo / time).
118
+ # @see https://bybit-exchange.github.io/docs/v5/spot-margin-uta/fixedborrow-contract-info
119
+ def query_fixed_borrow_contracts(**kwargs)
120
+ params = Bybit::Utils::WireKeys.camelize(kwargs)
121
+ @session.sign_request(method: :get, path: '/v5/spot-margin-trade/fixedborrow-contract-info', params: params)
122
+ end
123
+
124
+ # Query Fixed-Rate Borrow Orders
125
+ #
126
+ # GET /v5/spot-margin-trade/fixedborrow-order-info
127
+ #
128
+ # @option kwargs [String] :order_id Filter by borrow order ID.
129
+ # @option kwargs [String] :order_currency Filter by borrow coin name, uppercase only. e.g. `USDT`.
130
+ # @option kwargs [String] :state Filter by order state.
131
+ # - `1`: Matching (order accepted, matching in progress)
132
+ # - `2`: Partially filled & cancelled
133
+ # - `3`: Fully filled
134
+ # - `4`: Cancelled
135
+ # @option kwargs [String] :term Filter by loan term in days. e.g. `7`, `14`, `30`, `90`, `180`.
136
+ # @option kwargs [String] :limit Page size. Range: [1, 100]. Default: `10`.
137
+ # @option kwargs [String] :cursor Cursor for pagination. Use `nextPageCursor` from previous response.
138
+ # @return [Hash] Bybit V5 ApiResponse envelope (retCode / retMsg / result / retExtInfo / time).
139
+ # @see https://bybit-exchange.github.io/docs/v5/spot-margin-uta/fixedborrow-order-info
140
+ def query_fixed_borrow_orders(**kwargs)
141
+ params = Bybit::Utils::WireKeys.camelize(kwargs)
142
+ @session.sign_request(method: :get, path: '/v5/spot-margin-trade/fixedborrow-order-info', params: params)
143
+ end
144
+
145
+ # Query Fixed-Rate Borrow Market
146
+ #
147
+ # GET /v5/spot-margin-trade/fixedborrow-order-quote
148
+ #
149
+ # @param order_currency [String] Borrow coin name, uppercase only. e.g. `USDT`, `BTC`. **Required.**
150
+ # @option kwargs [String] :order_by Sort field.
151
+ # - `apy`: Sort by annual interest rate
152
+ # - `term`: Sort by loan term
153
+ # - `quantity`: Sort by available quantity
154
+ # @option kwargs [String] :term Filter by loan term in days. e.g. `7`, `14`, `30`, `90`, `180`.
155
+ # @option kwargs [Integer] :sort Sort order.
156
+ # - `0`: Ascending (default)
157
+ # - `1`: Descending
158
+ # @option kwargs [Integer] :limit Page size. Range: [1, 100]. Default: `10`.
159
+ # @return [Hash] Bybit V5 ApiResponse envelope (retCode / retMsg / result / retExtInfo / time).
160
+ # @see https://bybit-exchange.github.io/docs/v5/spot-margin-uta/fixedborrow-order-quote
161
+ def query_fixed_borrow_market(order_currency:, **kwargs)
162
+ params = Bybit::Utils::WireKeys.camelize(kwargs.merge(order_currency: order_currency))
163
+ @session.sign_request(method: :get, path: '/v5/spot-margin-trade/fixedborrow-order-quote', params: params)
164
+ end
165
+
166
+ # Renew Fixed-Rate Borrow
167
+ #
168
+ # POST /v5/spot-margin-trade/fixedborrow-renew
169
+ #
170
+ # @param loan_id [String] The loan contract ID (corresponds to match order ID). Required.
171
+ # @option kwargs [String] :qty Renewal amount.
172
+ # - If not provided, the full prepayment amount of the contract is used
173
+ # - Must be greater than 0
174
+ # @return [Hash] Bybit V5 ApiResponse envelope (retCode / retMsg / result / retExtInfo / time).
175
+ # @see https://bybit-exchange.github.io/docs/v5/spot-margin-uta/fixedborrow-renew
176
+ def renew_fixed_borrow(loan_id:, **kwargs)
177
+ params = Bybit::Utils::WireKeys.camelize(kwargs.merge(loanId: loan_id))
178
+ @session.sign_request(method: :post, path: '/v5/spot-margin-trade/fixedborrow-renew', body: params)
179
+ end
180
+
181
+ # Get Flexible Available Inventory
182
+ #
183
+ # GET /v5/spot-margin-trade/flexible-available-inventory
184
+ #
185
+ # @param currency [String] Coin name, uppercase only. e.g. `BTC`
186
+ # @return [Hash] Bybit V5 ApiResponse envelope (retCode / retMsg / result / retExtInfo / time).
187
+ # @see https://bybit-exchange.github.io/docs/v5/spot-margin-uta/flexible-available-inventory
188
+ def get_trade_flexible_available_inventory(currency:)
189
+ params = Bybit::Utils::WireKeys.camelize({ currency: currency })
190
+ @session.sign_request(method: :get, path: '/v5/spot-margin-trade/flexible-available-inventory', params: params)
191
+ end
192
+
193
+ # Get Auto Repay Mode
194
+ #
195
+ # GET /v5/spot-margin-trade/get-auto-repay-mode
196
+ #
197
+ # @option kwargs [String] :currency Coin name, uppercase only. e.g. `ETH`. When omitted, returns settings for all currencies.
198
+ # @return [Hash] Bybit V5 ApiResponse envelope (retCode / retMsg / result / retExtInfo / time).
199
+ # @see https://bybit-exchange.github.io/docs/v5/spot-margin-uta/get-auto-repay-mode
200
+ def get_trade_auto_repay_mode(**kwargs)
201
+ params = Bybit::Utils::WireKeys.camelize(kwargs)
202
+ @session.sign_request(method: :get, path: '/v5/spot-margin-trade/get-auto-repay-mode', params: params)
203
+ end
204
+
205
+ # Query Borrow Liability
206
+ #
207
+ # GET /v5/spot-margin-trade/liability
208
+ #
209
+ # @param currency [String] Coin name, uppercase only. e.g. `USDT`, `BTC`. **Required.**
210
+ # @return [Hash] Bybit V5 ApiResponse envelope (retCode / retMsg / result / retExtInfo / time).
211
+ # @see https://bybit-exchange.github.io/docs/v5/spot-margin-uta/liability
212
+ def query_borrow_liability(currency:)
213
+ params = Bybit::Utils::WireKeys.camelize({ currency: currency })
214
+ @session.sign_request(method: :get, path: '/v5/spot-margin-trade/liability', params: params)
215
+ end
216
+
217
+ # Get Max Borrowable Amount
218
+ #
219
+ # GET /v5/spot-margin-trade/max-borrowable
220
+ #
221
+ # @param currency [String] Coin name, uppercase only. e.g. `BTC`
222
+ # @return [Hash] Bybit V5 ApiResponse envelope (retCode / retMsg / result / retExtInfo / time).
223
+ # @see https://bybit-exchange.github.io/docs/v5/spot-margin-uta/max-borrowable
224
+ def get_trade_max_borrowable(currency:)
225
+ params = Bybit::Utils::WireKeys.camelize({ currency: currency })
226
+ @session.sign_request(method: :get, path: '/v5/spot-margin-trade/max-borrowable', params: params)
227
+ end
228
+
229
+ # Get Repayment Available Amount
230
+ #
231
+ # GET /v5/spot-margin-trade/repayment-available-amount
232
+ #
233
+ # @param currency [String] Coin name, uppercase only. e.g. `BTC`
234
+ # @return [Hash] Bybit V5 ApiResponse envelope (retCode / retMsg / result / retExtInfo / time).
235
+ # @see https://bybit-exchange.github.io/docs/v5/spot-margin-uta/repayment-available-amount
236
+ def get_trade_repayment_available_amount(currency:)
237
+ params = Bybit::Utils::WireKeys.camelize({ currency: currency })
238
+ @session.sign_request(method: :get, path: '/v5/spot-margin-trade/repayment-available-amount', params: params)
239
+ end
240
+
241
+ # Set Auto Repay Mode
242
+ #
243
+ # POST /v5/spot-margin-trade/set-auto-repay-mode
244
+ #
245
+ # @param auto_repay_mode [String] Auto repay mode switch:
246
+ # - `1`: Enable auto repay — Enable auto repay
247
+ # - `0`: Disable auto repay — Disable auto repay
248
+ # @option kwargs [String] :currency Coin name, uppercase only (e.g. `USDT`, `ETH`).
249
+ # If omitted, auto-repay is enabled/disabled for **all** currencies.
250
+ # @return [Hash] Bybit V5 ApiResponse envelope (retCode / retMsg / result / retExtInfo / time).
251
+ # @see https://bybit-exchange.github.io/docs/v5/spot-margin-uta/set-auto-repay-mode
252
+ def set_auto_repay_mode(auto_repay_mode:, **kwargs)
253
+ params = Bybit::Utils::WireKeys.camelize(kwargs.merge(autoRepayMode: auto_repay_mode))
254
+ @session.sign_request(method: :post, path: '/v5/spot-margin-trade/set-auto-repay-mode', body: params)
255
+ end
256
+
257
+ # Set spot cross margin leverage
258
+ #
259
+ # POST /v5/spot-margin-trade/set-leverage
260
+ #
261
+ # @param leverage [String] Leverage amount, valid range is 2 to 10
262
+ # @option kwargs [String] :currency Coin name, uppercase only (optional)
263
+ # @return [Hash] Bybit V5 ApiResponse envelope (retCode / retMsg / result / retExtInfo / time).
264
+ # @see https://bybit-exchange.github.io/docs/v5/spot-margin-uta/set-leverage
265
+ def spot_margin_set_leverage(leverage:, **kwargs)
266
+ params = Bybit::Utils::WireKeys.camelize(kwargs.merge(leverage: leverage))
267
+ @session.sign_request(method: :post, path: '/v5/spot-margin-trade/set-leverage', body: params)
268
+ end
269
+
270
+ # Get Spot Margin Trade Status
271
+ #
272
+ # GET /v5/spot-margin-trade/state
273
+ #
274
+ # @return [Hash] Bybit V5 ApiResponse envelope (retCode / retMsg / result / retExtInfo / time).
275
+ # @see https://bybit-exchange.github.io/docs/v5/spot-margin-uta/status
276
+ def get_trade_state
277
+ @session.sign_request(method: :get, path: '/v5/spot-margin-trade/state')
278
+ end
279
+
280
+ # Toggle spot cross margin mode
281
+ #
282
+ # POST /v5/spot-margin-trade/switch-mode
283
+ #
284
+ # @param spot_margin_mode [String] Spot margin mode: 1=on, 0=off
285
+ # @return [Hash] Bybit V5 ApiResponse envelope (retCode / retMsg / result / retExtInfo / time).
286
+ # @see https://bybit-exchange.github.io/docs/v5/spot-margin-uta/switch-mode
287
+ def spot_margin_switch_mode(spot_margin_mode:)
288
+ params = Bybit::Utils::WireKeys.camelize({ spotMarginMode: spot_margin_mode })
289
+ @session.sign_request(method: :post, path: '/v5/spot-margin-trade/switch-mode', body: params)
290
+ end
291
+
292
+ # Query Fixed-Rate Borrow Penalty Interest
293
+ #
294
+ # GET /v5/spot-margin-trade/fixedborrow-interest-accrued
295
+ #
296
+ # @option kwargs [String] :order_id Filter by fixed-rate borrow order ID.
297
+ # @option kwargs [String] :order_currency Filter by a single borrow coin, such as `USDT`.
298
+ # @option kwargs [String] :limit Page size as a string, from 1 to 100; defaults to 10.
299
+ # @option kwargs [String] :cursor Opaque `nextPageCursor` returned by the previous page.
300
+ # @return [Hash] Bybit V5 ApiResponse envelope (retCode / retMsg / result / retExtInfo / time).
301
+ # @see https://bybit-exchange.github.io/docs/v5/spot-margin-uta/fixedborrow-interest-accrued
302
+ def query_fixed_borrow_penalty_interest(**kwargs)
303
+ params = Bybit::Utils::WireKeys.camelize(kwargs)
304
+ @session.sign_request(method: :get, path: '/v5/spot-margin-trade/fixedborrow-interest-accrued', params: params)
305
+ end
306
+
307
+ # Cancel Fixed-Rate Borrow Order
308
+ #
309
+ # POST /v5/spot-margin-trade/fixedborrow-order-cancel
310
+ #
311
+ # @param order_id [String] Fixed-rate borrow order ID, not the contract match ID.
312
+ # @return [Hash] Bybit V5 ApiResponse envelope (retCode / retMsg / result / retExtInfo / time).
313
+ # @see https://bybit-exchange.github.io/docs/v5/spot-margin-uta/fixedborrow-order-cancel
314
+ def cancel_fixed_borrow_order(order_id:)
315
+ params = Bybit::Utils::WireKeys.camelize({ orderId: order_id })
316
+ @session.sign_request(method: :post, path: '/v5/spot-margin-trade/fixedborrow-order-cancel', body: params)
317
+ end
60
318
  end
61
319
  end
62
320
  end