bybit-connector-ruby 0.1.0 → 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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +203 -1
- data/README.md +159 -14
- data/examples/quickstart.rb +36 -7
- data/lib/bybit/client.rb +44 -16
- data/lib/bybit/error.rb +13 -5
- data/lib/bybit/rest_api/account_service.rb +50 -0
- data/lib/bybit/rest_api/alpha_service.rb +545 -0
- data/lib/bybit/rest_api/asset_service.rb +17 -0
- data/lib/bybit/rest_api/broker_service.rb +9 -4
- data/lib/bybit/rest_api/crypto_loan_service.rb +60 -0
- data/lib/bybit/rest_api/earn_service.rb +31 -0
- data/lib/bybit/rest_api/event_service.rb +92 -0
- data/lib/bybit/rest_api/fiat_service.rb +110 -0
- data/lib/bybit/rest_api/institutional_loan_service.rb +128 -0
- data/lib/bybit/rest_api/market_service.rb +17 -4
- data/lib/bybit/rest_api/misc_service.rb +36 -0
- data/lib/bybit/rest_api/position_service.rb +15 -0
- data/lib/bybit/rest_api/pre_upgrade_service.rb +130 -0
- data/lib/bybit/rest_api/referral_service.rb +61 -0
- data/lib/bybit/rest_api/spot_margin_service.rb +258 -0
- data/lib/bybit/rest_api/spot_x_service.rb +142 -0
- data/lib/bybit/rest_api/spread_trade_service.rb +202 -0
- data/lib/bybit/rest_api/strategy_service.rb +105 -0
- data/lib/bybit/rest_api/tax_service.rb +37 -0
- data/lib/bybit/rest_api/user_service.rb +10 -0
- data/lib/bybit/session.rb +18 -7
- data/lib/bybit/version.rb +1 -1
- data/lib/bybit/websocket/client.rb +294 -0
- data/lib/bybit/websocket.rb +9 -0
- metadata +62 -7
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Bybit
|
|
4
|
+
module RestApi
|
|
5
|
+
# /v5/pre-upgrade/* — historical queries scoped to activity that occurred
|
|
6
|
+
# BEFORE a Classic → UTA account upgrade. These records live in the legacy
|
|
7
|
+
# partition and never merge into the UTA tables, so callers upgrading from
|
|
8
|
+
# older SDKs need a dedicated namespace to fetch them.
|
|
9
|
+
class PreUpgradeService < BaseService
|
|
10
|
+
# Get Pre-upgrade Order History
|
|
11
|
+
#
|
|
12
|
+
# GET /v5/pre-upgrade/order/history
|
|
13
|
+
#
|
|
14
|
+
# @param category [String] Product type: `linear`, `inverse`, `option`
|
|
15
|
+
# @option kwargs [String] :symbol Symbol filter
|
|
16
|
+
# @option kwargs [String] :base_coin Base coin filter
|
|
17
|
+
# @option kwargs [String] :order_id Order ID filter
|
|
18
|
+
# @option kwargs [String] :order_link_id User-side order link ID
|
|
19
|
+
# @option kwargs [String] :order_filter Order-type filter
|
|
20
|
+
# @option kwargs [String] :order_status Order status filter
|
|
21
|
+
# @option kwargs [Integer] :start_time Start ms timestamp
|
|
22
|
+
# @option kwargs [Integer] :end_time End ms timestamp
|
|
23
|
+
# @option kwargs [Integer] :limit Records per page
|
|
24
|
+
# @option kwargs [String] :cursor Pagination cursor
|
|
25
|
+
# @return [Hash] Bybit V5 ApiResponse envelope (retCode / retMsg / result / retExtInfo / time).
|
|
26
|
+
# @see https://bybit-exchange.github.io/docs/v5/pre-upgrade/order-list
|
|
27
|
+
def get_order_history(category:, **kwargs)
|
|
28
|
+
params = kwargs.merge(category: category)
|
|
29
|
+
params = Bybit::Utils::WireKeys.camelize(params)
|
|
30
|
+
@session.sign_request(method: :get, path: '/v5/pre-upgrade/order/history', params: params)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Get Pre-upgrade Trade (Execution) History
|
|
34
|
+
#
|
|
35
|
+
# GET /v5/pre-upgrade/execution/list
|
|
36
|
+
#
|
|
37
|
+
# @param category [String] Product type: `linear`, `inverse`, `option`
|
|
38
|
+
# @option kwargs [String] :symbol Symbol filter
|
|
39
|
+
# @option kwargs [String] :order_id Order ID filter
|
|
40
|
+
# @option kwargs [String] :order_link_id User-side order link ID
|
|
41
|
+
# @option kwargs [String] :base_coin Base coin filter
|
|
42
|
+
# @option kwargs [Integer] :start_time Start ms timestamp
|
|
43
|
+
# @option kwargs [Integer] :end_time End ms timestamp
|
|
44
|
+
# @option kwargs [String] :exec_type Execution type filter
|
|
45
|
+
# @option kwargs [Integer] :limit Records per page
|
|
46
|
+
# @option kwargs [String] :cursor Pagination cursor
|
|
47
|
+
# @return [Hash] Bybit V5 ApiResponse envelope (retCode / retMsg / result / retExtInfo / time).
|
|
48
|
+
# @see https://bybit-exchange.github.io/docs/v5/pre-upgrade/execution
|
|
49
|
+
def get_trade_history(category:, **kwargs)
|
|
50
|
+
params = kwargs.merge(category: category)
|
|
51
|
+
params = Bybit::Utils::WireKeys.camelize(params)
|
|
52
|
+
@session.sign_request(method: :get, path: '/v5/pre-upgrade/execution/list', params: params)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# Get Pre-upgrade Closed PnL
|
|
56
|
+
#
|
|
57
|
+
# GET /v5/pre-upgrade/position/closed-pnl
|
|
58
|
+
#
|
|
59
|
+
# Bybit V5 only requires `symbol` when `category` is `inverse`; for
|
|
60
|
+
# `linear` it's optional. Keep it as an optional kwarg here — callers
|
|
61
|
+
# querying inverse pass it, callers on linear can omit it.
|
|
62
|
+
#
|
|
63
|
+
# @param category [String] Product type: `linear`, `inverse`
|
|
64
|
+
# @option kwargs [String] :symbol Symbol name (required for `inverse`)
|
|
65
|
+
# @option kwargs [Integer] :start_time Start ms timestamp
|
|
66
|
+
# @option kwargs [Integer] :end_time End ms timestamp
|
|
67
|
+
# @option kwargs [Integer] :limit Records per page
|
|
68
|
+
# @option kwargs [String] :cursor Pagination cursor
|
|
69
|
+
# @return [Hash] Bybit V5 ApiResponse envelope (retCode / retMsg / result / retExtInfo / time).
|
|
70
|
+
# @see https://bybit-exchange.github.io/docs/v5/pre-upgrade/close-pnl
|
|
71
|
+
def get_closed_pnl(category:, **kwargs)
|
|
72
|
+
params = kwargs.merge(category: category)
|
|
73
|
+
params = Bybit::Utils::WireKeys.camelize(params)
|
|
74
|
+
@session.sign_request(method: :get, path: '/v5/pre-upgrade/position/closed-pnl', params: params)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# Get Pre-upgrade Transaction Log (USDC Derivatives wallet)
|
|
78
|
+
#
|
|
79
|
+
# GET /v5/pre-upgrade/account/transaction-log
|
|
80
|
+
#
|
|
81
|
+
# @param category [String] Product type: `linear`, `option`
|
|
82
|
+
# @option kwargs [String] :base_coin Base coin filter
|
|
83
|
+
# @option kwargs [String] :type Transaction type filter
|
|
84
|
+
# @option kwargs [Integer] :start_time Start ms timestamp
|
|
85
|
+
# @option kwargs [Integer] :end_time End ms timestamp
|
|
86
|
+
# @option kwargs [Integer] :limit Records per page
|
|
87
|
+
# @option kwargs [String] :cursor Pagination cursor
|
|
88
|
+
# @return [Hash] Bybit V5 ApiResponse envelope (retCode / retMsg / result / retExtInfo / time).
|
|
89
|
+
# @see https://bybit-exchange.github.io/docs/v5/pre-upgrade/transaction-log
|
|
90
|
+
def get_transaction_log(category:, **kwargs)
|
|
91
|
+
params = kwargs.merge(category: category)
|
|
92
|
+
params = Bybit::Utils::WireKeys.camelize(params)
|
|
93
|
+
@session.sign_request(method: :get, path: '/v5/pre-upgrade/account/transaction-log', params: params)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
# Get Pre-upgrade Option Delivery Record
|
|
97
|
+
#
|
|
98
|
+
# GET /v5/pre-upgrade/asset/delivery-record
|
|
99
|
+
#
|
|
100
|
+
# @param category [String] Product type: `option`
|
|
101
|
+
# @option kwargs [String] :symbol Symbol filter
|
|
102
|
+
# @option kwargs [Integer] :expiry_date Delivery expiry date (YYYYMMDD)
|
|
103
|
+
# @option kwargs [Integer] :limit Records per page
|
|
104
|
+
# @option kwargs [String] :cursor Pagination cursor
|
|
105
|
+
# @return [Hash] Bybit V5 ApiResponse envelope (retCode / retMsg / result / retExtInfo / time).
|
|
106
|
+
# @see https://bybit-exchange.github.io/docs/v5/pre-upgrade/delivery
|
|
107
|
+
def get_option_delivery_record(category:, **kwargs)
|
|
108
|
+
params = kwargs.merge(category: category)
|
|
109
|
+
params = Bybit::Utils::WireKeys.camelize(params)
|
|
110
|
+
@session.sign_request(method: :get, path: '/v5/pre-upgrade/asset/delivery-record', params: params)
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
# Get Pre-upgrade USDC Session Settlement Record
|
|
114
|
+
#
|
|
115
|
+
# GET /v5/pre-upgrade/asset/settlement-record
|
|
116
|
+
#
|
|
117
|
+
# @param category [String] Product type: `linear`
|
|
118
|
+
# @option kwargs [String] :symbol Symbol filter
|
|
119
|
+
# @option kwargs [Integer] :limit Records per page
|
|
120
|
+
# @option kwargs [String] :cursor Pagination cursor
|
|
121
|
+
# @return [Hash] Bybit V5 ApiResponse envelope (retCode / retMsg / result / retExtInfo / time).
|
|
122
|
+
# @see https://bybit-exchange.github.io/docs/v5/pre-upgrade/settlement
|
|
123
|
+
def get_usdc_session_settlement(category:, **kwargs)
|
|
124
|
+
params = kwargs.merge(category: category)
|
|
125
|
+
params = Bybit::Utils::WireKeys.camelize(params)
|
|
126
|
+
@session.sign_request(method: :get, path: '/v5/pre-upgrade/asset/settlement-record', params: params)
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
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
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Bybit
|
|
4
|
+
module RestApi
|
|
5
|
+
class SpotXService < BaseService
|
|
6
|
+
# Get Launchpool project (activity) list
|
|
7
|
+
#
|
|
8
|
+
# GET /v5/spot-x/launchpool/project/list
|
|
9
|
+
#
|
|
10
|
+
# @param status [Integer] Activity phase filter.
|
|
11
|
+
# - `0` — Upcoming
|
|
12
|
+
# - `1` — Ongoing
|
|
13
|
+
# - `2` — Ended
|
|
14
|
+
# @option kwargs [String] :activity_coin Filter by activity (reward) coin symbol (case-insensitive), e.g. `BTC`, `ETH`.
|
|
15
|
+
# @option kwargs [String] :project_id Exact activity code. Use to query a single project.
|
|
16
|
+
# @option kwargs [String] :cursor Pagination cursor returned as `nextPageCursor` in the previous response. Omit for the first page.
|
|
17
|
+
# @option kwargs [Integer] :limit Number of items per page. Defaults to `10`. Maximum `10`.
|
|
18
|
+
# @return [Hash] Bybit V5 ApiResponse envelope (retCode / retMsg / result / retExtInfo / time).
|
|
19
|
+
# @see https://bybit-exchange.github.io/docs/v5/finance/spot-x/launchpool/launchpool-project-list
|
|
20
|
+
def get_launchpool_project_list(status:, **kwargs)
|
|
21
|
+
params = Bybit::Utils::WireKeys.camelize(kwargs.merge(status: status))
|
|
22
|
+
@session.public_request(path: '/v5/spot-x/launchpool/project/list', params: params)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Get user's staking operation records
|
|
26
|
+
#
|
|
27
|
+
# POST /v5/spot-x/launchpool/user/activity-log
|
|
28
|
+
#
|
|
29
|
+
# @option kwargs [String] :stake_coin Filter by stake coin symbol (case-sensitive).
|
|
30
|
+
# @option kwargs [Integer] :type Filter by operation type. Omit to return all types.
|
|
31
|
+
# - `0` PLEDGE — manual stake-in
|
|
32
|
+
# - `1` REDEEM — manual redeem
|
|
33
|
+
# - `2` INTEREST — reward/interest credit
|
|
34
|
+
# - `3` AUTO_REDEEM — auto principal return on maturity
|
|
35
|
+
# - `4` LOAN_PLEDGE — leveraged stake-in
|
|
36
|
+
# - `5` LOAN_REDEEM — manual leveraged redeem
|
|
37
|
+
# - `6` LOAN_AUTO_REDEEM — auto leveraged maturity redemption
|
|
38
|
+
# - `7` LOAN_RISKRATE_AUTO_REDEEM — leveraged liquidation
|
|
39
|
+
# - `8` RISK_USER_AUTO_REDEEM — risk-control forced redeem (non-leveraged)
|
|
40
|
+
# - `9` LOAN_RISK_USER_AUTO_REDEEM — risk-control forced redeem (leveraged)
|
|
41
|
+
# - `10` EARN_REWARD — earn product reward credit
|
|
42
|
+
# @option kwargs [Integer] :status Filter by record status. Omit to return all statuses.
|
|
43
|
+
# - `0` — Pending
|
|
44
|
+
# - `1` — Success
|
|
45
|
+
# - `2` — Failed
|
|
46
|
+
# @option kwargs [String] :start_time Query start time — 13-digit Unix millisecond timestamp string.
|
|
47
|
+
# Must be provided together with `endTime`.
|
|
48
|
+
# @option kwargs [String] :end_time Query end time — 13-digit Unix millisecond timestamp string.
|
|
49
|
+
# Must be provided together with `startTime`.
|
|
50
|
+
# @option kwargs [Integer] :page_size Number of records per page. Defaults to `10`. Maximum `10`.
|
|
51
|
+
# @option kwargs [Integer] :current Page number (1-based). Defaults to `1`. Maximum `100`.
|
|
52
|
+
# @return [Hash] Bybit V5 ApiResponse envelope (retCode / retMsg / result / retExtInfo / time).
|
|
53
|
+
# @see https://bybit-exchange.github.io/docs/v5/finance/spot-x/launchpool/launchpool-activity-log
|
|
54
|
+
def get_launchpool_user_activity_log(**kwargs)
|
|
55
|
+
params = Bybit::Utils::WireKeys.camelize(kwargs)
|
|
56
|
+
@session.sign_request(method: :post, path: '/v5/spot-x/launchpool/user/activity-log', body: params)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# Get user's active staking positions
|
|
60
|
+
#
|
|
61
|
+
# GET /v5/spot-x/launchpool/user/current-staking
|
|
62
|
+
#
|
|
63
|
+
# @return [Hash] Bybit V5 ApiResponse envelope (retCode / retMsg / result / retExtInfo / time).
|
|
64
|
+
# @see https://bybit-exchange.github.io/docs/v5/finance/spot-x/launchpool/launchpool-current-staking
|
|
65
|
+
def get_launchpool_user_current_staking
|
|
66
|
+
@session.sign_request(method: :get, path: '/v5/spot-x/launchpool/user/current-staking')
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# Get user's completed staking position history
|
|
70
|
+
#
|
|
71
|
+
# POST /v5/spot-x/launchpool/user/history
|
|
72
|
+
#
|
|
73
|
+
# @option kwargs [String] :stake_coin Filter by stake coin symbol.
|
|
74
|
+
# @option kwargs [String] :reward_coin Filter by reward coin symbol.
|
|
75
|
+
# @option kwargs [String] :start_time Staking period start filter — 13-digit Unix millisecond timestamp string.
|
|
76
|
+
# Filters positions whose `stakeBeginTime` is on or after this value.
|
|
77
|
+
# Must be provided together with `endTime`.
|
|
78
|
+
# @option kwargs [String] :end_time Staking period end filter — 13-digit Unix millisecond timestamp string.
|
|
79
|
+
# Filters positions whose `stakeEndTime` is on or before this value.
|
|
80
|
+
# Must be provided together with `startTime`.
|
|
81
|
+
# @option kwargs [Integer] :page_size Number of records per page. Defaults to `10`. Maximum `10`.
|
|
82
|
+
# @option kwargs [Integer] :current Page number (1-based). Defaults to `1`. Maximum `100`.
|
|
83
|
+
# @return [Hash] Bybit V5 ApiResponse envelope (retCode / retMsg / result / retExtInfo / time).
|
|
84
|
+
# @see https://bybit-exchange.github.io/docs/v5/finance/spot-x/launchpool/launchpool-user-history
|
|
85
|
+
def get_launchpool_user_history(**kwargs)
|
|
86
|
+
params = Bybit::Utils::WireKeys.camelize(kwargs)
|
|
87
|
+
@session.sign_request(method: :post, path: '/v5/spot-x/launchpool/user/history', body: params)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
# Get Puzzle project (activity) list
|
|
91
|
+
#
|
|
92
|
+
# GET /v5/spot-x/puzzle/project/list
|
|
93
|
+
#
|
|
94
|
+
# @param status [Integer] Activity phase filter.
|
|
95
|
+
# - `0` — Upcoming (not yet started)
|
|
96
|
+
# - `1` — Ongoing (in progress)
|
|
97
|
+
# - `2` — Ended
|
|
98
|
+
# @option kwargs [String] :project_id Exact activity code (unique project identifier). Use to query a single project.
|
|
99
|
+
# @option kwargs [String] :activity_coin Filter by activity coin symbol (case-insensitive), e.g. `BTC`, `ETH`.
|
|
100
|
+
# @option kwargs [String] :cursor Pagination cursor returned as `nextPageCursor` in the previous response. Omit for the first page.
|
|
101
|
+
# @option kwargs [Integer] :limit Number of items per page. Defaults to `10`. Maximum `10`.
|
|
102
|
+
# @return [Hash] Bybit V5 ApiResponse envelope (retCode / retMsg / result / retExtInfo / time).
|
|
103
|
+
# @see https://bybit-exchange.github.io/docs/v5/finance/spot-x/puzzle/puzzle-project-list
|
|
104
|
+
def get_puzzle_project_list(status:, **kwargs)
|
|
105
|
+
params = Bybit::Utils::WireKeys.camelize(kwargs.merge(status: status))
|
|
106
|
+
@session.public_request(path: '/v5/spot-x/puzzle/project/list', params: params)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
# Get Token Splash project (activity) list
|
|
110
|
+
#
|
|
111
|
+
# GET /v5/spot-x/token-splash/project/list
|
|
112
|
+
#
|
|
113
|
+
# @param status [Integer] Activity phase filter.
|
|
114
|
+
# - `0` — Upcoming (registration not yet started)
|
|
115
|
+
# - `1` — Ongoing (activity in progress)
|
|
116
|
+
# - `2` — Ended (announcement time has passed)
|
|
117
|
+
# @option kwargs [String] :project_id Exact activity code. Use to query a single project.
|
|
118
|
+
# @option kwargs [String] :activity_coin Filter by activity coin symbol (case-insensitive), e.g. `BTC`, `ETH`.
|
|
119
|
+
# @option kwargs [String] :cursor Pagination cursor returned as `nextPageCursor` in the previous response. Omit for the first page.
|
|
120
|
+
# @option kwargs [Integer] :limit Number of items per page. Defaults to `10`. Maximum `10`.
|
|
121
|
+
# @return [Hash] Bybit V5 ApiResponse envelope (retCode / retMsg / result / retExtInfo / time).
|
|
122
|
+
# @see https://bybit-exchange.github.io/docs/v5/finance/spot-x/token-splash/token-splash-project-list
|
|
123
|
+
def get_token_splash_project_list(status:, **kwargs)
|
|
124
|
+
params = Bybit::Utils::WireKeys.camelize(kwargs.merge(status: status))
|
|
125
|
+
@session.public_request(path: '/v5/spot-x/token-splash/project/list', params: params)
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
# Get user's Token Splash trade-task progress
|
|
129
|
+
#
|
|
130
|
+
# GET /v5/spot-x/token-splash/user/activity-params
|
|
131
|
+
#
|
|
132
|
+
# @option kwargs [String] :project_id Filter by exact activity code. Returns data for a single project when provided.
|
|
133
|
+
# @option kwargs [String] :activity_coin Filter by activity coin symbol (case-insensitive), e.g. `BTC`, `ETH`.
|
|
134
|
+
# @return [Hash] Bybit V5 ApiResponse envelope (retCode / retMsg / result / retExtInfo / time).
|
|
135
|
+
# @see https://bybit-exchange.github.io/docs/v5/finance/spot-x/token-splash/token-splash-user-activity-params
|
|
136
|
+
def get_token_splash_user_activity_params(**kwargs)
|
|
137
|
+
params = Bybit::Utils::WireKeys.camelize(kwargs)
|
|
138
|
+
@session.sign_request(method: :get, path: '/v5/spot-x/token-splash/user/activity-params', params: params)
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
end
|