From 41bccfaddcf62bee107257d346274b42a726fd3f Mon Sep 17 00:00:00 2001 From: alplabin <122352306+alplabin@users.noreply.github.com> Date: Thu, 5 Dec 2024 10:43:16 +0900 Subject: [PATCH] Release v1.7.0 --- CHANGELOG.md | 76 ++++++ Gemfile.lock | 32 +-- examples/spot/convert/convert_accept_quote.rb | 15 ++ examples/spot/convert/convert_asset_info.rb | 15 ++ .../spot/convert/convert_exchange_info.rb | 15 ++ examples/spot/convert/convert_get_quote.rb | 15 ++ .../convert/convert_limit_cancel_order.rb | 15 ++ .../spot/convert/convert_limit_place_order.rb | 15 ++ .../convert_limit_query_open_orders.rb | 15 ++ examples/spot/convert/convert_order_status.rb | 15 ++ .../spot/loan/adjust_flexible_loan_ltv.rb | 15 ++ examples/spot/loan/borrow_flexible_loan.rb | 15 ++ .../loan/get_flexible_loan_assets_data.rb | 15 ++ .../loan/get_flexible_loan_borrow_history.rb | 15 ++ .../loan/get_flexible_loan_collateral_data.rb | 15 ++ ...et_flexible_loan_ltv_adjustment_history.rb | 15 ++ .../loan/get_flexible_loan_ongoing_orders.rb | 15 ++ .../get_flexible_loan_repayment_history.rb | 15 ++ examples/spot/loan/get_loan_borrow_history.rb | 15 ++ .../loan/get_loan_ltv_adjustment_history.rb | 15 ++ .../spot/loan/get_loan_repayment_history.rb | 15 ++ examples/spot/loan/repay_flexible_loan.rb | 15 ++ .../spot/margin/margin_available_inventory.rb | 14 ++ examples/spot/margin/margin_borrow_repay.rb | 14 ++ .../spot/margin/margin_borrow_repay_record.rb | 14 ++ .../spot/margin/margin_leverage_bracket.rb | 14 ++ .../spot/margin/margin_manual_liquidation.rb | 14 ++ examples/spot/market/ticker_trading_day.rb | 16 ++ examples/spot/market/ui_klines.rb | 12 + .../spot/simple_earn/locked_redeem_option.rb | 12 + .../subaccount/get_sub_account_assets_v4.rb | 12 + .../subaccount/sub_account_enable_options.rb | 12 + .../sub_account_futures_asset_details.rb | 12 + examples/spot/subaccount/sub_account_list.rb | 12 + .../sub_account_margin_asset_details.rb | 12 + .../sub_account_transaction_statistics.rb | 12 + .../subaccount/sub_account_transfer_log.rb | 12 + .../sub_account_transfer_log_investor.rb | 12 + .../sub_account_transfer_log_sub_account.rb | 12 + examples/spot/trade/commission_rate.rb | 18 ++ examples/spot/trade/my_allocations.rb | 18 ++ examples/spot/trade/my_prevented_matches.rb | 18 ++ examples/spot/trade/new_oco_order.rb | 12 +- examples/spot/wallet/account_info.rb | 12 + ...cloud_mining_payment_and_refund_history.rb | 12 + examples/spot/wallet/delist_schedule.rb | 12 + examples/spot/wallet/deposit_address_list.rb | 12 + .../wallet/get_assets_converted_into_bnb.rb | 12 + .../wallet/one_click_arrival_deposit_apply.rb | 12 + .../spot/wallet/user_delegation_history.rb | 12 + examples/spot/wallet/wallet_balance.rb | 12 + lib/binance/session.rb | 3 +- lib/binance/spot/convert.rb | 134 ++++++++++- lib/binance/spot/loan.rb | 224 +++++++++++++++++- lib/binance/spot/margin.rb | 85 +++++++ lib/binance/spot/market.rb | 87 +++++-- lib/binance/spot/simple_earn.rb | 20 ++ lib/binance/spot/subaccount.rb | 173 ++++++++++++++ lib/binance/spot/trade.rb | 122 +++++++--- lib/binance/spot/wallet.rb | 118 +++++++++ lib/binance/spot/websocket.rb | 12 + lib/binance/version.rb | 2 +- package-lock.json | 6 + .../spot/convert/convert_accept_quote.rb | 35 +++ .../spot/convert/convert_asset_info.rb | 18 ++ .../spot/convert/convert_exchange_info.rb | 18 ++ .../binance/spot/convert/convert_get_quote.rb | 36 +++ .../convert/convert_limit_cancel_order.rb | 35 +++ .../spot/convert/convert_limit_place_order.rb | 39 +++ .../convert_limit_query_open_orders.rb | 18 ++ .../spot/convert/convert_order_status.rb | 18 ++ .../spot/loan/adjust_flexible_loan_ltv.rb | 38 +++ .../binance/spot/loan/borrow_flexible_loan.rb | 36 +++ .../loan/get_flexible_loan_assets_data.rb | 18 ++ .../loan/get_flexible_loan_borrow_history.rb | 18 ++ .../loan/get_flexible_loan_collateral_data.rb | 18 ++ ...et_flexible_loan_ltv_adjustment_history.rb | 18 ++ .../loan/get_flexible_loan_ongoing_orders.rb | 18 ++ .../get_flexible_loan_repayment_history.rb | 18 ++ .../spot/loan/get_loan_borrow_history.rb | 18 ++ spec/binance/spot/loan/get_loan_history.rb | 18 ++ .../loan/get_loan_ltv_adjustment_history.rb | 18 ++ .../spot/loan/get_loan_repayment_history.rb | 18 ++ spec/binance/spot/loan/repay_flexible_loan.rb | 37 +++ .../spot/margin/margin_available_inventory.rb | 35 +++ .../spot/margin/margin_borrow_repay.rb | 39 +++ .../spot/margin/margin_borrow_repay_record.rb | 35 +++ .../spot/margin/margin_leverage_bracket.rb | 18 ++ .../spot/margin/margin_manual_liquidation.rb | 35 +++ .../binance/spot/market/ticker_trading_day.rb | 35 +++ spec/binance/spot/market/ui_klines.rb | 46 ++++ .../spot/simple_earn/locked_redeem_option.rb | 36 +++ .../subaccount/get_sub_account_assets_v4.rb | 35 +++ .../subaccount/sub_account_enable_options.rb | 35 +++ .../sub_account_futures_asset_details.rb | 35 +++ .../spot/subaccount/sub_account_list.rb | 18 ++ .../sub_account_margin_asset_details.rb | 35 +++ .../sub_account_transaction_statistics.rb | 35 +++ .../subaccount/sub_account_transfer_log.rb | 39 +++ .../sub_account_transfer_log_investor.rb | 39 +++ .../sub_account_transfer_log_sub_account.rb | 38 +++ spec/binance/spot/trade/commission_rate.rb | 35 +++ spec/binance/spot/trade/my_allocations.rb | 35 +++ .../spot/trade/my_prevented_matches.rb | 35 +++ spec/binance/spot/trade/new_oco_order_spec.rb | 27 +-- spec/binance/spot/wallet/account_info.rb | 18 ++ ...cloud_mining_payment_and_refund_history.rb | 18 ++ spec/binance/spot/wallet/delist_schedule.rb | 18 ++ .../spot/wallet/deposit_address_list.rb | 35 +++ .../wallet/get_assets_converted_into_bnb.rb | 18 ++ .../wallet/one_click_arrival_deposit_apply.rb | 18 ++ .../spot/wallet/user_delegation_history.rb | 18 ++ spec/binance/spot/wallet/wallet_balance.rb | 18 ++ 113 files changed, 3075 insertions(+), 88 deletions(-) create mode 100755 examples/spot/convert/convert_accept_quote.rb create mode 100755 examples/spot/convert/convert_asset_info.rb create mode 100755 examples/spot/convert/convert_exchange_info.rb create mode 100755 examples/spot/convert/convert_get_quote.rb create mode 100755 examples/spot/convert/convert_limit_cancel_order.rb create mode 100755 examples/spot/convert/convert_limit_place_order.rb create mode 100755 examples/spot/convert/convert_limit_query_open_orders.rb create mode 100755 examples/spot/convert/convert_order_status.rb create mode 100755 examples/spot/loan/adjust_flexible_loan_ltv.rb create mode 100755 examples/spot/loan/borrow_flexible_loan.rb create mode 100755 examples/spot/loan/get_flexible_loan_assets_data.rb create mode 100755 examples/spot/loan/get_flexible_loan_borrow_history.rb create mode 100755 examples/spot/loan/get_flexible_loan_collateral_data.rb create mode 100755 examples/spot/loan/get_flexible_loan_ltv_adjustment_history.rb create mode 100755 examples/spot/loan/get_flexible_loan_ongoing_orders.rb create mode 100755 examples/spot/loan/get_flexible_loan_repayment_history.rb create mode 100755 examples/spot/loan/get_loan_borrow_history.rb create mode 100755 examples/spot/loan/get_loan_ltv_adjustment_history.rb create mode 100755 examples/spot/loan/get_loan_repayment_history.rb create mode 100755 examples/spot/loan/repay_flexible_loan.rb create mode 100755 examples/spot/margin/margin_available_inventory.rb create mode 100755 examples/spot/margin/margin_borrow_repay.rb create mode 100755 examples/spot/margin/margin_borrow_repay_record.rb create mode 100755 examples/spot/margin/margin_leverage_bracket.rb create mode 100755 examples/spot/margin/margin_manual_liquidation.rb create mode 100755 examples/spot/market/ticker_trading_day.rb create mode 100755 examples/spot/market/ui_klines.rb create mode 100755 examples/spot/simple_earn/locked_redeem_option.rb create mode 100755 examples/spot/subaccount/get_sub_account_assets_v4.rb create mode 100755 examples/spot/subaccount/sub_account_enable_options.rb create mode 100755 examples/spot/subaccount/sub_account_futures_asset_details.rb create mode 100755 examples/spot/subaccount/sub_account_list.rb create mode 100755 examples/spot/subaccount/sub_account_margin_asset_details.rb create mode 100755 examples/spot/subaccount/sub_account_transaction_statistics.rb create mode 100755 examples/spot/subaccount/sub_account_transfer_log.rb create mode 100755 examples/spot/subaccount/sub_account_transfer_log_investor.rb create mode 100755 examples/spot/subaccount/sub_account_transfer_log_sub_account.rb create mode 100755 examples/spot/trade/commission_rate.rb create mode 100755 examples/spot/trade/my_allocations.rb create mode 100755 examples/spot/trade/my_prevented_matches.rb create mode 100755 examples/spot/wallet/account_info.rb create mode 100755 examples/spot/wallet/cloud_mining_payment_and_refund_history.rb create mode 100755 examples/spot/wallet/delist_schedule.rb create mode 100755 examples/spot/wallet/deposit_address_list.rb create mode 100755 examples/spot/wallet/get_assets_converted_into_bnb.rb create mode 100755 examples/spot/wallet/one_click_arrival_deposit_apply.rb create mode 100755 examples/spot/wallet/user_delegation_history.rb create mode 100755 examples/spot/wallet/wallet_balance.rb create mode 100644 package-lock.json create mode 100644 spec/binance/spot/convert/convert_accept_quote.rb create mode 100644 spec/binance/spot/convert/convert_asset_info.rb create mode 100644 spec/binance/spot/convert/convert_exchange_info.rb create mode 100644 spec/binance/spot/convert/convert_get_quote.rb create mode 100644 spec/binance/spot/convert/convert_limit_cancel_order.rb create mode 100644 spec/binance/spot/convert/convert_limit_place_order.rb create mode 100644 spec/binance/spot/convert/convert_limit_query_open_orders.rb create mode 100644 spec/binance/spot/convert/convert_order_status.rb create mode 100644 spec/binance/spot/loan/adjust_flexible_loan_ltv.rb create mode 100644 spec/binance/spot/loan/borrow_flexible_loan.rb create mode 100644 spec/binance/spot/loan/get_flexible_loan_assets_data.rb create mode 100644 spec/binance/spot/loan/get_flexible_loan_borrow_history.rb create mode 100644 spec/binance/spot/loan/get_flexible_loan_collateral_data.rb create mode 100644 spec/binance/spot/loan/get_flexible_loan_ltv_adjustment_history.rb create mode 100644 spec/binance/spot/loan/get_flexible_loan_ongoing_orders.rb create mode 100644 spec/binance/spot/loan/get_flexible_loan_repayment_history.rb create mode 100644 spec/binance/spot/loan/get_loan_borrow_history.rb create mode 100644 spec/binance/spot/loan/get_loan_history.rb create mode 100644 spec/binance/spot/loan/get_loan_ltv_adjustment_history.rb create mode 100644 spec/binance/spot/loan/get_loan_repayment_history.rb create mode 100644 spec/binance/spot/loan/repay_flexible_loan.rb create mode 100644 spec/binance/spot/margin/margin_available_inventory.rb create mode 100644 spec/binance/spot/margin/margin_borrow_repay.rb create mode 100644 spec/binance/spot/margin/margin_borrow_repay_record.rb create mode 100644 spec/binance/spot/margin/margin_leverage_bracket.rb create mode 100644 spec/binance/spot/margin/margin_manual_liquidation.rb create mode 100644 spec/binance/spot/market/ticker_trading_day.rb create mode 100644 spec/binance/spot/market/ui_klines.rb create mode 100644 spec/binance/spot/simple_earn/locked_redeem_option.rb create mode 100644 spec/binance/spot/subaccount/get_sub_account_assets_v4.rb create mode 100644 spec/binance/spot/subaccount/sub_account_enable_options.rb create mode 100644 spec/binance/spot/subaccount/sub_account_futures_asset_details.rb create mode 100644 spec/binance/spot/subaccount/sub_account_list.rb create mode 100644 spec/binance/spot/subaccount/sub_account_margin_asset_details.rb create mode 100644 spec/binance/spot/subaccount/sub_account_transaction_statistics.rb create mode 100644 spec/binance/spot/subaccount/sub_account_transfer_log.rb create mode 100644 spec/binance/spot/subaccount/sub_account_transfer_log_investor.rb create mode 100644 spec/binance/spot/subaccount/sub_account_transfer_log_sub_account.rb create mode 100644 spec/binance/spot/trade/commission_rate.rb create mode 100644 spec/binance/spot/trade/my_allocations.rb create mode 100644 spec/binance/spot/trade/my_prevented_matches.rb create mode 100644 spec/binance/spot/wallet/account_info.rb create mode 100644 spec/binance/spot/wallet/cloud_mining_payment_and_refund_history.rb create mode 100644 spec/binance/spot/wallet/delist_schedule.rb create mode 100644 spec/binance/spot/wallet/deposit_address_list.rb create mode 100644 spec/binance/spot/wallet/get_assets_converted_into_bnb.rb create mode 100644 spec/binance/spot/wallet/one_click_arrival_deposit_apply.rb create mode 100644 spec/binance/spot/wallet/user_delegation_history.rb create mode 100644 spec/binance/spot/wallet/wallet_balance.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index b386f02..96c6570 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,81 @@ # Changelog +## 1.7.0 -2024-12-05 +### Added +- Convert endpoints: + - `GET /sapi/v1/convert/exchangeInfo` + - `GET /sapi/v1/convert/assetInfo` + - `POST /sapi/v1/convert/getQuote` + - `POST /sapi/v1/convert/acceptQuote` + - `GET /sapi/v1/convert/orderStatus` + - `POST /sapi/v1/convert/limit/placeOrder` + - `POST /sapi/v1/convert/limit/cancelOrder` + - `POST /sapi/v1/convert/limit/queryOpenOrders` + +- Loan endpoints: + - `GET /sapi/v2/loan/flexible/collateral/data` + - `GET /sapi/v2/loan/flexible/loanable/data` + - `POST /sapi/v2/loan/flexible/borrow` + - `POST /sapi/v2/loan/flexible/repay` + - `POST /sapi/v2/loan/flexible/adjust/ltv` + - `GET /sapi/v2/loan/flexible/ltv/adjustment/history` + - `GET /sapi/v2/loan/flexible/borrow/history` + - `GET /sapi/v2/loan/flexible/ongoing/orders` + - `GET /sapi/v2/loan/flexible/repay/history` + - `GET /sapi/v1/loan/borrow/history` + - `GET /sapi/v1/loan/ltv/adjustment/history` + - `GET /sapi/v1/loan/repay/history` + +- Margin endpoints: + - `POST /sapi/v1/margin/borrow-repay` + - `GET /sapi/v1/margin/borrow-repay` + - `GET /sapi/v1/margin/available-inventory` + - `GET /sapi/v1/margin/leverageBracket` + - `POST /sapi/v1/margin/manual-liquidation` + +- Market endpoints: + - `GET /api/v3/ticker/tradingDay` + - `GET /api/v3/uiKlines` + +- Simple Earn endpoints: + - `POST /sapi/v1/simple-earn/locked/setRedeemOption` + +- Sub Account endpoints: + - `GET /sapi/v4/sub-account/assets` + - `POST /sapi/v1/sub-account/eoptions/enable` + - `GET /sapi/v1/managed-subaccount/marginAsset` + - `GET /sapi/v1/sub-account/transaction-statistics` + - `GET /sapi/v1/managed-subaccount/fetch-future-asset` + - `GET /sapi/v1/managed-subaccount/queryTransLogForTradeParent` + - `GET /sapi/v1/managed-subaccount/query-trans-log` + - `GET /sapi/v1/managed-subaccount/queryTransLogForInvestor` + - `GET /sapi/v1/managed-subaccount/info` + +- Trade endpoint: + - `GET /api/v3/myPreventedMatches` + - `GET /api/v3/myAllocations` + - `GET /api/v3/account/commission` + +- Wallet endpoints: + - `GET /sapi/v1/spot/delist-schedule` + - `GET /sapi/v1/capital/deposit/address/list` + - `POST /sapi/v1/capital/deposit/credit-apply` + - `GET /sapi/v1/asset/wallet/balance` + - `POST /sapi/v1/asset/dust-btc` + - `GET /sapi/v1/asset/ledger-transfer/cloud-mining/queryByPage` + - `GET /sapi/v1/asset/custody/transfer-history` + - `GET /sapi/v1/account/info` + +- Websocket: + - `@avgPrice` + +### Changed +- Added new parameter `redeemTo` to endpoint `POST /sapi/v1/simple-earn/locked/subscribe` +- Added new parameter `timeZone` to endpoint `GET /api/v3/klines` +- Added new parameters `orderRateLimitExceededMode`, `strategyId`, `strategyType`, `selfTradePreventionMode` and `cancelRestrictions` to endpoint `POST /api/v3/order/cancelReplace` +- Added new parameters `showPermissionSets` and `symbolStatus` to endpoint `GET /api/v3/exchangeInfo` +- Replaced endpoint `POST /api/v3/order/oco` by `POST /api/v3/orderList/oco` + ## 1.6.0 - 2024-10-02 ### Changed diff --git a/Gemfile.lock b/Gemfile.lock index 0d633be..e703b66 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - binance-connector-ruby (1.6.0) + binance-connector-ruby (1.7.0) faraday (~> 1.8) websocket-eventmachine-client (~> 1.3) @@ -57,9 +57,9 @@ GEM faraday-rack (1.0.0) faraday-retry (1.0.3) gem-release (2.2.2) - hashdiff (1.1.1) + hashdiff (1.1.2) ice_nine (0.11.2) - json (2.7.2) + json (2.8.2) language_server-protocol (3.17.0.3) memoizable (0.4.2) thread_safe (~> 0.3, >= 0.3.1) @@ -72,7 +72,7 @@ GEM procto (~> 0.0.2) multipart-post (2.4.1) parallel (1.26.3) - parser (3.3.5.0) + parser (3.3.6.0) ast (~> 2.4.1) racc proc_to_ast (0.2.0) @@ -84,19 +84,19 @@ GEM racc (1.8.1) rainbow (3.1.1) rake (13.2.1) - regexp_parser (2.9.2) - rexml (3.3.8) - rouge (4.4.0) + regexp_parser (2.9.3) + rexml (3.3.9) + rouge (4.5.1) rspec (3.13.0) rspec-core (~> 3.13.0) rspec-expectations (~> 3.13.0) rspec-mocks (~> 3.13.0) - rspec-core (3.13.1) + rspec-core (3.13.2) rspec-support (~> 3.13.0) rspec-expectations (3.13.3) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.13.0) - rspec-mocks (3.13.1) + rspec-mocks (3.13.2) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.13.0) rspec-parameterized (1.0.2) @@ -110,18 +110,18 @@ GEM rspec-parameterized-table_syntax (1.0.1) binding_of_caller rspec-parameterized-core (< 2) - rspec-support (3.13.1) - rubocop (1.66.1) + rspec-support (3.13.2) + rubocop (1.69.0) json (~> 2.3) language_server-protocol (>= 3.17.0) parallel (~> 1.10) parser (>= 3.3.0.2) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 2.4, < 3.0) - rubocop-ast (>= 1.32.2, < 2.0) + rubocop-ast (>= 1.36.1, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 2.4.0, < 3.0) - rubocop-ast (1.32.3) + unicode-display_width (>= 2.4.0, < 4.0) + rubocop-ast (1.36.2) parser (>= 3.3.1.0) ruby-progressbar (1.13.0) ruby2_keywords (0.0.5) @@ -132,7 +132,9 @@ GEM simplecov-html (0.13.1) simplecov_json_formatter (0.1.4) thread_safe (0.3.6) - unicode-display_width (2.6.0) + unicode-display_width (3.1.2) + unicode-emoji (~> 4.0, >= 4.0.4) + unicode-emoji (4.0.4) unparser (0.5.7) abstract_type (~> 0.0.7) adamantium (~> 0.2.0) diff --git a/examples/spot/convert/convert_accept_quote.rb b/examples/spot/convert/convert_accept_quote.rb new file mode 100755 index 0000000..719dfdb --- /dev/null +++ b/examples/spot/convert/convert_accept_quote.rb @@ -0,0 +1,15 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +$LOAD_PATH.unshift('./lib') + +require 'binance' +require_relative '../../common' + +logger = Common.setup_logger + +# set key here +# or BINANCE_PUBLIC_API_KEY in env +client = Binance::Spot.new(key: '', secret: '') + +logger.info(client.convert_accept_quote(quoteId: '1234')) diff --git a/examples/spot/convert/convert_asset_info.rb b/examples/spot/convert/convert_asset_info.rb new file mode 100755 index 0000000..97e609d --- /dev/null +++ b/examples/spot/convert/convert_asset_info.rb @@ -0,0 +1,15 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +$LOAD_PATH.unshift('./lib') + +require 'binance' +require_relative '../../common' + +logger = Common.setup_logger + +# set key here +# or BINANCE_PUBLIC_API_KEY in env +client = Binance::Spot.new(key: '', secret: '') + +logger.info(client.convert_asset_info) diff --git a/examples/spot/convert/convert_exchange_info.rb b/examples/spot/convert/convert_exchange_info.rb new file mode 100755 index 0000000..9f7e14c --- /dev/null +++ b/examples/spot/convert/convert_exchange_info.rb @@ -0,0 +1,15 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +$LOAD_PATH.unshift('./lib') + +require 'binance' +require_relative '../../common' + +logger = Common.setup_logger + +# set key here +# or BINANCE_PUBLIC_API_KEY in env +client = Binance::Spot.new(key: '', secret: '') + +logger.info(client.convert_exchange_info) diff --git a/examples/spot/convert/convert_get_quote.rb b/examples/spot/convert/convert_get_quote.rb new file mode 100755 index 0000000..cc78618 --- /dev/null +++ b/examples/spot/convert/convert_get_quote.rb @@ -0,0 +1,15 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +$LOAD_PATH.unshift('./lib') + +require 'binance' +require_relative '../../common' + +logger = Common.setup_logger + +# set key here +# or BINANCE_PUBLIC_API_KEY in env +client = Binance::Spot.new(key: '', secret: '') + +logger.info(client.convert_get_quote(fromAsset: 'BNB', toAsset: 'USDT', fromAmount: 1.0)) diff --git a/examples/spot/convert/convert_limit_cancel_order.rb b/examples/spot/convert/convert_limit_cancel_order.rb new file mode 100755 index 0000000..2431e0a --- /dev/null +++ b/examples/spot/convert/convert_limit_cancel_order.rb @@ -0,0 +1,15 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +$LOAD_PATH.unshift('./lib') + +require 'binance' +require_relative '../../common' + +logger = Common.setup_logger + +# set key here +# or BINANCE_PUBLIC_API_KEY in env +client = Binance::Spot.new(key: '', secret: '') + +logger.info(client.convert_limit_cancel_order(orderId: '1234')) diff --git a/examples/spot/convert/convert_limit_place_order.rb b/examples/spot/convert/convert_limit_place_order.rb new file mode 100755 index 0000000..30fef46 --- /dev/null +++ b/examples/spot/convert/convert_limit_place_order.rb @@ -0,0 +1,15 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +$LOAD_PATH.unshift('./lib') + +require 'binance' +require_relative '../../common' + +logger = Common.setup_logger + +# set key here +# or BINANCE_PUBLIC_API_KEY in env +client = Binance::Spot.new(key: '', secret: '') + +logger.info(client.convert_limit_place_order(baseAsset: 'BNB', quoteAsset: 'USDT', limitPrice: 590.0, side: 'BUY', expiredType: '1_D', baseAmount: 1.0)) diff --git a/examples/spot/convert/convert_limit_query_open_orders.rb b/examples/spot/convert/convert_limit_query_open_orders.rb new file mode 100755 index 0000000..853a923 --- /dev/null +++ b/examples/spot/convert/convert_limit_query_open_orders.rb @@ -0,0 +1,15 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +$LOAD_PATH.unshift('./lib') + +require 'binance' +require_relative '../../common' + +logger = Common.setup_logger + +# set key here +# or BINANCE_PUBLIC_API_KEY in env +client = Binance::Spot.new(key: '', secret: '') + +logger.info(client.convert_limit_query_open_orders) diff --git a/examples/spot/convert/convert_order_status.rb b/examples/spot/convert/convert_order_status.rb new file mode 100755 index 0000000..318b215 --- /dev/null +++ b/examples/spot/convert/convert_order_status.rb @@ -0,0 +1,15 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +$LOAD_PATH.unshift('./lib') + +require 'binance' +require_relative '../../common' + +logger = Common.setup_logger + +# set key here +# or BINANCE_PUBLIC_API_KEY in env +client = Binance::Spot.new(key: '', secret: '') + +logger.info(client.convert_order_status) diff --git a/examples/spot/loan/adjust_flexible_loan_ltv.rb b/examples/spot/loan/adjust_flexible_loan_ltv.rb new file mode 100755 index 0000000..9cb79a4 --- /dev/null +++ b/examples/spot/loan/adjust_flexible_loan_ltv.rb @@ -0,0 +1,15 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +$LOAD_PATH.unshift('./lib') + +require 'binance' +require_relative '../../common' + +logger = Common.setup_logger + +key = '' +secret = '' + +client = Binance::Spot.new(key: key, secret: secret) +logger.info(client.adjust_flexible_loan_ltv(loanCoin: 'BUSD', collateralCoin: 'BNB', adjustmentAmount: 1.0, direction: 'ADDITIONAL')) diff --git a/examples/spot/loan/borrow_flexible_loan.rb b/examples/spot/loan/borrow_flexible_loan.rb new file mode 100755 index 0000000..7f9654f --- /dev/null +++ b/examples/spot/loan/borrow_flexible_loan.rb @@ -0,0 +1,15 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +$LOAD_PATH.unshift('./lib') + +require 'binance' +require_relative '../../common' + +logger = Common.setup_logger + +key = '' +secret = '' + +client = Binance::Spot.new(key: key, secret: secret) +logger.info(client.borrow_flexible_loan(loanCoin: 'BUSD', collateralCoin: 'BNB', loanAmount: 1.0)) diff --git a/examples/spot/loan/get_flexible_loan_assets_data.rb b/examples/spot/loan/get_flexible_loan_assets_data.rb new file mode 100755 index 0000000..979f95d --- /dev/null +++ b/examples/spot/loan/get_flexible_loan_assets_data.rb @@ -0,0 +1,15 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +$LOAD_PATH.unshift('./lib') + +require 'binance' +require_relative '../../common' + +logger = Common.setup_logger + +key = '' +secret = '' + +client = Binance::Spot.new(key: key, secret: secret) +logger.info(client.get_flexible_loan_assets_data) diff --git a/examples/spot/loan/get_flexible_loan_borrow_history.rb b/examples/spot/loan/get_flexible_loan_borrow_history.rb new file mode 100755 index 0000000..5cb7647 --- /dev/null +++ b/examples/spot/loan/get_flexible_loan_borrow_history.rb @@ -0,0 +1,15 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +$LOAD_PATH.unshift('./lib') + +require 'binance' +require_relative '../../common' + +logger = Common.setup_logger + +key = '' +secret = '' + +client = Binance::Spot.new(key: key, secret: secret) +logger.info(client.get_flexible_loan_borrow_history) diff --git a/examples/spot/loan/get_flexible_loan_collateral_data.rb b/examples/spot/loan/get_flexible_loan_collateral_data.rb new file mode 100755 index 0000000..1050ad5 --- /dev/null +++ b/examples/spot/loan/get_flexible_loan_collateral_data.rb @@ -0,0 +1,15 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +$LOAD_PATH.unshift('./lib') + +require 'binance' +require_relative '../../common' + +logger = Common.setup_logger + +key = '' +secret = '' + +client = Binance::Spot.new(key: key, secret: secret) +logger.info(client.get_flexible_loan_collateral_data) diff --git a/examples/spot/loan/get_flexible_loan_ltv_adjustment_history.rb b/examples/spot/loan/get_flexible_loan_ltv_adjustment_history.rb new file mode 100755 index 0000000..5619338 --- /dev/null +++ b/examples/spot/loan/get_flexible_loan_ltv_adjustment_history.rb @@ -0,0 +1,15 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +$LOAD_PATH.unshift('./lib') + +require 'binance' +require_relative '../../common' + +logger = Common.setup_logger + +key = '' +secret = '' + +client = Binance::Spot.new(key: key, secret: secret) +logger.info(client.get_flexible_loan_ltv_adjustment_history) diff --git a/examples/spot/loan/get_flexible_loan_ongoing_orders.rb b/examples/spot/loan/get_flexible_loan_ongoing_orders.rb new file mode 100755 index 0000000..d9cc193 --- /dev/null +++ b/examples/spot/loan/get_flexible_loan_ongoing_orders.rb @@ -0,0 +1,15 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +$LOAD_PATH.unshift('./lib') + +require 'binance' +require_relative '../../common' + +logger = Common.setup_logger + +key = '' +secret = '' + +client = Binance::Spot.new(key: key, secret: secret) +logger.info(client.get_flexible_loan_ongoing_orders) diff --git a/examples/spot/loan/get_flexible_loan_repayment_history.rb b/examples/spot/loan/get_flexible_loan_repayment_history.rb new file mode 100755 index 0000000..82b9e83 --- /dev/null +++ b/examples/spot/loan/get_flexible_loan_repayment_history.rb @@ -0,0 +1,15 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +$LOAD_PATH.unshift('./lib') + +require 'binance' +require_relative '../../common' + +logger = Common.setup_logger + +key = '' +secret = '' + +client = Binance::Spot.new(key: key, secret: secret) +logger.info(client.get_flexible_loan_repayment_history) diff --git a/examples/spot/loan/get_loan_borrow_history.rb b/examples/spot/loan/get_loan_borrow_history.rb new file mode 100755 index 0000000..4b7883c --- /dev/null +++ b/examples/spot/loan/get_loan_borrow_history.rb @@ -0,0 +1,15 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +$LOAD_PATH.unshift('./lib') + +require 'binance' +require_relative '../../common' + +logger = Common.setup_logger + +key = '' +secret = '' + +client = Binance::Spot.new(key: key, secret: secret) +logger.info(client.get_loan_borrow_history) diff --git a/examples/spot/loan/get_loan_ltv_adjustment_history.rb b/examples/spot/loan/get_loan_ltv_adjustment_history.rb new file mode 100755 index 0000000..45ba76c --- /dev/null +++ b/examples/spot/loan/get_loan_ltv_adjustment_history.rb @@ -0,0 +1,15 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +$LOAD_PATH.unshift('./lib') + +require 'binance' +require_relative '../../common' + +logger = Common.setup_logger + +key = '' +secret = '' + +client = Binance::Spot.new(key: key, secret: secret) +logger.info(client.get_loan_ltv_adjustment_history) diff --git a/examples/spot/loan/get_loan_repayment_history.rb b/examples/spot/loan/get_loan_repayment_history.rb new file mode 100755 index 0000000..7fb0ddb --- /dev/null +++ b/examples/spot/loan/get_loan_repayment_history.rb @@ -0,0 +1,15 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +$LOAD_PATH.unshift('./lib') + +require 'binance' +require_relative '../../common' + +logger = Common.setup_logger + +key = '' +secret = '' + +client = Binance::Spot.new(key: key, secret: secret) +logger.info(client.get_loan_repayment_history) diff --git a/examples/spot/loan/repay_flexible_loan.rb b/examples/spot/loan/repay_flexible_loan.rb new file mode 100755 index 0000000..8b01844 --- /dev/null +++ b/examples/spot/loan/repay_flexible_loan.rb @@ -0,0 +1,15 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +$LOAD_PATH.unshift('./lib') + +require 'binance' +require_relative '../../common' + +logger = Common.setup_logger + +key = '' +secret = '' + +client = Binance::Spot.new(key: key, secret: secret) +logger.info(client.repay_flexible_loan(loanCoin: 'BUSD', collateralCoin: 'BNB', repayAmount: 1.0)) diff --git a/examples/spot/margin/margin_available_inventory.rb b/examples/spot/margin/margin_available_inventory.rb new file mode 100755 index 0000000..b6386ae --- /dev/null +++ b/examples/spot/margin/margin_available_inventory.rb @@ -0,0 +1,14 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +$LOAD_PATH.unshift('./lib') + +require 'binance' +require_relative '../../common' + +logger = Common.setup_logger + +# set key here +# or BINANCE_PUBLIC_API_KEY in env +client = Binance::Spot.new(key: '', secret: '') +logger.info(client.margin_available_inventory(type: 'MARGIN')) diff --git a/examples/spot/margin/margin_borrow_repay.rb b/examples/spot/margin/margin_borrow_repay.rb new file mode 100755 index 0000000..a3e371c --- /dev/null +++ b/examples/spot/margin/margin_borrow_repay.rb @@ -0,0 +1,14 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +$LOAD_PATH.unshift('./lib') + +require 'binance' +require_relative '../../common' + +logger = Common.setup_logger + +# set key here +# or BINANCE_PUBLIC_API_KEY in env +client = Binance::Spot.new(key: '', secret: '') +logger.info(client.margin_borrow_repay(asset: 'BNB', isIsolated: 'TRUE', symbol: 'BNBUSDT', amount: '1.0', type: 'BORROW')) diff --git a/examples/spot/margin/margin_borrow_repay_record.rb b/examples/spot/margin/margin_borrow_repay_record.rb new file mode 100755 index 0000000..9da91e2 --- /dev/null +++ b/examples/spot/margin/margin_borrow_repay_record.rb @@ -0,0 +1,14 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +$LOAD_PATH.unshift('./lib') + +require 'binance' +require_relative '../../common' + +logger = Common.setup_logger + +# set key here +# or BINANCE_PUBLIC_API_KEY in env +client = Binance::Spot.new(key: '', secret: '') +logger.info(client.margin_borrow_repay_record(type: 'BORROW')) diff --git a/examples/spot/margin/margin_leverage_bracket.rb b/examples/spot/margin/margin_leverage_bracket.rb new file mode 100755 index 0000000..0a2a1ab --- /dev/null +++ b/examples/spot/margin/margin_leverage_bracket.rb @@ -0,0 +1,14 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +$LOAD_PATH.unshift('./lib') + +require 'binance' +require_relative '../../common' + +logger = Common.setup_logger + +# set key here +# or BINANCE_PUBLIC_API_KEY in env +client = Binance::Spot.new(key: '', secret: '') +logger.info(client.margin_leverage_bracket) diff --git a/examples/spot/margin/margin_manual_liquidation.rb b/examples/spot/margin/margin_manual_liquidation.rb new file mode 100755 index 0000000..c3c26d7 --- /dev/null +++ b/examples/spot/margin/margin_manual_liquidation.rb @@ -0,0 +1,14 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +$LOAD_PATH.unshift('./lib') + +require 'binance' +require_relative '../../common' + +logger = Common.setup_logger + +# set key here +# or BINANCE_PUBLIC_API_KEY in env +client = Binance::Spot.new(key: '', secret: '') +logger.info(client.margin_manual_liquidation(type: 'MARGIN')) diff --git a/examples/spot/market/ticker_trading_day.rb b/examples/spot/market/ticker_trading_day.rb new file mode 100755 index 0000000..c664f2d --- /dev/null +++ b/examples/spot/market/ticker_trading_day.rb @@ -0,0 +1,16 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +$LOAD_PATH.unshift('./lib') + +require 'binance' +require_relative '../../common' + +logger = Common.setup_logger + +client = Binance::Spot.new(key: '', base_url: 'https://testnet.binance.vision') + +logger.info(client.ticker_price) + +# with symbol +logger.info(client.ticker_trading_day(symbol: 'BNBUSDT')) diff --git a/examples/spot/market/ui_klines.rb b/examples/spot/market/ui_klines.rb new file mode 100755 index 0000000..8aeebc8 --- /dev/null +++ b/examples/spot/market/ui_klines.rb @@ -0,0 +1,12 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +$LOAD_PATH.unshift('./lib') + +require 'binance' +require_relative '../../common' + +logger = Common.setup_logger + +client = Binance::Spot.new(key: '', base_url: 'https://testnet.binance.vision') +logger.info(client.ui_klines(symbol: 'BTCUSDT', interval: '1m')) diff --git a/examples/spot/simple_earn/locked_redeem_option.rb b/examples/spot/simple_earn/locked_redeem_option.rb new file mode 100755 index 0000000..fdf1376 --- /dev/null +++ b/examples/spot/simple_earn/locked_redeem_option.rb @@ -0,0 +1,12 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +$LOAD_PATH.unshift('./lib') + +require 'binance' +require_relative '../../common' + +logger = Common.setup_logger + +client = Binance::Spot.new(key: '', secret: '') +logger.info(client.locked_redeem_option(positionId: '1234', redeemTo: 'SPOT')) diff --git a/examples/spot/subaccount/get_sub_account_assets_v4.rb b/examples/spot/subaccount/get_sub_account_assets_v4.rb new file mode 100755 index 0000000..15a1c5e --- /dev/null +++ b/examples/spot/subaccount/get_sub_account_assets_v4.rb @@ -0,0 +1,12 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +$LOAD_PATH.unshift('./lib') + +require 'binance' +require_relative '../../common' + +logger = Common.setup_logger + +client = Binance::Spot.new(key: '', secret: '') +logger.info(client.get_sub_account_assets_v4(email: '')) diff --git a/examples/spot/subaccount/sub_account_enable_options.rb b/examples/spot/subaccount/sub_account_enable_options.rb new file mode 100755 index 0000000..2fdfce0 --- /dev/null +++ b/examples/spot/subaccount/sub_account_enable_options.rb @@ -0,0 +1,12 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +$LOAD_PATH.unshift('./lib') + +require 'binance' +require_relative '../../common' + +logger = Common.setup_logger + +client = Binance::Spot.new(key: '', secret: '') +logger.info(client.sub_account_enable_options(email: '')) diff --git a/examples/spot/subaccount/sub_account_futures_asset_details.rb b/examples/spot/subaccount/sub_account_futures_asset_details.rb new file mode 100755 index 0000000..1a38571 --- /dev/null +++ b/examples/spot/subaccount/sub_account_futures_asset_details.rb @@ -0,0 +1,12 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +$LOAD_PATH.unshift('./lib') + +require 'binance' +require_relative '../../common' + +logger = Common.setup_logger + +client = Binance::Spot.new(key: '', secret: '') +logger.info(client.sub_account_futures_asset_details(email: '')) diff --git a/examples/spot/subaccount/sub_account_list.rb b/examples/spot/subaccount/sub_account_list.rb new file mode 100755 index 0000000..fa5224b --- /dev/null +++ b/examples/spot/subaccount/sub_account_list.rb @@ -0,0 +1,12 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +$LOAD_PATH.unshift('./lib') + +require 'binance' +require_relative '../../common' + +logger = Common.setup_logger + +client = Binance::Spot.new(key: '', secret: '') +logger.info(client.sub_account_list) diff --git a/examples/spot/subaccount/sub_account_margin_asset_details.rb b/examples/spot/subaccount/sub_account_margin_asset_details.rb new file mode 100755 index 0000000..3ca4a20 --- /dev/null +++ b/examples/spot/subaccount/sub_account_margin_asset_details.rb @@ -0,0 +1,12 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +$LOAD_PATH.unshift('./lib') + +require 'binance' +require_relative '../../common' + +logger = Common.setup_logger + +client = Binance::Spot.new(key: '', secret: '') +logger.info(client.sub_account_margin_asset_details(email: '')) diff --git a/examples/spot/subaccount/sub_account_transaction_statistics.rb b/examples/spot/subaccount/sub_account_transaction_statistics.rb new file mode 100755 index 0000000..9c55a01 --- /dev/null +++ b/examples/spot/subaccount/sub_account_transaction_statistics.rb @@ -0,0 +1,12 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +$LOAD_PATH.unshift('./lib') + +require 'binance' +require_relative '../../common' + +logger = Common.setup_logger + +client = Binance::Spot.new(key: '', secret: '') +logger.info(client.sub_account_transaction_statistics(email: '')) diff --git a/examples/spot/subaccount/sub_account_transfer_log.rb b/examples/spot/subaccount/sub_account_transfer_log.rb new file mode 100755 index 0000000..3062fcf --- /dev/null +++ b/examples/spot/subaccount/sub_account_transfer_log.rb @@ -0,0 +1,12 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +$LOAD_PATH.unshift('./lib') + +require 'binance' +require_relative '../../common' + +logger = Common.setup_logger + +client = Binance::Spot.new(key: '', secret: '') +logger.info(client.sub_account_transfer_log(email: '', startTime: 1_640_998_861_000, endTime: 1_646_096_461_000, page: 1, limit: 10)) diff --git a/examples/spot/subaccount/sub_account_transfer_log_investor.rb b/examples/spot/subaccount/sub_account_transfer_log_investor.rb new file mode 100755 index 0000000..84d6fdf --- /dev/null +++ b/examples/spot/subaccount/sub_account_transfer_log_investor.rb @@ -0,0 +1,12 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +$LOAD_PATH.unshift('./lib') + +require 'binance' +require_relative '../../common' + +logger = Common.setup_logger + +client = Binance::Spot.new(key: '', secret: '') +logger.info(client.sub_account_transfer_log_investor(email: '', startTime: 1_640_998_861_000, endTime: 1_646_096_461_000, page: 1, limit: 10)) diff --git a/examples/spot/subaccount/sub_account_transfer_log_sub_account.rb b/examples/spot/subaccount/sub_account_transfer_log_sub_account.rb new file mode 100755 index 0000000..e5191ff --- /dev/null +++ b/examples/spot/subaccount/sub_account_transfer_log_sub_account.rb @@ -0,0 +1,12 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +$LOAD_PATH.unshift('./lib') + +require 'binance' +require_relative '../../common' + +logger = Common.setup_logger + +client = Binance::Spot.new(key: '', secret: '') +logger.info(client.sub_account_transfer_log_sub_account(startTime: 1_640_998_861_000, endTime: 1_646_096_461_000, page: 1, limit: 10)) diff --git a/examples/spot/trade/commission_rate.rb b/examples/spot/trade/commission_rate.rb new file mode 100755 index 0000000..7f6a185 --- /dev/null +++ b/examples/spot/trade/commission_rate.rb @@ -0,0 +1,18 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +$LOAD_PATH.unshift('./lib') + +require 'binance' +require_relative '../../common' + +logger = Common.setup_logger + +# set key and secret here +# or BINANCE_PUBLIC_API_KEY and BINANCE_PRIVATE_SECRET in env + +key = '' +secret = '' +client = Binance::Spot.new(key: key, secret: secret, base_url: 'https://testnet.binance.vision') + +logger.info(client.commission_rate(symbol: 'BNBUSDT')) diff --git a/examples/spot/trade/my_allocations.rb b/examples/spot/trade/my_allocations.rb new file mode 100755 index 0000000..807363c --- /dev/null +++ b/examples/spot/trade/my_allocations.rb @@ -0,0 +1,18 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +$LOAD_PATH.unshift('./lib') + +require 'binance' +require_relative '../../common' + +logger = Common.setup_logger + +# set key and secret here +# or BINANCE_PUBLIC_API_KEY and BINANCE_PRIVATE_SECRET in env + +key = '' +secret = '' +client = Binance::Spot.new(key: key, secret: secret, base_url: 'https://testnet.binance.vision') + +logger.info(client.my_allocations(symbol: 'BNBUSDT')) diff --git a/examples/spot/trade/my_prevented_matches.rb b/examples/spot/trade/my_prevented_matches.rb new file mode 100755 index 0000000..51d72d9 --- /dev/null +++ b/examples/spot/trade/my_prevented_matches.rb @@ -0,0 +1,18 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +$LOAD_PATH.unshift('./lib') + +require 'binance' +require_relative '../../common' + +logger = Common.setup_logger + +# set key and secret here +# or BINANCE_PUBLIC_API_KEY and BINANCE_PRIVATE_SECRET in env + +key = '' +secret = '' +client = Binance::Spot.new(key: key, secret: secret, base_url: 'https://testnet.binance.vision') + +logger.info(client.my_prevented_matches(symbol: 'BNBUSDT')) diff --git a/examples/spot/trade/new_oco_order.rb b/examples/spot/trade/new_oco_order.rb index 7108e9e..2ca5aa9 100755 --- a/examples/spot/trade/new_oco_order.rb +++ b/examples/spot/trade/new_oco_order.rb @@ -17,12 +17,12 @@ params = { symbol: 'BNBUSDT', - side: 'BUY', - quantity: 0.1, - price: 370, - stopPrice: 375, - stopLimitPrice: 374.8, - stopLimitTimeInForce: 'GTC' + side: 'SELL', + quantity: 1, + aboveType: 'LIMIT_MAKER', + belowType: 'LIMIT_MAKER', + abovePrice: 600, + belowPrice: 590 } logger.info(client.new_oco_order(params)) diff --git a/examples/spot/wallet/account_info.rb b/examples/spot/wallet/account_info.rb new file mode 100755 index 0000000..0539db3 --- /dev/null +++ b/examples/spot/wallet/account_info.rb @@ -0,0 +1,12 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +$LOAD_PATH.unshift('./lib') + +require 'binance' +require_relative '../../common' + +logger = Common.setup_logger + +client = Binance::Spot.new(key: '', secret: '') +logger.info(client.account_info) diff --git a/examples/spot/wallet/cloud_mining_payment_and_refund_history.rb b/examples/spot/wallet/cloud_mining_payment_and_refund_history.rb new file mode 100755 index 0000000..3327881 --- /dev/null +++ b/examples/spot/wallet/cloud_mining_payment_and_refund_history.rb @@ -0,0 +1,12 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +$LOAD_PATH.unshift('./lib') + +require 'binance' +require_relative '../../common' + +logger = Common.setup_logger + +client = Binance::Spot.new(key: '', secret: '') +logger.info(client.cloud_mining_payment_and_refund_history) diff --git a/examples/spot/wallet/delist_schedule.rb b/examples/spot/wallet/delist_schedule.rb new file mode 100755 index 0000000..d270171 --- /dev/null +++ b/examples/spot/wallet/delist_schedule.rb @@ -0,0 +1,12 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +$LOAD_PATH.unshift('./lib') + +require 'binance' +require_relative '../../common' + +logger = Common.setup_logger + +client = Binance::Spot.new(key: '', secret: '') +logger.info(client.delist_schedule) diff --git a/examples/spot/wallet/deposit_address_list.rb b/examples/spot/wallet/deposit_address_list.rb new file mode 100755 index 0000000..7cf35af --- /dev/null +++ b/examples/spot/wallet/deposit_address_list.rb @@ -0,0 +1,12 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +$LOAD_PATH.unshift('./lib') + +require 'binance' +require_relative '../../common' + +logger = Common.setup_logger + +client = Binance::Spot.new(key: '', secret: '') +logger.info(client.deposit_address_list(coin: 'BNB')) diff --git a/examples/spot/wallet/get_assets_converted_into_bnb.rb b/examples/spot/wallet/get_assets_converted_into_bnb.rb new file mode 100755 index 0000000..6f99ddc --- /dev/null +++ b/examples/spot/wallet/get_assets_converted_into_bnb.rb @@ -0,0 +1,12 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +$LOAD_PATH.unshift('./lib') + +require 'binance' +require_relative '../../common' + +logger = Common.setup_logger + +client = Binance::Spot.new(key: '', secret: '') +logger.info(client.get_assets_converted_into_bnb) diff --git a/examples/spot/wallet/one_click_arrival_deposit_apply.rb b/examples/spot/wallet/one_click_arrival_deposit_apply.rb new file mode 100755 index 0000000..efeef90 --- /dev/null +++ b/examples/spot/wallet/one_click_arrival_deposit_apply.rb @@ -0,0 +1,12 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +$LOAD_PATH.unshift('./lib') + +require 'binance' +require_relative '../../common' + +logger = Common.setup_logger + +client = Binance::Spot.new(key: '', secret: '') +logger.info(client.one_click_arrival_deposit_apply) diff --git a/examples/spot/wallet/user_delegation_history.rb b/examples/spot/wallet/user_delegation_history.rb new file mode 100755 index 0000000..b641a34 --- /dev/null +++ b/examples/spot/wallet/user_delegation_history.rb @@ -0,0 +1,12 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +$LOAD_PATH.unshift('./lib') + +require 'binance' +require_relative '../../common' + +logger = Common.setup_logger + +client = Binance::Spot.new(key: '', secret: '') +logger.info(client.user_delegation_history(email: '', startTime: 1_640_998_861_000, endTime: 1_646_096_461_000)) diff --git a/examples/spot/wallet/wallet_balance.rb b/examples/spot/wallet/wallet_balance.rb new file mode 100755 index 0000000..9f641ff --- /dev/null +++ b/examples/spot/wallet/wallet_balance.rb @@ -0,0 +1,12 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +$LOAD_PATH.unshift('./lib') + +require 'binance' +require_relative '../../common' + +logger = Common.setup_logger + +client = Binance::Spot.new(key: '', secret: '') +logger.info(client.wallet_balance) diff --git a/lib/binance/session.rb b/lib/binance/session.rb index b82f910..6d0194c 100644 --- a/lib/binance/session.rb +++ b/lib/binance/session.rb @@ -33,7 +33,8 @@ def sign_request(method, path, params: {}) private def process_request(conn, method, path, params) - response = conn.send(method, path_with_query(path, params.compact), nil) + compact = (params || {}).compact || {} + response = conn.send(method, path_with_query(path, compact), nil) extract_response(response) rescue Faraday::ClientError => e raise Binance::ClientError, e.response diff --git a/lib/binance/spot/convert.rb b/lib/binance/spot/convert.rb index 4652cc0..c89009b 100644 --- a/lib/binance/spot/convert.rb +++ b/lib/binance/spot/convert.rb @@ -5,6 +5,68 @@ class Spot # Convert endpoints # @see https://developers.binance.com/docs/convert/Introduction module Convert + # List All Convert Pairs + # + # GET /sapi/v1/convert/exchangeInfo + # + # @param kwargs [Hash] + # @option kwargs [String] :fromAsset Either fromAsset or toAsset or both should be send. User spends coin + # @option kwargs [String] :toAsset Either fromAsset or toAsset or both should be send. User spends coin + # @see https://developers.binance.com/docs/convert/market-data + def convert_exchange_info(**kwargs) + @session.sign_request(:get, '/sapi/v1/convert/exchangeInfo', params: kwargs) + end + + # Query order quantity precision per asset (USER_DATA) + # + # GET /sapi/v1/convert/assetInfo + # + # @param kwargs [Hash] + # @option kwargs [Integer] :recvWindow The value cannot be greater than 60000 + # @see https://developers.binance.com/docs/convert/market-data/Query-order-quantity-precision-per-asset + def convert_asset_info(**kwargs) + @session.sign_request(:get, '/sapi/v1/convert/assetInfo', params: kwargs) + end + + # Send Quote Request (USER_DATA) + # + # POST /sapi/v1/convert/getQuote + # + # @param fromAsset [String] + # @param toAsset [String] + # @param kwargs [Hash] + # @option kwargs [Float] :fromAmount Either fromAmount or toAmount should be specified. When specified, it is the amount you will be debited after the conversion + # @option kwargs [Float] :toAmount Either fromAmount or toAmount should be specified. When specified, it is the amount you will be credited after the conversion + # @option kwargs [String] :walletType SPOT or FUNDING. Default is SPOT + # @option kwargs [String] :validTime 10s, 30s, 1m, default 10s + # @option kwargs [Integer] :recvWindow The value cannot be greater than 60000 + # @see https://developers.binance.com/docs/convert/trade + def convert_get_quote(fromAsset:, toAsset:, **kwargs) + Binance::Utils::Validation.require_param('fromAsset', fromAsset) + Binance::Utils::Validation.require_param('toAsset', toAsset) + + @session.sign_request(:post, '/sapi/v1/convert/getQuote', params: kwargs.merge( + fromAsset: fromAsset, + toAsset: toAsset + )) + end + + # Accept Quote (TRADE) + # + # POST /sapi/v1/convert/acceptQuote + # + # @param quoteId [String] + # @param kwargs [Hash] + # @option kwargs [Integer] :recvWindow The value cannot be greater than 60000 + # @see https://developers.binance.com/docs/convert/trade/Accept-Quote + def convert_accept_quote(quoteId:, **kwargs) + Binance::Utils::Validation.require_param('quoteId', quoteId) + + @session.sign_request(:post, '/sapi/v1/convert/acceptQuote', params: kwargs.merge( + quoteId: quoteId + )) + end + # Get Convert Trade History (USER_DATA) # # GET /sapi/v1/convert/tradeFlow @@ -14,7 +76,7 @@ module Convert # @param kwargs [Hash] # @option kwargs [Integer] :limit default 100, max 1000 # @option kwargs [Integer] :recvWindow The value cannot be greater than 60000 - # @see https://developers.binance.com/docs/convert/trade/Get-Convert-Trade-History#http-request + # @see https://developers.binance.com/docs/convert/trade/Get-Convert-Trade-History def convert_trade_flow(startTime:, endTime:, **kwargs) Binance::Utils::Validation.require_param('startTime', startTime) Binance::Utils::Validation.require_param('endTime', endTime) @@ -24,6 +86,76 @@ def convert_trade_flow(startTime:, endTime:, **kwargs) endTime: endTime )) end + + # Order status (USER_DATA) + # + # GET /sapi/v1/convert/orderStatus + # + # @param kwargs [Hash] + # @option kwargs [String] :orderId Either orderId or quoteId is required + # @option kwargs [String] :quoteId Either orderId or quoteId is required + # @see https://developers.binance.com/docs/convert/trade/Order-Status + def convert_order_status(**kwargs) + @session.sign_request(:get, '/sapi/v1/convert/orderStatus', params: kwargs) + end + + # Place limit order (USER_DATA) + # + # POST /sapi/v1/convert/limit/placeOrder + # + # @param baseAsset [String] base asset (use the response fromIsBase from GET /sapi/v1/convert/exchangeInfo api to check which one is baseAsset) + # @param quoteAsset [String] quote asset + # @param limitPrice [Float] Symbol limit price (from baseAsset to quoteAsset) + # @param side [String] BUY or SELL + # @param expiredType [String] 1_D, 3_D, 7_D, 30_D (D means day) + # @param kwargs [Hash] + # @option kwargs [Float] :baseAmount Base asset amount. (One of baseAmount or quoteAmount is required) + # @option kwargs [Float] :quoteAmount Quote asset amount. (One of baseAmount or quoteAmount is required) + # @option kwargs [String] :walletType SPOT or FUNDING or SPOT_FUNDING. It is to use which type of assets. Default is SPOT. + # @option kwargs [Integer] :recvWindow The value cannot be greater than 60000 + # @see https://developers.binance.com/docs/convert/trade/Place-Order + def convert_limit_place_order(baseAsset:, quoteAsset:, limitPrice:, side:, expiredType:, **kwargs) + Binance::Utils::Validation.require_param('baseAsset', baseAsset) + Binance::Utils::Validation.require_param('quoteAsset', quoteAsset) + Binance::Utils::Validation.require_param('limitPrice', limitPrice) + Binance::Utils::Validation.require_param('side', side) + Binance::Utils::Validation.require_param('expiredType', expiredType) + + @session.sign_request(:post, '/sapi/v1/convert/limit/placeOrder', params: kwargs.merge( + baseAsset: baseAsset, + quoteAsset: quoteAsset, + limitPrice: limitPrice, + side: side, + expiredType: expiredType + )) + end + + # Cancel limit order (USER_DATA) + # + # POST /sapi/v1/convert/limit/cancelOrder + # + # @param orderId [String] + # @param kwargs [Hash] + # @option kwargs [Integer] :recvWindow The value cannot be greater than 60000 + # @see https://developers.binance.com/docs/convert/trade/Cancel-Order + def convert_limit_cancel_order(orderId:, **kwargs) + Binance::Utils::Validation.require_param('orderId', orderId) + + @session.sign_request(:post, '/sapi/v1/convert/limit/cancelOrder', params: kwargs.merge( + orderId: orderId + )) + end + + # Query limit open orders (USER_DATA) + # + # POST /sapi/v1/convert/limit/queryOpenOrders + # + # @param kwargs [Hash] + # @option kwargs [Integer] :recvWindow The value cannot be greater than 60000 + # @see https://developers.binance.com/docs/convert/trade/Query-Order + def convert_limit_query_open_orders(**kwargs) + @session.sign_request(:post, '/sapi/v1/convert/limit/queryOpenOrders', params: kwargs) + end end end end diff --git a/lib/binance/spot/loan.rb b/lib/binance/spot/loan.rb index 8036216..97272db 100644 --- a/lib/binance/spot/loan.rb +++ b/lib/binance/spot/loan.rb @@ -5,21 +5,235 @@ class Spot # all loan endpoints # @see https://developers.binance.com/docs/crypto_loan/Introduction module Loan + # Get Flexible Loan Collateral Assets Data (USER_DATA) + # + # GET /sapi/v2/loan/flexible/collateral/data + # + # @param kwargs [Hash] + # @option kwargs [String] :collateralCoin + # @option kwargs [Integer] :recvWindow The value cannot be greater than 60000 + # @see https://developers.binance.com/docs/crypto_loan/flexible-rate/market-data + def get_flexible_loan_collateral_data(**kwargs) + @session.sign_request(:get, '/sapi/v2/loan/flexible/collateral/data', params: kwargs) + end + + # Get Flexible Loan Assets Data (USER_DATA) + # + # GET /sapi/v2/loan/flexible/loanable/data + # + # @param kwargs [Hash] + # @option kwargs [String] :loanCoin + # @option kwargs [Integer] :recvWindow The value cannot be greater than 60000 + # @see https://developers.binance.com/docs/crypto_loan/flexible-rate/market-data/Get-Flexible-Loan-Assets-Data + def get_flexible_loan_assets_data(**kwargs) + @session.sign_request(:get, '/sapi/v2/loan/flexible/loanable/data', params: kwargs) + end + + # Flexible Loan Borrow (TRADE) + # + # POST /sapi/v2/loan/flexible/borrow + # + # @param loanCoin [String] + # @param collateralCoin [String] + # @param kwargs [Hash] + # @option kwargs [Float] :loanAmount Mandatory when collateralAmount is empty + # @option kwargs [Float] :collateralAmount Mandatory when loanAmount is empty + # @option kwargs [Integer] :recvWindow The value cannot be greater than 60000 + # @see https://developers.binance.com/docs/crypto_loan/flexible-rate/trade + def borrow_flexible_loan(loanCoin:, collateralCoin:, **kwargs) + Binance::Utils::Validation.require_param('loanCoin', loanCoin) + Binance::Utils::Validation.require_param('collateralCoin', collateralCoin) + + @session.sign_request(:post, '/sapi/v2/loan/flexible/borrow', params: kwargs.merge( + loanCoin: loanCoin, + collateralCoin: collateralCoin + )) + end + + # Flexible Loan Repay (TRADE) + # + # POST /sapi/v2/loan/flexible/repay + # + # @param loanCoin [String] + # @param collateralCoin [String] + # @param repayAmount [Float] + # @param kwargs [Hash] + # @option kwargs [Boolean] :collateralReturn Default: TRUE. TRUE: Return extra collateral to spot account; FALSE: Keep extra collateral in the order, and lower LTV. + # @option kwargs [Boolean] :fullRepayment Default: FALSE. TRUE: Full repayment; FALSE: Partial repayment, based on loanAmount + # @option kwargs [Integer] :recvWindow The value cannot be greater than 60000 + # @see https://developers.binance.com/docs/crypto_loan/flexible-rate/trade/Flexible-Loan-Repay + def repay_flexible_loan(loanCoin:, collateralCoin:, repayAmount:, **kwargs) + Binance::Utils::Validation.require_param('loanCoin', loanCoin) + Binance::Utils::Validation.require_param('collateralCoin', collateralCoin) + Binance::Utils::Validation.require_param('repayAmount', repayAmount) + + @session.sign_request(:post, '/sapi/v2/loan/flexible/repay', params: kwargs.merge( + loanCoin: loanCoin, + collateralCoin: collateralCoin, + repayAmount: repayAmount + )) + end + + # Flexible Loan Adjust LTV (TRADE) + # + # POST /sapi/v2/loan/flexible/adjust/ltv + # + # @param loanCoin [String] + # @param collateralCoin [String] + # @param adjustmentAmount [Float] + # @param direction [String] ADDITIONAL or REDUCED + # @param kwargs [Hash] + # @option kwargs [Integer] :recvWindow The value cannot be greater than 60000 + # @see https://developers.binance.com/docs/crypto_loan/flexible-rate/trade/Flexible-Loan-Adjust-LTV + def adjust_flexible_loan_ltv(loanCoin:, collateralCoin:, adjustmentAmount:, direction:, **kwargs) + Binance::Utils::Validation.require_param('loanCoin', loanCoin) + Binance::Utils::Validation.require_param('collateralCoin', collateralCoin) + Binance::Utils::Validation.require_param('adjustmentAmount', adjustmentAmount) + Binance::Utils::Validation.require_param('direction', direction) + + @session.sign_request(:post, '/sapi/v2/loan/flexible/adjust/ltv', params: kwargs.merge( + loanCoin: loanCoin, + collateralCoin: collateralCoin, + adjustmentAmount: adjustmentAmount, + direction: direction + )) + end + + # Get Flexible Loan LTV Adjustment History (USER_DATA) + # + # GET /sapi/v2/loan/flexible/ltv/adjustment/history + # + # @param kwargs [Hash] + # @option kwargs [String] :loanCoin + # @option kwargs [String] :collateralCoin + # @option kwargs [Integer] :startTime + # @option kwargs [Integer] :endTime + # @option kwargs [Integer] :current Current querying page. Start from 1; default: 1; max: 1000 + # @option kwargs [Integer] :limit Default: 10; max: 100 + # @option kwargs [Integer] :recvWindow The value cannot be greater than 60000 + # @see https://developers.binance.com/docs/crypto_loan/flexible-rate/user-information + def get_flexible_loan_ltv_adjustment_history(**kwargs) + @session.sign_request(:get, '/sapi/v2/loan/flexible/ltv/adjustment/history', params: kwargs) + end + + # Get Flexible Loan Borrow History(USER_DATA) + # + # GET /sapi/v2/loan/flexible/borrow/history + # + # @param kwargs [Hash] + # @option kwargs [String] :loanCoin + # @option kwargs [String] :collateralCoin + # @option kwargs [Integer] :startTime + # @option kwargs [Integer] :endTime + # @option kwargs [Integer] :current Current querying page. Start from 1; default: 1; max: 1000 + # @option kwargs [Integer] :limit Default: 10; max: 100 + # @option kwargs [Integer] :recvWindow The value cannot be greater than 60000 + # @see https://developers.binance.com/docs/crypto_loan/flexible-rate/user-information/Get-Flexible-Loan-Borrow-History + def get_flexible_loan_borrow_history(**kwargs) + @session.sign_request(:get, '/sapi/v2/loan/flexible/borrow/history', params: kwargs) + end + + # Get Flexible Loan Ongoing Orders (USER_DATA) + # + # GET /sapi/v2/loan/flexible/ongoing/orders + # + # @param kwargs [Hash] + # @option kwargs [String] :loanCoin + # @option kwargs [String] :collateralCoin + # @option kwargs [Integer] :current Current querying page. Start from 1; default: 1; max: 1000 + # @option kwargs [Integer] :limit Default: 10; max: 100 + # @option kwargs [Integer] :recvWindow The value cannot be greater than 60000 + # @see https://developers.binance.com/docs/crypto_loan/flexible-rate/user-information/Get-Flexible-Loan-Ongoing-Orders + def get_flexible_loan_ongoing_orders(**kwargs) + @session.sign_request(:get, '/sapi/v2/loan/flexible/ongoing/orders', params: kwargs) + end + + # Get Flexible Loan Repayment History (USER_DATA) + # + # GET /sapi/v2/loan/flexible/repay/history + # + # @param kwargs [Hash] + # @option kwargs [String] :loanCoin + # @option kwargs [String] :collateralCoin + # @option kwargs [Integer] :startTime + # @option kwargs [Integer] :endTime + # @option kwargs [Integer] :current Current querying page. Start from 1; default: 1; max: 1000 + # @option kwargs [Integer] :limit Default: 10; max: 100 + # @option kwargs [Integer] :recvWindow The value cannot be greater than 60000 + # @see https://developers.binance.com/docs/crypto_loan/flexible-rate/user-information/Get-Flexible-Loan-Repayment-History + def get_flexible_loan_repayment_history(**kwargs) + @session.sign_request(:get, '/sapi/v2/loan/flexible/repay/history', params: kwargs) + end + # Get Crypto Loans Income History (USER_DATA) # # GET /sapi/v1/loan/income # - # @param asset [String] - # @option kwargs [String] :type + # @param kwargs [Hash] + # @param kwargs [String] :asset + # @option kwargs [String] :type All types will be returned by default. Enum:borrowIn ,collateralSpent, repayAmount, collateralReturn(Collateral return after repayment), addCollateral + # removeCollateral, collateralReturnAfterLiquidation # @option kwargs [Integer] :startTime # @option kwargs [Integer] :endTime # @option kwargs [Integer] :limit default 20, max 100 # @option kwargs [Integer] :recvWindow The value cannot be greater than 60000 # @see https://developers.binance.com/docs/crypto_loan/stable-rate/market-data/Get-Crypto-Loans-Income-History - def get_loan_history(asset:, **kwargs) - Binance::Utils::Validation.require_param('asset', asset) + def get_loan_history(**kwargs) + @session.sign_request(:get, '/sapi/v1/loan/income', params: kwargs) + end - @session.sign_request(:get, '/sapi/v1/loan/income', params: kwargs.merge(asset: asset)) + # Get Loan Borrow History (USER_DATA) + # + # GET /sapi/v1/loan/borrow/history + # + # @param kwargs [Hash] + # @option kwargs [Integer] :orderId orderId in POST /sapi/v1/loan/borrow + # @option kwargs [String] :loanCoin + # @option kwargs [String] :collateralCoin + # @option kwargs [Integer] :startTime + # @option kwargs [Integer] :endTime + # @option kwargs [Integer] :current Current querying page. Start from 1; default: 1; max: 1000 + # @option kwargs [Integer] :limit Default: 10; max: 100 + # @option kwargs [Integer] :recvWindow The value cannot be greater than 60000 + # @see https://developers.binance.com/docs/crypto_loan/stable-rate/user-information + def get_loan_borrow_history(**kwargs) + @session.sign_request(:get, '/sapi/v1/loan/borrow/history', params: kwargs) + end + + # Get Loan LTV Adjustment History (USER_DATA) + # + # GET /sapi/v1/loan/ltv/adjustment/history + # + # @param kwargs [Hash] + # @option kwargs [Integer] :orderId + # @option kwargs [String] :loanCoin + # @option kwargs [String] :collateralCoin + # @option kwargs [Integer] :startTime + # @option kwargs [Integer] :endTime + # @option kwargs [Integer] :current Current querying page. Start from 1; default: 1; max: 1000 + # @option kwargs [Integer] :limit Default: 10; max: 100 + # @option kwargs [Integer] :recvWindow The value cannot be greater than 60000 + # @see https://developers.binance.com/docs/crypto_loan/stable-rate/user-information/Get-Loan-LTV-Adjustment-History + def get_loan_ltv_adjustment_history(**kwargs) + @session.sign_request(:get, '/sapi/v1/loan/ltv/adjustment/history', params: kwargs) + end + + # Get Loan Repayment History (USER_DATA) + # + # GET /sapi/v1/loan/repay/history + # + # @param kwargs [Hash] + # @option kwargs [Integer] :orderId + # @option kwargs [String] :loanCoin + # @option kwargs [String] :collateralCoin + # @option kwargs [Integer] :startTime + # @option kwargs [Integer] :endTime + # @option kwargs [Integer] :current Current querying page. Start from 1; default: 1; max: 1000 + # @option kwargs [Integer] :limit Default: 10; max: 100 + # @option kwargs [Integer] :recvWindow The value cannot be greater than 60000 + # @see https://developers.binance.com/docs/crypto_loan/stable-rate/user-information/Get-Loan-Repayment-History + def get_loan_repayment_history(**kwargs) + @session.sign_request(:get, '/sapi/v1/loan/repay/history', params: kwargs) end end end diff --git a/lib/binance/spot/margin.rb b/lib/binance/spot/margin.rb index 6a709d2..3e22704 100644 --- a/lib/binance/spot/margin.rb +++ b/lib/binance/spot/margin.rb @@ -33,6 +33,27 @@ def margin_price_index(symbol:) @session.limit_request(path: '/sapi/v1/margin/priceIndex', params: { symbol: symbol }) end + # Query Margin Available Inventory(USER_DATA) + # + # GET /sapi/v1/margin/available-inventory + # + # @param type [String] MARGIN or ISOLATED + # @see https://developers.binance.com/docs/margin_trading/market-data/Query-margin-avaliable-inventory + def margin_available_inventory(type:) + Binance::Utils::Validation.require_param('type', type) + + @session.sign_request(:get, '/sapi/v1/margin/available-inventory', params: { type: type }) + end + + # Query Liability Coin Leverage Bracket in Cross Margin Pro Mode(MARKET_DATA) + # + # GET /sapi/v1/margin/leverageBracket + # + # @see https://developers.binance.com/docs/margin_trading/market-data/Query-Liability-Coin-Leverage-Bracket-in-Cross-Margin-Pro-Mode + def margin_leverage_bracket + @session.limit_request(path: '/sapi/v1/margin/leverageBracket') + end + # Margin Account New Order (TRADE) # # POST /sapi/v1/margin/order @@ -138,6 +159,55 @@ def margin_interest_history(**kwargs) @session.sign_request(:get, '/sapi/v1/margin/interestHistory', params: kwargs) end + # Margin account borrow/repay (MARGIN) + # + # POST /sapi/v1/margin/borrow-repay + # + # @param asset [String] + # @param isIsolated [String] TRUE for Isolated Margin, FALSE for Cross Margin, Default FALSE + # @param symbol [String] + # @param amount [String] + # @param type [String] BORROW, REPAY + # @param kwargs [Hash] + # @option kwargs [Integer] :recvWindow The value cannot be greater than 60000 + # @see https://developers.binance.com/docs/margin_trading/borrow-and-repay/Margin-Account-Borrow-Repay + def margin_borrow_repay(asset:, isIsolated:, symbol:, amount:, type:, **kwargs) + Binance::Utils::Validation.require_param('asset', asset) + Binance::Utils::Validation.require_param('isIsolated', isIsolated) + Binance::Utils::Validation.require_param('symbol', symbol) + Binance::Utils::Validation.require_param('amount', amount) + Binance::Utils::Validation.require_param('type', type) + + @session.sign_request(:post, '/sapi/v1/margin/borrow-repay', params: kwargs.merge( + asset: asset, + isIsolated: isIsolated, + symbol: symbol, + amount: amount, + type: type + )) + end + + # Query borrow/repay records in Margin account (USER_DATA) + # + # GET /sapi/v1/margin/borrow-repay + # + # @param type [String] BORROW or REPAY + # @param kwargs [Hash] + # @option kwargs [String] :asset + # @option kwargs [String] :isIsolated + # @option kwargs [String] :txId + # @option kwargs [Integer] :startTime + # @option kwargs [Integer] :endTime + # @option kwargs [Integer] :current Currently querying page. Start from 1. Default:1 + # @option kwargs [Integer] :size Default:10 Max:100 + # @option kwargs [Integer] :recvWindow The value cannot be greater than 60000 + # @see https://developers.binance.com/docs/margin_trading/borrow-and-repay/Query-Borrow-Repay + def margin_borrow_repay_record(type:, **kwargs) + Binance::Utils::Validation.require_param('type', type) + + @session.sign_request(:get, '/sapi/v1/margin/borrow-repay', params: kwargs.merge(type: type)) + end + # Get Force Liquidation Record (USER_DATA) # # GET /sapi/v1/margin/forceLiquidationRec @@ -337,6 +407,21 @@ def margin_my_trades(symbol:, **kwargs) @session.sign_request(:get, '/sapi/v1/margin/myTrades', params: kwargs.merge(symbol: symbol)) end + # Margin Manual Liquidation + # + # POST /sapi/v1/margin/manual-liquidation + # + # @param type [String] MARGIN or ISOLATED + # @param kwargs [Hash] + # @param kwargs [String] :symbol When type selects ISOLATED, symbol must be filled in + # @option kwargs [Integer] :recvWindow The value cannot be greater than 60000 + # @see https://developers.binance.com/docs/margin_trading/trade/Margin-Manual-Liquidation + def margin_manual_liquidation(type:, **kwargs) + Binance::Utils::Validation.require_param('type', type) + + @session.sign_request(:post, '/sapi/v1/margin/manual-liquidation', params: kwargs.merge(type: type)) + end + # Query Max Borrow (USER_DATA) # # GET /sapi/v1/margin/maxBorrowable diff --git a/lib/binance/spot/market.rb b/lib/binance/spot/market.rb index e23099f..d430aab 100644 --- a/lib/binance/spot/market.rb +++ b/lib/binance/spot/market.rb @@ -9,13 +9,13 @@ class Spot # - trades # - orderbook # - etc - # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api#market-data-endpoints + # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api/public-api-endpoints#market-data-endpoints module Market # Test Connectivity # # GET /api/v3/ping # - # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api#test-connectivity + # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api/public-api-endpoints#test-connectivity def ping @session.public_request(path: '/api/v3/ping') end @@ -24,7 +24,7 @@ def ping # # GET /api/v3/time # - # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api#check-server-time + # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api/public-api-endpoints#check-server-time def time @session.public_request(path: '/api/v3/time') end @@ -36,7 +36,9 @@ def time # @option kwargs [string] :symbol # @option kwargs [string] :symbols # @option kwargs [string] :permissions - # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api#exchange-information + # @option kwargs [Boolean] :feature Controls whether the content of the permissionSets field is populated or not. Defaults to true + # @option kwargs [string] :symbolStatus Filters symbols that have this tradingStatus. Valid values: TRADING, HALT, BREAK. Cannot be used in combination with symbols or symbol. + # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api/public-api-endpoints#exchange-information def exchange_info(symbol: nil, symbols: nil, permissions: nil) if symbols.is_a?(Array) symbols = symbols.map { |v| "%22#{v}%22" }.join(',') @@ -59,7 +61,7 @@ def exchange_info(symbol: nil, symbols: nil, permissions: nil) # @param symbol [String] the symbol # @param kwargs [Hash] # @option kwargs [Integer] :limit Default 100; max 1000. Valid limits:[5, 10, 20, 50, 100, 500, 1000, 5000] - # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api#order-book + # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api/public-api-endpoints#order-book def depth(symbol:, **kwargs) Binance::Utils::Validation.require_param('symbol', symbol) @@ -76,7 +78,7 @@ def depth(symbol:, **kwargs) # @param symbol [String] the symbol # @param kwargs [Hash] # @option kwargs [Integer] :limit Default 500; max 1000. - # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api#recent-trades-list + # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api/public-api-endpoints#recent-trades-list def trades(symbol:, **kwargs) Binance::Utils::Validation.require_param('symbol', symbol) @@ -96,7 +98,7 @@ def trades(symbol:, **kwargs) # @param kwargs [Hash] # @option kwargs [Integer] :limit Default 500; max 1000. # @option kwargs [Integer] :fromId Trade id to fetch from. Default gets most recent trades. - # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api#old-trade-lookup + # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api/public-api-endpoints#old-trade-lookup def historical_trades(symbol:, **kwargs) Binance::Utils::Validation.require_param('symbol', symbol) @@ -118,7 +120,7 @@ def historical_trades(symbol:, **kwargs) # @option kwargs [Integer] :endTime Timestamp in ms to get aggregate trades until INCLUSIVE. # @option kwargs [Integer] :fromId Trade id to fetch from. Default gets most recent trades. # @option kwargs [Integer] :limit Default 500; max 1000. - # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api#compressedaggregate-trades-list + # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api/public-api-endpoints#compressedaggregate-trades-list def agg_trades(symbol:, **kwargs) Binance::Utils::Validation.require_param('symbol', symbol) @@ -140,8 +142,9 @@ def agg_trades(symbol:, **kwargs) # @param kwargs [Hash] # @option kwargs [Integer] :startTime Timestamp in ms to get aggregate trades from INCLUSIVE. # @option kwargs [Integer] :endTime Timestamp in ms to get aggregate trades until INCLUSIVE. + # @option kwargs [String] :timeZone Default: 0 (UTC) # @option kwargs [Integer] :limit Default 500; max 1000. - # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api#klinecandlestick-data + # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api/public-api-endpoints#klinecandlestick-data def klines(symbol:, interval:, **kwargs) Binance::Utils::Validation.require_param('symbol', symbol) Binance::Utils::Validation.require_param('interval', interval) @@ -155,6 +158,33 @@ def klines(symbol:, interval:, **kwargs) ) end + # UIKlines + # + # uiKlines return modified kline data, optimized for presentation of candlestick charts + # + # GET /api/v3/uiKlines + # + # @param symbol [String] the symbol + # @param interval [String] interval + # @param kwargs [Hash] + # @option kwargs [Integer] :startTime + # @option kwargs [Integer] :endTime + # @option kwargs [String] :timeZone Default: 0 (UTC) + # @option kwargs [Integer] :limit Default 500; max 1000. + # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api/public-api-endpoints#uiklines + def ui_klines(symbol:, interval:, **kwargs) + Binance::Utils::Validation.require_param('symbol', symbol) + Binance::Utils::Validation.require_param('interval', interval) + + @session.public_request( + path: '/api/v3/uiKlines', + params: kwargs.merge( + symbol: symbol, + interval: interval + ) + ) + end + # Current Average Price # # Current average price for a symbol. @@ -162,7 +192,7 @@ def klines(symbol:, interval:, **kwargs) # GET /api/v3/avgPrice # # @param symbol [String] the symbol - # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api#current-average-price + # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api/public-api-endpoints#current-average-price def avg_price(symbol:) Binance::Utils::Validation.require_param('symbol', symbol) @@ -179,7 +209,7 @@ def avg_price(symbol:) # GET /api/v3/ticker/24hr # # @param symbol [String] the symbol - # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api#24hr-ticker-price-change-statistics + # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api/public-api-endpoints#24hr-ticker-price-change-statistics def ticker_24hr(symbol: nil) @session.public_request( path: '/api/v3/ticker/24hr', @@ -187,6 +217,35 @@ def ticker_24hr(symbol: nil) ) end + # Trading Day Ticker + # + # Price change statistics for a trading day. + # + # GET /api/v3/ticker/tradingDay + # + # @param kwargs [Hash] + # @option kwargs [string] :symbol Either symbol or symbols must be provided + # @option kwargs [string] :symbols + # @option kwargs [String] :timeZone Default: 0 (UTC) + # @option kwargs [String] :type Supported values: FULL or MINI. Default: FULL + # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api/public-api-endpoints#trading-day-ticker + def ticker_trading_day(symbol: nil, symbols: nil, **kwargs) + raise Binance::DuplicatedParametersError.new('symbol', 'symbols') unless symbols.nil? || symbol.nil? + + if symbols + symbols = symbols.map { |s| "\"#{s}\"" }.join(',') + symbols = { symbols: "\[#{symbols}\]".upcase } + end + + @session.public_request( + path: '/api/v3/ticker/tradingDay', + params: kwargs.merge( + symbol: symbol, + symbols: symbols + ) + ) + end + # Symbol Price Ticker # # Latest price for a symbol or symbols. @@ -194,7 +253,7 @@ def ticker_24hr(symbol: nil) # GET /api/v3/ticker/price # # @param symbol [String] the symbol - # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api#symbol-price-ticker + # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api/public-api-endpoints#symbol-price-ticker def ticker_price(symbol: nil) @session.public_request( path: '/api/v3/ticker/price', @@ -209,7 +268,7 @@ def ticker_price(symbol: nil) # GET /api/v3/ticker/bookTicker # # @param symbol [String] the symbol - # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api#symbol-order-book-ticker + # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api/public-api-endpoints#symbol-order-book-ticker def book_ticker(symbol: nil) @session.public_request( path: '/api/v3/ticker/bookTicker', @@ -224,7 +283,7 @@ def book_ticker(symbol: nil) # GET /api/v3/ticker/bookTicker # # @param symbol [String] the symbol - # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api#symbol-order-book-ticker + # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api/public-api-endpoints#symbol-order-book-ticker def ticker(symbol: nil, symbols: nil, windowSize: '1d') raise Binance::DuplicatedParametersError.new('symbol', 'symbols') unless symbols.nil? || symbol.nil? diff --git a/lib/binance/spot/simple_earn.rb b/lib/binance/spot/simple_earn.rb index 710be7c..c470208 100644 --- a/lib/binance/spot/simple_earn.rb +++ b/lib/binance/spot/simple_earn.rb @@ -63,6 +63,7 @@ def flexible_subscribe(productId:, amount:, **kwargs) # @param kwargs [Hash] # @option kwargs [Boolean] :autoSubscribe true or false, default true # @option kwargs [String] :sourceAccount SPOT,FUND,ALL, default SPOT + # @option kwargs [String] :redeemTo SPOT,FLEXIBLE, default FLEXIBLE # @option kwargs [Integer] :recvWindow The value cannot be greater than 60000 # @see https://developers.binance.com/docs/simple_earn/earn/Subscribe-Locked-Product def locked_subscribe(projectId:, amount:, **kwargs) @@ -365,6 +366,25 @@ def locked_subscription_preview(projectId:, amount:, **kwargs) )) end + # Set Locked Product Redeem Option (USER_DATA) + # + # POST /sapi/v1/simple-earn/locked/setRedeemOption + # + # @param positionId [String] + # @param redeemTo [String] SPOT or FLEXIBLE + # @param kwargs [Hash] + # @option kwargs [Integer] :recvWindow The value cannot be greater than 60000 + # @see https://developers.binance.com/docs/simple_earn/earn/Set-Locked-Redeem-Option + def locked_redeem_option(positionId:, redeemTo:, **kwargs) + Binance::Utils::Validation.require_param('positionId', positionId) + Binance::Utils::Validation.require_param('redeemTo', redeemTo) + + @session.sign_request(:post, '/sapi/v1/simple-earn/locked/setRedeemOption', params: kwargs.merge( + positionId: positionId, + redeemTo: redeemTo + )) + end + # Get Rate History (USER_DATA) # # GET /sapi/v1/simple-earn/flexible/history/rateHistory diff --git a/lib/binance/spot/subaccount.rb b/lib/binance/spot/subaccount.rb index 7341ed1..388d6e4 100644 --- a/lib/binance/spot/subaccount.rb +++ b/lib/binance/spot/subaccount.rb @@ -124,6 +124,20 @@ def get_sub_account_assets(email:, **kwargs) @session.sign_request(:get, '/sapi/v3/sub-account/assets', params: kwargs.merge(email: email)) end + # Query Sub-account Assets (For Master Account)(USER_DATA) + # + # GET /sapi/v4/sub-account/assets + # + # @param email [String] + # @param kwargs [Hash] + # @option kwargs [Integer] :recvWindow The value cannot be greater than 60000 + # @see https://developers.binance.com/docs/sub_account/asset-management/Query-Sub-account-Assets-V4 + def get_sub_account_assets_v4(email:, **kwargs) + Binance::Utils::Validation.require_param('email', email) + + @session.sign_request(:get, '/sapi/v4/sub-account/assets', params: kwargs.merge(email: email)) + end + # Query Sub-account Spot Assets Summary (For Master Account) # # GET /sapi/v1/sub-account/spotSummary @@ -214,6 +228,22 @@ def sub_account_enable_margin(email:, **kwargs) )) end + # Enable Options for Sub-account(For Master Account)(USER_DATA) + # + # POST /sapi/v1/sub-account/eoptions/enable + # + # @param email [String] Sub user email + # @param kwargs [Hash] + # @option kwargs [Integer] :recvWindow The value cannot be greater than 60000 + # @see https://developers.binance.com/docs/sub_account/account-management/Enable-Options-for-Sub-account + def sub_account_enable_options(email:, **kwargs) + Binance::Utils::Validation.require_param('email', email) + + @session.sign_request(:post, '/sapi/v1/sub-account/eoptions/enable', params: kwargs.merge( + email: email + )) + end + # Get Detail on Sub-account's Margin Account (For Master Account) # # GET /sapi/v1/sub-account/margin/account @@ -313,6 +343,22 @@ def sub_account_futures_position_risk(email:, futuresType:, **kwargs) )) end + # Query Sub-account Transaction Statistics(For Master Account)(USER_DATA) + # + # GET /sapi/v1/sub-account/transaction-statistics + # + # @param email [String] Sub user email + # @param kwargs [Hash] + # @option kwargs [Integer] :recvWindow The value cannot be greater than 60000 + # @see https://developers.binance.com/docs/sub_account/account-management/Query-Sub-account-Transaction-Statistics + def sub_account_transaction_statistics(email:, **kwargs) + Binance::Utils::Validation.require_param('email', email) + + @session.sign_request(:get, '/sapi/v1/sub-account/transaction-statistics', params: kwargs.merge( + email: email + )) + end + # Futures Transfer for Sub-account(For Master Account) # # POST /sapi/v1/sub-account/futures/transfer @@ -526,6 +572,34 @@ def sub_account_asset_details(email:, **kwargs) @session.sign_request(:get, '/sapi/v1/managed-subaccount/asset', params: kwargs.merge(email: email)) end + # Query Managed Sub-account Margin Asset Details(For Investor Master Account)(USER_DATA) + # + # GET /sapi/v1/managed-subaccount/marginAsset + # + # @param email [String] + # @param kwargs [Hash] + # @option kwargs [String] :accountType No input or input "MARGIN" to get Cross Margin account details. Input "ISOLATED_MARGIN" to get Isolated Margin account details. + # @see https://developers.binance.com/docs/sub_account/managed-sub-account/Query-Managed-Sub-account-Margin-Asset-Details + def sub_account_margin_asset_details(email:, **kwargs) + Binance::Utils::Validation.require_param('email', email) + + @session.sign_request(:get, '/sapi/v1/managed-subaccount/marginAsset', params: kwargs.merge(email: email)) + end + + # Query Managed Sub-account Futures Asset Details(For Investor Master Account)(USER_DATA) + # + # GET /sapi/v1/managed-subaccount/fetch-future-asset + # + # @param email [String] + # @param kwargs [Hash] + # @option kwargs [String] :accountType No input or input "USDT_FUTURE" to get UM Futures account details. Input "COIN_FUTURE" to get CM Futures account details. + # @see https://developers.binance.com/docs/sub_account/managed-sub-account/Query-Managed-Sub-account-Futures-Asset-Details + def sub_account_futures_asset_details(email:, **kwargs) + Binance::Utils::Validation.require_param('email', email) + + @session.sign_request(:get, '/sapi/v1/managed-subaccount/fetch-future-asset', params: kwargs.merge(email: email)) + end + # Withdrawl assets from the managed sub-account (For Investor Master Account) # # POST /sapi/v1/managed-subaccount/withdraw @@ -549,6 +623,105 @@ def withdraw_from_sub_account(fromEmail:, asset:, amount:, **kwargs) )) end + # Query Managed Sub Account Transfer Log(For Trading Team Master Account)(USER_DATA) + # + # GET /sapi/v1/managed-subaccount/queryTransLogForTradeParent + # + # @param email [String] Managed Sub Account Email + # @param startTime [Integer] + # @param endTime [Integer] + # @param page [Integer] + # @param limit [Integer] Limit (Max: 500) + # @param kwargs [Hash] + # @option kwargs [String] :transfers Transfer Direction (FROM/TO) + # @option kwargs [String] :transferFunctionAccountType Transfer function account type (SPOT/MARGIN/ISOLATED_MARGIN/USDT_FUTURE/COIN_FUTURE) + # @see https://developers.binance.com/docs/sub_account/managed-sub-account/Query-Managed-Sub-Account-Transfer-Log-Trading-Team-Master + def sub_account_transfer_log(email:, startTime:, endTime:, page:, limit:, **kwargs) + Binance::Utils::Validation.require_param('email', email) + Binance::Utils::Validation.require_param('startTime', startTime) + Binance::Utils::Validation.require_param('endTime', endTime) + Binance::Utils::Validation.require_param('page', page) + Binance::Utils::Validation.require_param('limit', limit) + + @session.sign_request(:get, '/sapi/v1/managed-subaccount/queryTransLogForTradeParent', params: kwargs.merge( + email: email, + startTime: startTime, + endTime: endTime, + page: page, + limit: limit + )) + end + + # Query Managed Sub Account Transfer Log (For Trading Team Sub Account)(USER_DATA) + # + # GET /sapi/v1/managed-subaccount/query-trans-log + # + # @param startTime [Integer] + # @param endTime [Integer] + # @param page [Integer] + # @param limit [Integer] Limit (Max: 500) + # @param kwargs [Hash] + # @option kwargs [String] :transfers Transfer Direction (FROM/TO) + # @option kwargs [String] :transferFunctionAccountType Transfer function account type (SPOT/MARGIN/ISOLATED_MARGIN/USDT_FUTURE/COIN_FUTURE) + # @option kwargs [Integer] :recvWindow The value cannot be greater than 60000 + # @see https://developers.binance.com/docs/sub_account/managed-sub-account/Query-Managed-Sub-Account-Transfer-Log-Trading-Team-Sub + def sub_account_transfer_log_sub_account(startTime:, endTime:, page:, limit:, **kwargs) + Binance::Utils::Validation.require_param('startTime', startTime) + Binance::Utils::Validation.require_param('endTime', endTime) + Binance::Utils::Validation.require_param('page', page) + Binance::Utils::Validation.require_param('limit', limit) + + @session.sign_request(:get, '/sapi/v1/managed-subaccount/query-trans-log', params: kwargs.merge( + startTime: startTime, + endTime: endTime, + page: page, + limit: limit + )) + end + + # Query Managed Sub Account Transfer Log (For Investor Master Account)(USER_DATA) + # + # GET /sapi/v1/managed-subaccount/queryTransLogForInvestor + # + # @param email [String] Managed Sub Account Email + # @param startTime [Integer] + # @param endTime [Integer] + # @param page [Integer] + # @param limit [Integer] Limit (Max: 500) + # @param kwargs [Hash] + # @option kwargs [String] :transfers Transfer Direction (FROM/TO) + # @option kwargs [String] :transferFunctionAccountType Transfer function account type (SPOT/MARGIN/ISOLATED_MARGIN/USDT_FUTURE/COIN_FUTURE) + # @see https://developers.binance.com/docs/sub_account/managed-sub-account/Query-Managed-Sub-Account-Transfer-Log-Investor + def sub_account_transfer_log_investor(email:, startTime:, endTime:, page:, limit:, **kwargs) + Binance::Utils::Validation.require_param('email', email) + Binance::Utils::Validation.require_param('startTime', startTime) + Binance::Utils::Validation.require_param('endTime', endTime) + Binance::Utils::Validation.require_param('page', page) + Binance::Utils::Validation.require_param('limit', limit) + + @session.sign_request(:get, '/sapi/v1/managed-subaccount/queryTransLogForInvestor', params: kwargs.merge( + email: email, + startTime: startTime, + endTime: endTime, + page: page, + limit: limit + )) + end + + # Query Managed Sub-account List (For Investor)(USER_DATA) + # + # GET /sapi/v1/managed-subaccount/info + # + # @param kwargs [Hash] + # @option kwargs [String] :email Status Managed sub-account email + # @option kwargs [Integer] :page Default: 1 + # @option kwargs [Integer] :limit Default: 10, Max: 20 + # @option kwargs [Integer] :recvWindow The value cannot be greater than 60000 + # @see https://developers.binance.com/docs/sub_account/managed-sub-account/Query-Managed-Sub-account-List + def sub_account_list(**kwargs) + @session.sign_request(:get, '/sapi/v1/managed-subaccount/info', params: kwargs) + end + # Enable or Disable IP Restriction for a Sub-account API Key (For Master Account) # # POST /sapi/v2/sub-account/subAccountApi/ipRestriction diff --git a/lib/binance/spot/trade.rb b/lib/binance/spot/trade.rb index 64fff67..dbe659a 100644 --- a/lib/binance/spot/trade.rb +++ b/lib/binance/spot/trade.rb @@ -29,7 +29,7 @@ module Trade # @option kwargs [Float] :icebergeQty # @option kwargs [String] :newOrderRespType Set the response JSON. ACK, RESULT, or FULL. # @option kwargs [Integer] :recvWindow The value cannot be greater than 60000 - # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api#test-new-order-trade + # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api/public-api-endpoints#test-new-order-trade def new_order_test(symbol:, side:, type:, **kwargs) Binance::Utils::Validation.require_param('symbol', symbol) Binance::Utils::Validation.require_param('side', side) @@ -61,7 +61,7 @@ def new_order_test(symbol:, side:, type:, **kwargs) # @option kwargs [Float] :icebergeQty # @option kwargs [String] :newOrderRespType Set the response JSON. ACK, RESULT, or FULL. # @option kwargs [Integer] :recvWindow The value cannot be greater than 60000 - # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api#new-order-trade + # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api/public-api-endpoints#new-order-trade def new_order(symbol:, side:, type:, **kwargs) Binance::Utils::Validation.require_param('symbol', symbol) Binance::Utils::Validation.require_param('side', side) @@ -84,7 +84,7 @@ def new_order(symbol:, side:, type:, **kwargs) # @option kwargs [String] :origClientOrderId # @option kwargs [String] :newClientOrderId # @option kwargs [Integer] :recvWindow The value cannot be greater than 60000 - # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api#cancel-order-trade + # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api/public-api-endpoints#cancel-order-trade def cancel_order(symbol:, **kwargs) Binance::Utils::Validation.require_param('symbol', symbol) @@ -98,7 +98,7 @@ def cancel_order(symbol:, **kwargs) # @param symbol [String] the symbol # @param kwargs [Hash] # @option kwargs [Integer] :recvWindow The value cannot be greater than 60000 - # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api#cancel-all-open-orders-on-a-symbol-trade + # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api/public-api-endpoints#cancel-all-open-orders-on-a-symbol-trade def cancel_open_orders(symbol:, **kwargs) Binance::Utils::Validation.require_param('symbol', symbol) @@ -114,7 +114,7 @@ def cancel_open_orders(symbol:, **kwargs) # @option kwargs [Integer] :orderId # @option kwargs [String] :origClientOrderId # @option kwargs [Integer] :recvWindow The value cannot be greater than 60000 - # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api#query-order-user_data + # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api/public-api-endpoints#query-order-user_data def get_order(symbol:, **kwargs) Binance::Utils::Validation.require_param('symbol', symbol) @@ -128,7 +128,7 @@ def get_order(symbol:, **kwargs) # @param kwargs [Hash] # @option kwargs [String] :symbol the symbol # @option kwargs [Integer] :recvWindow The value cannot be greater than 60000 - # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api#current-open-orders-user_data + # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api/public-api-endpoints#current-open-orders-user_data def open_orders(**kwargs) @session.sign_request(:get, '/api/v3/openOrders', params: kwargs) end @@ -146,7 +146,7 @@ def open_orders(**kwargs) # @option kwargs [String] :endTime # @option kwargs [String] :limit Default 500; max 1000. # @option kwargs [Integer] :recvWindow The value cannot be greater than 60000 - # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api#all-orders-user_data + # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api/public-api-endpoints#all-orders-user_data def all_orders(symbol:, **kwargs) Binance::Utils::Validation.require_param('symbol', symbol) @@ -162,32 +162,42 @@ def all_orders(symbol:, **kwargs) # @param symbol [String] the symbol # @param side [String] # @param quantity [Float] - # @param price [Float] - # @param stopPrice [Float] + # @param aboveType [String] + # @param belowType [String] # @param kwargs [Hash] # @option kwargs [String] :listClientOrderId - # @option kwargs [String] :limitClientOrderId - # @option kwargs [Float] :limitIcebergQty - # @option kwargs [String] :stopClientOrderId - # @option kwargs [Float] :stopLimitPrice - # @option kwargs [Float] :stopIcebergQty - # @option kwargs [Float] :stopLimitTimeInForce GTC/ FOK/ IOC + # @option kwargs [String] :aboveClientOrderId Arbitrary unique ID among open orders for the above order. Automatically generated if not sent + # @option kwargs [Integer] :aboveIcebergQty Note that this can only be used if aboveTimeInForce is GTC + # @option kwargs [Float] :abovePrice + # @option kwargs [Float] :aboveStopPriceCan be used if aboveType is STOP_LOSS or STOP_LOSS_LIMIT. Either aboveStopPrice or aboveTrailingDelta or both, must be specified. + # @option kwargs [Integer] :aboveTrailingDelta + # @option kwargs [Float] :aboveTimeInForce Required if the aboveType is STOP_LOSS_LIMIT. + # @option kwargs [Integer] :aboveStrategyId Arbitrary numeric value identifying the above order within an order strategy. + # @option kwargs [Integer] :aboveStrategyType Arbitrary numeric value identifying the above order strategy. Values smaller than 1000000 are reserved and cannot be used. + # @option kwargs [String] :belowClientOrderId Arbitrary unique ID among open orders for the below order. Automatically generated if not sent + # @option kwargs [Integer] :belowIcebergQty Note that this can only be used if belowTimeInForce is GTC + # @option kwargs [Float] :belowPrice Can be used if belowType is STOP_LOSS_LIMIT or LIMIT_MAKER to specify the limit price. + # @option kwargs [Float] :belowStopPrice Can be used if belowType is STOP_LOSS or STOP_LOSS_LIMIT. Either belowStopPrice or belowTrailingDelta or both, must be specified. + # @option kwargs [Integer] :belowTrailingDelta + # @option kwargs [String] :belowTimeInForce Required if the belowType is STOP_LOSS_LIMIT + # @option kwargs [Integer] :belowStrategyId Arbitrary numeric value identifying the below order within an order strategy + # @option kwargs [String] :belowStrategyType Arbitrary numeric value identifying the below order strategy. Values smaller than 1000000 are reserved and cannot be used. # @option kwargs [String] :newOrderRespType # @option kwargs [Integer] :recvWindow The value cannot be greater than 60000 - # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api#new-oco---deprecated-trade - def new_oco_order(symbol:, side:, quantity:, price:, stopPrice:, **kwargs) + # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api/public-api-endpoints#new-order-list---oco-trade + def new_oco_order(symbol:, side:, quantity:, aboveType:, belowType:, **kwargs) Binance::Utils::Validation.require_param('symbol', symbol) Binance::Utils::Validation.require_param('side', side) Binance::Utils::Validation.require_param('quantity', quantity) - Binance::Utils::Validation.require_param('price', price) - Binance::Utils::Validation.require_param('stopPrice', stopPrice) + Binance::Utils::Validation.require_param('aboveType', aboveType) + Binance::Utils::Validation.require_param('belowType', belowType) @session.sign_request(:post, '/api/v3/order/oco', params: kwargs.merge( symbol: symbol, side: side, quantity: quantity, - price: price, - stopPrice: stopPrice + aboveType: aboveType, + belowType: belowType )) end @@ -201,7 +211,7 @@ def new_oco_order(symbol:, side:, quantity:, price:, stopPrice:, **kwargs) # @option kwargs [String] :listClientOrderId # @option kwargs [String] :newClientOrderId # @option kwargs [Integer] :recvWindow The value cannot be greater than 60000 - # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api#cancel-order-list-trade + # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api/public-api-endpoints#cancel-order-list-trade def cancel_order_list(symbol:, **kwargs) Binance::Utils::Validation.require_param('symbol', symbol) @@ -218,7 +228,7 @@ def cancel_order_list(symbol:, **kwargs) # @option kwargs [Integer] :orderListId # @option kwargs [String] :orgClientOrderId # @option kwargs [Integer] :recvWindow The value cannot be greater than 60000 - # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api#query-order-lists-user_data + # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api/public-api-endpoints#query-order-list-user_data def order_list(**kwargs) @session.sign_request(:get, '/api/v3/orderList', params: kwargs) end @@ -235,7 +245,7 @@ def order_list(**kwargs) # @option kwargs [String] :endTime # @option kwargs [String] :limit Default 500; max 1000. # @option kwargs [Integer] :recvWindow The value cannot be greater than 60000 - # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api#query-all-order-lists-user_data + # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api/public-api-endpoints#query-all-order-lists-user_data def all_order_list(**kwargs) @session.sign_request(:get, '/api/v3/allOrderList', params: kwargs) end @@ -246,7 +256,7 @@ def all_order_list(**kwargs) # # @param kwargs [Hash] # @option kwargs [Integer] :recvWindow The value cannot be greater than 60000 - # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api#query-open-order-lists-user_data + # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api/public-api-endpoints#query-open-order-lists-user_data def open_order_list(**kwargs) @session.sign_request(:get, '/api/v3/openOrderList', params: kwargs) end @@ -257,7 +267,7 @@ def open_order_list(**kwargs) # # @param kwargs [Hash] # @option kwargs [Integer] :recvWindow The value cannot be greater than 60000 - # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api#account-information-user_data + # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api/public-api-endpoints#account-information-user_data def account(**kwargs) @session.sign_request(:get, '/api/v3/account', params: kwargs) end @@ -274,7 +284,7 @@ def account(**kwargs) # @option kwargs [Integer] :fromId TradeId to fetch from. Default gets most recent trades. # @option kwargs [Integer] :limit Default 500; max 1000. # @option kwargs [Integer] :recvWindow The value cannot be greater than 60000 - # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api#account-trade-list-user_data + # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api/public-api-endpoints#account-trade-list-user_data def my_trades(symbol:, **kwargs) @session.sign_request(:get, '/api/v3/myTrades', params: kwargs.merge(symbol: symbol)) end @@ -285,11 +295,59 @@ def my_trades(symbol:, **kwargs) # # @param kwargs [Hash] # @option kwargs [Integer] :recvWindow The value cannot be greater than 60000 - # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api#query-current-order-count-usage-trade + # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api/public-api-endpoints#query-unfilled-order-count-user_data def get_order_rate_limit(**kwargs) @session.sign_request(:get, '/api/v3/rateLimit/order', params: kwargs) end + # Query Prevented Matches (USER_DATA) + # + # GET /api/v3/myPreventedMatches + # + # @param symbol [String] + # @param kwargs [Hash] + # @param kwargs [Integer] :preventedMatchId + # @param kwargs [Integer] :orderId + # @param kwargs [Integer] :fromPreventedMatchId + # @param kwargs [Integer] :limit Default: 500; Max: 1000 + # @param kwargs [Integer] :recvWindow The value cannot be greater than 60000 + # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api/public-api-endpoints#query-prevented-matches-user_data + def my_prevented_matches(symbol:, **kwargs) + Binance::Utils::Validation.require_param('symbol', symbol) + + @session.sign_request(:get, '/api/v3/myPreventedMatches', params: kwargs.merge(symbol: symbol)) + end + + # Query Allocations (USER_DATA) + # + # GET /api/v3/myAllocations + # + # @param symbol [String] + # @param kwargs [Hash] + # @param kwargs [Integer] :startTime + # @param kwargs [Integer] :endTime + # @param kwargs [Integer] :fromAllocationId + # @param kwargs [Integer] :limit Default 500;Max 1000 + # @param kwargs [Integer] :orderId + # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api/public-api-endpoints#query-allocations-user_data + def my_allocations(symbol:, **kwargs) + Binance::Utils::Validation.require_param('symbol', symbol) + + @session.sign_request(:get, '/api/v3/myAllocations', params: kwargs.merge(symbol: symbol)) + end + + # Query Commission Rates (USER_DATA) + # + # GET /api/v3/account/commission + # + # @param symbol [String] + # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api/public-api-endpoints#query-commission-rates-user_data + def commission_rate(symbol:) + Binance::Utils::Validation.require_param('symbol', symbol) + + @session.sign_request(:get, '/api/v3/account/commission', params: { symbol: symbol }) + end + # Cancel an Existing Order and Send a New Order (TRADE) # # POST /api/v3/order/cancelReplace @@ -307,12 +365,18 @@ def get_order_rate_limit(**kwargs) # @option kwargs [String] :cancelOrigClientOrderId # @option kwargs [Integer] :cancelOrderId # @option kwargs [String] :newClientOrderId + # @option kwargs [Integer] :strategyId + # @option kwargs [Integer] :strategyType The value cannot be less than 1000000 # @option kwargs [Float] :stopPrice # @option kwargs [Integer] :trailingDelta # @option kwargs [Float] :icebergQty # @option kwargs [String] :newOrderRespType + # @option kwargs [String] :selfTradePreventionMode The allowed enums is dependent on what is configured on the symbo + # @option kwargs [String] :cancelRestrictions ONLY_NEW - Cancel will succeed if the order status is NEW. ONLY_PARTIALLY_FILLED - Cancel will succeed if order status is PARTIALLY_FILLED + # @option kwargs [String] :orderRateLimitExceededMode DO_NOTHING (default)- will only attempt to cancel the order if account has not exceeded the unfilled order rate limit + # CANCEL_ONLY - will always cancel the order # @option kwargs [Integer] :recvWindow The value cannot be greater than 60000 - # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api#cancel-an-existing-order-and-send-a-new-order-trade + # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api/public-api-endpoints#cancel-an-existing-order-and-send-a-new-order-trade def cancel_replace(symbol:, side:, type:, cancelReplaceMode:, **kwargs) Binance::Utils::Validation.require_param('symbol', symbol) Binance::Utils::Validation.require_param('side', side) diff --git a/lib/binance/spot/wallet.rb b/lib/binance/spot/wallet.rb index b9877dc..f2579a4 100644 --- a/lib/binance/spot/wallet.rb +++ b/lib/binance/spot/wallet.rb @@ -16,6 +16,17 @@ def system_status @session.public_request(path: '/sapi/v1/system/status') end + # Get symbols delist schedule for spot (MARKET_DATA) + # + # GET /sapi/v1/spot/delist-schedule + # + # @param kwargs [Hash] + # @option kwargs [Integer] :recvWindow The value cannot be greater than 60000 + # @see https://developers.binance.com/docs/wallet/others/delist-schedule + def delist_schedule(**kwargs) + @session.public_request(path: '/sapi/v1/spot/delist-schedule', params: kwargs) + end + # All Coins' Information (USER_DATA) # # GET /sapi/v1/capital/config/getall @@ -149,6 +160,36 @@ def deposit_address(coin:, **kwargs) )) end + # Fetch deposit address list with network (USER_DATA) + # + # GET /sapi/v1/capital/deposit/address/list + # + # @param coin [String] coin refers to the parent network address format that the address is using + # @param kwargs [Hash] + # @option kwargs [String] :network + # @see https://developers.binance.com/docs/wallet/capital/fetch-deposit-address-list-with-network + def deposit_address_list(coin:, **kwargs) + Binance::Utils::Validation.require_param('coin', coin) + + @session.sign_request(:get, '/sapi/v1/capital/deposit/address/list', params: kwargs.merge( + coin: coin + )) + end + + # One click arrival deposit apply (for expired address deposit) (USER_DATA) + # + # POST /sapi/v1/capital/deposit/credit-apply + # + # @param kwargs [Hash] + # @option kwargs [String] :depositId Deposit record Id, priority use + # @option kwargs [String] :txId Deposit txId, used when depositId is not specified + # @option kwargs [String] :subAccountId Sub-accountId of Cloud user + # @option kwargs [String] :subUserId Sub-userId of parent user + # @see https://developers.binance.com/docs/wallet/capital/one-click-arrival-deposite-apply + def one_click_arrival_deposit_apply(**kwargs) + @session.sign_request(:post, '/sapi/v1/capital/deposit/credit-apply', params: kwargs) + end + # Account Status (USER_DATA) # # GET /sapi/v1/account/status @@ -233,6 +274,17 @@ def asset_detail(**kwargs) @session.sign_request(:get, '/sapi/v1/asset/assetDetail', params: kwargs) end + # Query User Wallet Balance (USER_DATA) + # + # GET /sapi/v1/asset/wallet/balance + # + # @param kwargs [Hash] + # @option kwargs [Integer] :recvWindow The value cannot be greater than 60000 + # @see https://developers.binance.com/docs/wallet/asset/query-user-wallet-balance + def wallet_balance(**kwargs) + @session.sign_request(:get, '/sapi/v1/asset/wallet/balance', params: kwargs) + end + # Trade Fee (USER_DATA) # # GET /sapi/v1/asset/tradeFee @@ -288,6 +340,18 @@ def user_universal_transfer_history(type:, **kwargs) @session.sign_request(:get, '/sapi/v1/asset/transfer', params: kwargs.merge(type: type)) end + # Get Assets That Can Be Converted Into BNB (USER_DATA) + # + # POST /sapi/v1/asset/dust-btc + # + # @param kwargs [Hash] + # @option kwargs [String] :accountType SPOT or MARGIN,default SPOT + # @option kwargs [Integer] :recvWindow The value cannot be greater than 60000 + # @see https://developers.binance.com/docs/wallet/asset/assets-can-convert-bnb + def get_assets_converted_into_bnb(**kwargs) + @session.sign_request(:post, '/sapi/v1/asset/dust-btc', params: kwargs) + end + # Funding Wallet (USER_DATA) # # POST /sapi/v1/asset/get-funding-asset @@ -301,6 +365,60 @@ def funding_wallet(**kwargs) @session.sign_request(:post, '/sapi/v1/asset/get-funding-asset', params: kwargs) end + # Get Cloud-Mining payment and refund history (USER_DATA) + # + # GET /sapi/v1/asset/ledger-transfer/cloud-mining/queryByPage + # + # @param kwargs [Hash] + # @option kwargs [Integer] :tranId + # @option kwargs [String] :clientTranId The unique flag + # @option kwargs [String] :asset If it is blank, we will query all assets + # @option kwargs [Integer] :startTime inclusive, unit: ms + # @option kwargs [Integer] :endTime exclusive, unit: ms + # @option kwargs [Integer] :current current page, default 1, the min value is 1 + # @option kwargs [Integer] :size page size, default 10, the max value is 100 + # @see https://developers.binance.com/docs/wallet/asset/cloud-mining-payment-and-refund-history + def cloud_mining_payment_and_refund_history(**kwargs) + @session.sign_request(:get, '/sapi/v1/asset/ledger-transfer/cloud-mining/queryByPage', params: kwargs) + end + + # Query User Delegation History (For Master Account)(USER_DATA) + # + # GET /sapi/v1/asset/custody/transfer-history + # + # @param email [String] + # @param startTime [Integer] + # @param endTime [Integer] + # @param kwargs [Hash] + # @option kwargs [String] :type Delegate/Undelegate + # @option kwargs [String] :asset + # @option kwargs [Integer] :current Default 1 + # @option kwargs [Integer] :size default 10, max 100 + # @option kwargs [Integer] :recvWindow The value cannot be greater than 60000 + # @see https://developers.binance.com/docs/wallet/asset/query-user-delegation + def user_delegation_history(email:, startTime:, endTime:, **kwargs) + Binance::Utils::Validation.require_param('email', email) + Binance::Utils::Validation.require_param('startTime', startTime) + Binance::Utils::Validation.require_param('endTime', endTime) + + @session.sign_request(:get, '/sapi/v1/asset/custody/transfer-history', params: kwargs.merge( + email: email, + startTime: startTime, + endTime: endTime + )) + end + + # Account info (USER_DATA) + # + # GET /sapi/v1/account/info + # + # @param kwargs [Hash] + # @option kwargs [Integer] :recvWindow The value cannot be greater than 60000 + # @see https://developers.binance.com/docs/wallet/account + def account_info(**kwargs) + @session.sign_request(:get, '/sapi/v1/account/info', params: kwargs) + end + # Get API Key Permission (USER_DATA) # # GET /sapi/v1/account/apiRestrictions diff --git a/lib/binance/spot/websocket.rb b/lib/binance/spot/websocket.rb index aa3861e..668e806 100644 --- a/lib/binance/spot/websocket.rb +++ b/lib/binance/spot/websocket.rb @@ -99,6 +99,18 @@ def book_ticker(callbacks:, symbol: nil) create_connection(url, callbacks) end + # Average Price + # Average price streams push changes in the average price over a fixed time interval. + # Stream Name: @avgPrice + # Update Speed: 1000ms + # + # @param symbol [String] + # @see https://developers.binance.com/docs/binance-spot-api-docs/web-socket-streams#average-price + def avg_price(symbol:, callbacks:) + url = "#{@base_url}/ws/#{symbol.downcase}@avgPrice" + create_connection(url, callbacks) + end + # Partial Book Depth Streams # Top bids and asks, Valid are 5, 10, or 20. # Stream Name: @depth OR @depth@100ms. diff --git a/lib/binance/version.rb b/lib/binance/version.rb index eb48978..9434f7b 100644 --- a/lib/binance/version.rb +++ b/lib/binance/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Binance - VERSION = '1.6.0' + VERSION = '1.7.0' end diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..9ce85d9 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,6 @@ +{ + "name": "binance-connector-ruby", + "lockfileVersion": 3, + "requires": true, + "packages": {} +} diff --git a/spec/binance/spot/convert/convert_accept_quote.rb b/spec/binance/spot/convert/convert_accept_quote.rb new file mode 100644 index 0000000..b435f9f --- /dev/null +++ b/spec/binance/spot/convert/convert_accept_quote.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Binance::Spot::Convert, '#convert_accept_quote' do + let(:path) { '/sapi/v1/convert/acceptQuote' } + let(:body) { fixture('response.json') } + let(:status) { 200 } + + before do + mocking_signature_and_ts(**params) + stub_binance_sign_request(:post, path, status, body, params) + end + + context 'validation' do + where(:params) do + [ + { quoteId: '' } + ] + end + with_them do + it 'should raise validation error without mandatory params' do + expect { spot_client_signed.convert_accept_quote(**params) }.to raise_error(Binance::RequiredParameterError) + end + end + end + + context 'with params' do + let(:params) { { quoteId: '1234' } } + it 'should accept the offered quote by quote ID' do + spot_client_signed.convert_accept_quote(**params) + expect(send_a_request_with_signature(:post, path, params)).to have_been_made + end + end +end diff --git a/spec/binance/spot/convert/convert_asset_info.rb b/spec/binance/spot/convert/convert_asset_info.rb new file mode 100644 index 0000000..8979f48 --- /dev/null +++ b/spec/binance/spot/convert/convert_asset_info.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Binance::Spot::Convert, '#convert_asset_info' do + let(:path) { '/sapi/v1/convert/assetInfo' } + let(:body) { fixture('response.json') } + let(:status) { 200 } + + before do + stub_binance_sign_request(:get, path, status, body) + end + + it 'should return supported assets precision information' do + spot_client_signed.convert_asset_info + expect(send_a_request_with_signature(:get, path)).to have_been_made + end +end diff --git a/spec/binance/spot/convert/convert_exchange_info.rb b/spec/binance/spot/convert/convert_exchange_info.rb new file mode 100644 index 0000000..4d0e1e2 --- /dev/null +++ b/spec/binance/spot/convert/convert_exchange_info.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Binance::Spot::Convert, '#convert_exchange_info' do + let(:path) { '/sapi/v1/convert/exchangeInfo' } + let(:body) { fixture('response.json') } + let(:status) { 200 } + + before do + stub_binance_sign_request(:get, path, status, body, params) + end + + it 'should return all convertible token pairs and the tokens respective upper/lower limits' do + spot_client_signed.convert_exchange_info(**params) + expect(send_a_request_with_signature(:get, path, params)).to have_been_made + end +end diff --git a/spec/binance/spot/convert/convert_get_quote.rb b/spec/binance/spot/convert/convert_get_quote.rb new file mode 100644 index 0000000..7f1d6b1 --- /dev/null +++ b/spec/binance/spot/convert/convert_get_quote.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Binance::Spot::Convert, '#convert_get_quote' do + let(:path) { '/sapi/v1/convert/getQuote' } + let(:body) { fixture('response.json') } + let(:status) { 200 } + + before do + mocking_signature_and_ts(**params) + stub_binance_sign_request(:post, path, status, body, params) + end + + context 'validation' do + where(:params) do + [ + { fromAsset: 'USDT', toAsset: '' }, + { fromAsset: '', toAsset: 'BNB' } + ] + end + with_them do + it 'should raise validation error without mandatory params' do + expect { spot_client_signed.convert_get_quote(**params) }.to raise_error(Binance::RequiredParameterError) + end + end + end + + context 'with params' do + let(:params) { { fromAsset: 'USDT', toAsset: 'BNB' } } + it 'should return quote for the requested token pairs' do + spot_client_signed.convert_get_quote(**params) + expect(send_a_request_with_signature(:post, path, params)).to have_been_made + end + end +end diff --git a/spec/binance/spot/convert/convert_limit_cancel_order.rb b/spec/binance/spot/convert/convert_limit_cancel_order.rb new file mode 100644 index 0000000..3899ab0 --- /dev/null +++ b/spec/binance/spot/convert/convert_limit_cancel_order.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Binance::Spot::Convert, '#convert_limit_cancel_order' do + let(:path) { '/sapi/v1/convert/limit/cancelOrder' } + let(:body) { fixture('response.json') } + let(:status) { 200 } + + before do + mocking_signature_and_ts(**params) + stub_binance_sign_request(:post, path, status, body, params) + end + + context 'validation' do + where(:params) do + [ + { orderId: '' } + ] + end + with_them do + it 'should raise validation error without mandatory params' do + expect { spot_client_signed.convert_limit_cancel_order(**params) }.to raise_error(Binance::RequiredParameterError) + end + end + end + + context 'with params' do + let(:params) { { orderId: '1234' } } + it 'should cancel a limit order' do + spot_client_signed.convert_limit_cancel_order(**params) + expect(send_a_request_with_signature(:post, path, params)).to have_been_made + end + end +end diff --git a/spec/binance/spot/convert/convert_limit_place_order.rb b/spec/binance/spot/convert/convert_limit_place_order.rb new file mode 100644 index 0000000..bd5cc69 --- /dev/null +++ b/spec/binance/spot/convert/convert_limit_place_order.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Binance::Spot::Convert, '#convert_limit_place_order' do + let(:path) { '/sapi/v1/convert/limit/placeOrder' } + let(:body) { fixture('response.json') } + let(:status) { 200 } + + before do + mocking_signature_and_ts(**params) + stub_binance_sign_request(:post, path, status, body, params) + end + + context 'validation' do + where(:params) do + [ + { baseAsset: '', quoteAsset: 'USDT', limitPrice: 590.0, side: 'BUY', expiredType: '1_D', baseAmount: 1.0 }, + { baseAsset: 'BNB', quoteAsset: '', limitPrice: 590.0, side: 'BUY', expiredType: '1_D', baseAmount: 1.0 }, + { baseAsset: 'BNB', quoteAsset: 'USDT', limitPrice: '', side: 'BUY', expiredType: '1_D', baseAmount: 1.0 }, + { baseAsset: 'BNB', quoteAsset: 'USDT', limitPrice: 590.0, side: '', expiredType: '1_D', baseAmount: 1.0 }, + { baseAsset: 'BNB', quoteAsset: 'USDT', limitPrice: 590.0, side: 'BUY', expiredType: '', baseAmount: 1.0 } + ] + end + with_them do + it 'should raise validation error without mandatory params' do + expect { spot_client_signed.convert_limit_place_order(**params) }.to raise_error(Binance::RequiredParameterError) + end + end + end + + context 'with params' do + let(:params) { { baseAsset: 'BNB', quoteAsset: 'USDT', limitPrice: 590.0, side: 'BUY', expiredType: '1_D', baseAmount: 1.0 } } + it 'should place a limit order' do + spot_client_signed.convert_limit_place_order(**params) + expect(send_a_request_with_signature(:post, path, params)).to have_been_made + end + end +end diff --git a/spec/binance/spot/convert/convert_limit_query_open_orders.rb b/spec/binance/spot/convert/convert_limit_query_open_orders.rb new file mode 100644 index 0000000..b9257ba --- /dev/null +++ b/spec/binance/spot/convert/convert_limit_query_open_orders.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Binance::Spot::Convert, '#convert_limit_query_open_orders' do + let(:path) { '/sapi/v1/convert/limit/queryOpenOrders' } + let(:body) { fixture('response.json') } + let(:status) { 200 } + + before do + stub_binance_sign_request(:post, path, status, body) + end + + it 'should return a quote for the requested token pairs' do + spot_client_signed.convert_limit_query_open_orders + expect(send_a_request_with_signature(:post, path)).to have_been_made + end +end diff --git a/spec/binance/spot/convert/convert_order_status.rb b/spec/binance/spot/convert/convert_order_status.rb new file mode 100644 index 0000000..872d082 --- /dev/null +++ b/spec/binance/spot/convert/convert_order_status.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Binance::Spot::Convert, '#convert_order_status' do + let(:path) { '/sapi/v1/convert/orderStatus' } + let(:body) { fixture('response.json') } + let(:status) { 200 } + + before do + stub_binance_sign_request(:get, path, status, body) + end + + it 'should retrieve convert trade history' do + spot_client_signed.convert_order_status + expect(send_a_request_with_signature(:get, path)).to have_been_made + end +end diff --git a/spec/binance/spot/loan/adjust_flexible_loan_ltv.rb b/spec/binance/spot/loan/adjust_flexible_loan_ltv.rb new file mode 100644 index 0000000..297b761 --- /dev/null +++ b/spec/binance/spot/loan/adjust_flexible_loan_ltv.rb @@ -0,0 +1,38 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Binance::Spot::Convert, '#adjust_flexible_loan_ltv' do + let(:path) { '/sapi/v2/loan/flexible/adjust/ltv' } + let(:body) { fixture('response.json') } + let(:status) { 200 } + + before do + mocking_signature_and_ts(**params) + stub_binance_sign_request(:post, path, status, body, params) + end + + context 'validation' do + where(:params) do + [ + { loanCoin: '', collateralCoin: 'BNB', adjustmentAmount: 1.0, direction: 'ADDITIONAL' }, + { loanCoin: 'BUSD', collateralCoin: '', adjustmentAmount: 1.0, direction: 'ADDITIONAL' }, + { loanCoin: 'BUSD', collateralCoin: 'BNB', adjustmentAmount: '', direction: 'ADDITIONAL' }, + { loanCoin: 'BUSD', collateralCoin: 'BNB', adjustmentAmount: 1.0, direction: '' } + ] + end + with_them do + it 'should raise validation error without mandatory params' do + expect { spot_client_signed.adjust_flexible_loan_ltv(**params) }.to raise_error(Binance::RequiredParameterError) + end + end + end + + context 'with params' do + let(:params) { { loanCoin: 'BUSD', collateralCoin: 'BNB', adjustmentAmount: 1.0, direction: 'ADDITIONAL' } } + it 'should return flexible Loan Adjust LTV' do + spot_client_signed.adjust_flexible_loan_ltv(**params) + expect(send_a_request_with_signature(:post, path, params)).to have_been_made + end + end +end diff --git a/spec/binance/spot/loan/borrow_flexible_loan.rb b/spec/binance/spot/loan/borrow_flexible_loan.rb new file mode 100644 index 0000000..da50c15 --- /dev/null +++ b/spec/binance/spot/loan/borrow_flexible_loan.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Binance::Spot::Convert, '#borrow_flexible_loan' do + let(:path) { '/sapi/v2/loan/flexible/borrow' } + let(:body) { fixture('response.json') } + let(:status) { 200 } + + before do + mocking_signature_and_ts(**params) + stub_binance_sign_request(:post, path, status, body, params) + end + + context 'validation' do + where(:params) do + [ + { loanCoin: '', collateralCoin: 'BNB', loanAmount: 1.0 }, + { loanCoin: 'BUSD', collateralCoin: '', loanAmount: 1.0 } + ] + end + with_them do + it 'should raise validation error without mandatory params' do + expect { spot_client_signed.borrow_flexible_loan(**params) }.to raise_error(Binance::RequiredParameterError) + end + end + end + + context 'with params' do + let(:params) { { loanCoin: 'BUSD', collateralCoin: 'BNB', loanAmount: 1.0 } } + it 'should borrow Flexible Loan' do + spot_client_signed.borrow_flexible_loan(**params) + expect(send_a_request_with_signature(:post, path, params)).to have_been_made + end + end +end diff --git a/spec/binance/spot/loan/get_flexible_loan_assets_data.rb b/spec/binance/spot/loan/get_flexible_loan_assets_data.rb new file mode 100644 index 0000000..ac8ef8e --- /dev/null +++ b/spec/binance/spot/loan/get_flexible_loan_assets_data.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Binance::Spot::Convert, '#get_flexible_loan_assets_data' do + let(:path) { '/sapi/v2/loan/flexible/loanable/data' } + let(:body) { fixture('response.json') } + let(:status) { 200 } + + before do + stub_binance_sign_request(:get, path, status, body) + end + + it 'should return interest rate and borrow limit of flexible loanable assets' do + spot_client_signed.get_flexible_loan_assets_data + expect(send_a_request_with_signature(:get, path)).to have_been_made + end +end diff --git a/spec/binance/spot/loan/get_flexible_loan_borrow_history.rb b/spec/binance/spot/loan/get_flexible_loan_borrow_history.rb new file mode 100644 index 0000000..19c6b2c --- /dev/null +++ b/spec/binance/spot/loan/get_flexible_loan_borrow_history.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Binance::Spot::Convert, '#get_flexible_loan_borrow_history' do + let(:path) { '/sapi/v2/loan/flexible/borrow/history' } + let(:body) { fixture('response.json') } + let(:status) { 200 } + + before do + stub_binance_sign_request(:get, path, status, body) + end + + it 'should return flexible loan borrow history' do + spot_client_signed.get_flexible_loan_borrow_history + expect(send_a_request_with_signature(:get, path)).to have_been_made + end +end diff --git a/spec/binance/spot/loan/get_flexible_loan_collateral_data.rb b/spec/binance/spot/loan/get_flexible_loan_collateral_data.rb new file mode 100644 index 0000000..bb6e7d6 --- /dev/null +++ b/spec/binance/spot/loan/get_flexible_loan_collateral_data.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Binance::Spot::Convert, '#get_flexible_loan_collateral_data' do + let(:path) { '/sapi/v2/loan/flexible/collateral/data' } + let(:body) { fixture('response.json') } + let(:status) { 200 } + + before do + stub_binance_sign_request(:get, path, status, body) + end + + it 'should return LTV information and collateral limit of flexible loans collateral assets' do + spot_client_signed.get_flexible_loan_collateral_data + expect(send_a_request_with_signature(:get, path)).to have_been_made + end +end diff --git a/spec/binance/spot/loan/get_flexible_loan_ltv_adjustment_history.rb b/spec/binance/spot/loan/get_flexible_loan_ltv_adjustment_history.rb new file mode 100644 index 0000000..372eb78 --- /dev/null +++ b/spec/binance/spot/loan/get_flexible_loan_ltv_adjustment_history.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Binance::Spot::Convert, '#get_flexible_loan_ltv_adjustment_history' do + let(:path) { '/sapi/v2/loan/flexible/ltv/adjustment/history' } + let(:body) { fixture('response.json') } + let(:status) { 200 } + + before do + stub_binance_sign_request(:get, path, status, body) + end + + it 'should return flexible Loan LTV Adjustment History' do + spot_client_signed.get_flexible_loan_ltv_adjustment_history + expect(send_a_request_with_signature(:get, path)).to have_been_made + end +end diff --git a/spec/binance/spot/loan/get_flexible_loan_ongoing_orders.rb b/spec/binance/spot/loan/get_flexible_loan_ongoing_orders.rb new file mode 100644 index 0000000..1dc40e5 --- /dev/null +++ b/spec/binance/spot/loan/get_flexible_loan_ongoing_orders.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Binance::Spot::Convert, '#get_flexible_loan_ongoing_orders' do + let(:path) { '/sapi/v2/loan/flexible/ongoing/orders' } + let(:body) { fixture('response.json') } + let(:status) { 200 } + + before do + stub_binance_sign_request(:get, path, status, body) + end + + it 'should return flexible loan ongoing orders' do + spot_client_signed.get_flexible_loan_ongoing_orders + expect(send_a_request_with_signature(:get, path)).to have_been_made + end +end diff --git a/spec/binance/spot/loan/get_flexible_loan_repayment_history.rb b/spec/binance/spot/loan/get_flexible_loan_repayment_history.rb new file mode 100644 index 0000000..dbd87d9 --- /dev/null +++ b/spec/binance/spot/loan/get_flexible_loan_repayment_history.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Binance::Spot::Convert, '#get_flexible_loan_repayment_history' do + let(:path) { '/sapi/v2/loan/flexible/repay/history' } + let(:body) { fixture('response.json') } + let(:status) { 200 } + + before do + stub_binance_sign_request(:get, path, status, body) + end + + it 'should return flexible loan repayment history' do + spot_client_signed.get_flexible_loan_repayment_history + expect(send_a_request_with_signature(:get, path)).to have_been_made + end +end diff --git a/spec/binance/spot/loan/get_loan_borrow_history.rb b/spec/binance/spot/loan/get_loan_borrow_history.rb new file mode 100644 index 0000000..50b06f4 --- /dev/null +++ b/spec/binance/spot/loan/get_loan_borrow_history.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Binance::Spot::Convert, '#get_loan_borrow_history' do + let(:path) { '/sapi/v1/loan/borrow/history' } + let(:body) { fixture('response.json') } + let(:status) { 200 } + + before do + stub_binance_sign_request(:get, path, status, body) + end + + it 'should return loan borrow history' do + spot_client_signed.get_loan_borrow_history + expect(send_a_request_with_signature(:get, path)).to have_been_made + end +end diff --git a/spec/binance/spot/loan/get_loan_history.rb b/spec/binance/spot/loan/get_loan_history.rb new file mode 100644 index 0000000..f9e831a --- /dev/null +++ b/spec/binance/spot/loan/get_loan_history.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Binance::Spot::Convert, '#get_loan_history' do + let(:path) { '/sapi/v1/loan/income' } + let(:body) { fixture('response.json') } + let(:status) { 200 } + + before do + stub_binance_sign_request(:get, path, status, body) + end + + it 'should accept the offered quote by quote ID' do + spot_client_signed.get_loan_history + expect(send_a_request_with_signature(:get, path)).to have_been_made + end +end diff --git a/spec/binance/spot/loan/get_loan_ltv_adjustment_history.rb b/spec/binance/spot/loan/get_loan_ltv_adjustment_history.rb new file mode 100644 index 0000000..d643ff3 --- /dev/null +++ b/spec/binance/spot/loan/get_loan_ltv_adjustment_history.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Binance::Spot::Convert, '#get_loan_ltv_adjustment_history' do + let(:path) { '/sapi/v1/loan/ltv/adjustment/history' } + let(:body) { fixture('response.json') } + let(:status) { 200 } + + before do + stub_binance_sign_request(:get, path, status, body) + end + + it 'should return loan LTV adjustment history' do + spot_client_signed.get_loan_ltv_adjustment_history + expect(send_a_request_with_signature(:get, path)).to have_been_made + end +end diff --git a/spec/binance/spot/loan/get_loan_repayment_history.rb b/spec/binance/spot/loan/get_loan_repayment_history.rb new file mode 100644 index 0000000..7b9fa81 --- /dev/null +++ b/spec/binance/spot/loan/get_loan_repayment_history.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Binance::Spot::Convert, '#get_loan_repayment_history' do + let(:path) { '/sapi/v1/loan/repay/history' } + let(:body) { fixture('response.json') } + let(:status) { 200 } + + before do + stub_binance_sign_request(:get, path, status, body) + end + + it 'should return loan repayment history' do + spot_client_signed.get_loan_repayment_history + expect(send_a_request_with_signature(:get, path)).to have_been_made + end +end diff --git a/spec/binance/spot/loan/repay_flexible_loan.rb b/spec/binance/spot/loan/repay_flexible_loan.rb new file mode 100644 index 0000000..87687f5 --- /dev/null +++ b/spec/binance/spot/loan/repay_flexible_loan.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Binance::Spot::Convert, '#repay_flexible_loan' do + let(:path) { '/sapi/v2/loan/flexible/repay' } + let(:body) { fixture('response.json') } + let(:status) { 200 } + + before do + mocking_signature_and_ts(**params) + stub_binance_sign_request(:post, path, status, body, params) + end + + context 'validation' do + where(:params) do + [ + { loanCoin: '', collateralCoin: 'BNB', repayAmount: 1.0 }, + { loanCoin: 'BUSD', collateralCoin: '', repayAmount: 1.0 }, + { loanCoin: '', collateralCoin: 'BNB', repayAmount: '' } + ] + end + with_them do + it 'should raise validation error without mandatory params' do + expect { spot_client_signed.repay_flexible_loan(**params) }.to raise_error(Binance::RequiredParameterError) + end + end + end + + context 'with params' do + let(:params) { { loanCoin: 'BUSD', collateralCoin: 'BNB', repayAmount: 1.0 } } + it 'should return flexible loan repay' do + spot_client_signed.repay_flexible_loan(**params) + expect(send_a_request_with_signature(:post, path, params)).to have_been_made + end + end +end diff --git a/spec/binance/spot/margin/margin_available_inventory.rb b/spec/binance/spot/margin/margin_available_inventory.rb new file mode 100644 index 0000000..71fba91 --- /dev/null +++ b/spec/binance/spot/margin/margin_available_inventory.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Binance::Spot::Convert, '#margin_available_inventory' do + let(:path) { '/sapi/v1/margin/available-inventory' } + let(:body) { fixture('response.json') } + let(:status) { 200 } + + before do + mocking_signature_and_ts(**params) + stub_binance_sign_request(:get, path, status, body, params) + end + + context 'validation' do + where(:params) do + [ + { type: '' } + ] + end + with_them do + it 'should raise validation error without mandatory params' do + expect { spot_client_signed.margin_available_inventory(**params) }.to raise_error(Binance::RequiredParameterError) + end + end + end + + context 'with params' do + let(:params) { { type: 'MARGIN' } } + it 'should return margin available Inventory' do + spot_client_signed.margin_available_inventory(**params) + expect(send_a_request_with_signature(:get, path, params)).to have_been_made + end + end +end diff --git a/spec/binance/spot/margin/margin_borrow_repay.rb b/spec/binance/spot/margin/margin_borrow_repay.rb new file mode 100644 index 0000000..4b9be37 --- /dev/null +++ b/spec/binance/spot/margin/margin_borrow_repay.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Binance::Spot::Convert, '#margin_borrow_repay' do + let(:path) { '/sapi/v1/margin/borrow-repay' } + let(:body) { fixture('response.json') } + let(:status) { 200 } + + before do + mocking_signature_and_ts(**params) + stub_binance_sign_request(:post, path, status, body, params) + end + + context 'validation' do + where(:params) do + [ + { asset: '', isIsolated: 'TRUE', symbol: 'BNBUSDT', amount: '1.0', type: 'BORROW' }, + { asset: 'BNB', isIsolated: '', symbol: 'BNBUSDT', amount: '1.0', type: 'BORROW' }, + { asset: 'BNB', isIsolated: 'TRUE', symbol: '', amount: '1.0', type: 'BORROW' }, + { asset: 'BNB', isIsolated: 'TRUE', symbol: 'BNBUSDT', amount: '', type: 'BORROW' }, + { asset: 'BNB', isIsolated: 'TRUE', symbol: 'BNBUSDT', amount: '1.0', type: '' } + ] + end + with_them do + it 'should raise validation error without mandatory params' do + expect { spot_client_signed.margin_borrow_repay(**params) }.to raise_error(Binance::RequiredParameterError) + end + end + end + + context 'with params' do + let(:params) { { asset: 'BNB', isIsolated: 'TRUE', symbol: 'BNBUSDT', amount: '1.0', type: 'BORROW' } } + it 'should return borrow/repay records in Margin account' do + spot_client_signed.margin_borrow_repay(**params) + expect(send_a_request_with_signature(:post, path, params)).to have_been_made + end + end +end diff --git a/spec/binance/spot/margin/margin_borrow_repay_record.rb b/spec/binance/spot/margin/margin_borrow_repay_record.rb new file mode 100644 index 0000000..d5bb7c0 --- /dev/null +++ b/spec/binance/spot/margin/margin_borrow_repay_record.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Binance::Spot::Convert, '#margin_borrow_repay_record' do + let(:path) { '/sapi/v1/margin/borrow-repay' } + let(:body) { fixture('response.json') } + let(:status) { 200 } + + before do + mocking_signature_and_ts(**params) + stub_binance_sign_request(:get, path, status, body, params) + end + + context 'validation' do + where(:params) do + [ + { type: '' } + ] + end + with_them do + it 'should raise validation error without mandatory params' do + expect { spot_client_signed.margin_borrow_repay_record(**params) }.to raise_error(Binance::RequiredParameterError) + end + end + end + + context 'with params' do + let(:params) { { type: 'BORROW' } } + it 'should accept the offered quote by quote ID' do + spot_client_signed.margin_borrow_repay_record(**params) + expect(send_a_request_with_signature(:get, path, params)).to have_been_made + end + end +end diff --git a/spec/binance/spot/margin/margin_leverage_bracket.rb b/spec/binance/spot/margin/margin_leverage_bracket.rb new file mode 100644 index 0000000..dc199a1 --- /dev/null +++ b/spec/binance/spot/margin/margin_leverage_bracket.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Binance::Spot::Convert, '#margin_leverage_bracket' do + let(:path) { '/sapi/v1/margin/leverageBracket' } + let(:body) { fixture('response.json') } + let(:status) { 200 } + + before do + stub_binance_sign_request(:get, path, status, body) + end + + it 'should return liability coin leverage bracket in Cross Margin Pro Mode' do + spot_client_signed.margin_leverage_bracket + expect(send_a_request_with_signature(:get, path)).to have_been_made + end +end diff --git a/spec/binance/spot/margin/margin_manual_liquidation.rb b/spec/binance/spot/margin/margin_manual_liquidation.rb new file mode 100644 index 0000000..bf3482d --- /dev/null +++ b/spec/binance/spot/margin/margin_manual_liquidation.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Binance::Spot::Convert, '#margin_manual_liquidation' do + let(:path) { '/sapi/v1/margin/manual-liquidation' } + let(:body) { fixture('response.json') } + let(:status) { 200 } + + before do + mocking_signature_and_ts(**params) + stub_binance_sign_request(:post, path, status, body, params) + end + + context 'validation' do + where(:params) do + [ + { type: '' } + ] + end + with_them do + it 'should raise validation error without mandatory params' do + expect { spot_client_signed.margin_manual_liquidation(**params) }.to raise_error(Binance::RequiredParameterError) + end + end + end + + context 'with params' do + let(:params) { { type: 'MARGIN' } } + it 'should return Margin manual liquidation' do + spot_client_signed.margin_manual_liquidation(**params) + expect(send_a_request_with_signature(:post, path, params)).to have_been_made + end + end +end diff --git a/spec/binance/spot/market/ticker_trading_day.rb b/spec/binance/spot/market/ticker_trading_day.rb new file mode 100644 index 0000000..4fa6e6e --- /dev/null +++ b/spec/binance/spot/market/ticker_trading_day.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Binance::Spot::Convert, '#ticker_trading_day' do + let(:path) { '/api/v3/ticker/tradingDay' } + let(:body) { fixture('response.json') } + let(:status) { 200 } + + before do + mocking_signature_and_ts(**params) + stub_binance_sign_request(:get, path, status, body, params) + end + + context 'validation' do + where(:params) do + [ + { symbol: '', symbols: '' } + ] + end + with_them do + it 'should raise validation error without mandatory params' do + expect { spot_client_signed.ticker_trading_day(**params) }.to raise_error(Binance::RequiredParameterError) + end + end + end + + context 'with params' do + let(:params) { { symbol: 'BNBUSTD' } } + it 'should return price change statistics for a trading day' do + spot_client_signed.ticker_trading_day(**params) + expect(send_a_request_with_signature(:get, path, params)).to have_been_made + end + end +end diff --git a/spec/binance/spot/market/ui_klines.rb b/spec/binance/spot/market/ui_klines.rb new file mode 100644 index 0000000..d83a653 --- /dev/null +++ b/spec/binance/spot/market/ui_klines.rb @@ -0,0 +1,46 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Binance::Spot::Market, '#ui_klines' do + let(:symbol) { 'BNBUSDT' } + let(:interval) { '1m' } + let(:path) { "/api/v3/uiKlines?symbol=#{symbol}&interval=#{interval}" } + let(:body) { fixture('response.json') } + let(:status) { 200 } + + before do + stub_binance_request(:get, path, status, body) + end + + context 'validation' do + it 'should raise validation error without symbol' do + expect { spot_client.ui_klines(symbol: '', interval: interval) }.to raise_error(Binance::RequiredParameterError) + end + + it 'should raise validation error without interval' do + expect { spot_client.ui_klines(symbol: symbol, interval: '') }.to raise_error(Binance::RequiredParameterError) + end + end + + it 'should return ui_klines' do + spot_client.ui_klines(symbol: symbol, interval: interval) + expect(send_a_request(:get, path)).to have_been_made + end + + describe 'with params' do + let(:params) do + { symbol: symbol, + interval: interval, + startTime: '1589507863477', + endTime: '1589507863477', + limit: 500 } + end + let(:path) { "/api/v3/uiKlines?#{Binance::Utils::Url.build_query(**params)}" } + + it 'should return ui_klines' do + spot_client.ui_klines(**params) + expect(send_a_request(:get, path)).to have_been_made + end + end +end diff --git a/spec/binance/spot/simple_earn/locked_redeem_option.rb b/spec/binance/spot/simple_earn/locked_redeem_option.rb new file mode 100644 index 0000000..5c7f4b7 --- /dev/null +++ b/spec/binance/spot/simple_earn/locked_redeem_option.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Binance::Spot::Convert, '#locked_redeem_option' do + let(:path) { '/sapi/v1/simple-earn/locked/setRedeemOption' } + let(:body) { fixture('response.json') } + let(:status) { 200 } + + before do + mocking_signature_and_ts(**params) + stub_binance_sign_request(:post, path, status, body, params) + end + + context 'validation' do + where(:params) do + [ + { positionId: '', redeemTo: 'SPOT' }, + { positionId: '1234', redeemTo: '' } + ] + end + with_them do + it 'should raise validation error without mandatory params' do + expect { spot_client_signed.locked_redeem_option(**params) }.to raise_error(Binance::RequiredParameterError) + end + end + end + + context 'with params' do + let(:params) { { positionId: '1234', redeemTo: 'SPOT' } } + it 'should set redeem option for Locked product' do + spot_client_signed.locked_redeem_option(**params) + expect(send_a_request_with_signature(:post, path, params)).to have_been_made + end + end +end diff --git a/spec/binance/spot/subaccount/get_sub_account_assets_v4.rb b/spec/binance/spot/subaccount/get_sub_account_assets_v4.rb new file mode 100644 index 0000000..06b4a24 --- /dev/null +++ b/spec/binance/spot/subaccount/get_sub_account_assets_v4.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Binance::Spot::Convert, '#get_sub_account_assets_v4' do + let(:path) { '/sapi/v4/sub-account/assets' } + let(:body) { fixture('response.json') } + let(:status) { 200 } + + before do + mocking_signature_and_ts(**params) + stub_binance_sign_request(:get, path, status, body, params) + end + + context 'validation' do + where(:params) do + [ + { email: '' } + ] + end + with_them do + it 'should raise validation error without mandatory params' do + expect { spot_client_signed.get_sub_account_assets_v4(**params) }.to raise_error(Binance::RequiredParameterError) + end + end + end + + context 'with params' do + let(:params) { { email: 'test@test.com' } } + it 'should return sub-account assets' do + spot_client_signed.get_sub_account_assets_v4(**params) + expect(send_a_request_with_signature(:get, path, params)).to have_been_made + end + end +end diff --git a/spec/binance/spot/subaccount/sub_account_enable_options.rb b/spec/binance/spot/subaccount/sub_account_enable_options.rb new file mode 100644 index 0000000..007c5f8 --- /dev/null +++ b/spec/binance/spot/subaccount/sub_account_enable_options.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Binance::Spot::Convert, '#sub_account_enable_options' do + let(:path) { '/sapi/v1/sub-account/eoptions/enable' } + let(:body) { fixture('response.json') } + let(:status) { 200 } + + before do + mocking_signature_and_ts(**params) + stub_binance_sign_request(:post, path, status, body, params) + end + + context 'validation' do + where(:params) do + [ + { email: '' } + ] + end + with_them do + it 'should raise validation error without mandatory params' do + expect { spot_client_signed.sub_account_enable_options(**params) }.to raise_error(Binance::RequiredParameterError) + end + end + end + + context 'with params' do + let(:params) { { email: 'test@test.com' } } + it 'should enable options for Sub-account' do + spot_client_signed.sub_account_enable_options(**params) + expect(send_a_request_with_signature(:post, path, params)).to have_been_made + end + end +end diff --git a/spec/binance/spot/subaccount/sub_account_futures_asset_details.rb b/spec/binance/spot/subaccount/sub_account_futures_asset_details.rb new file mode 100644 index 0000000..653b782 --- /dev/null +++ b/spec/binance/spot/subaccount/sub_account_futures_asset_details.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Binance::Spot::Convert, '#sub_account_futures_asset_details' do + let(:path) { '/sapi/v1/managed-subaccount/fetch-future-asset' } + let(:body) { fixture('response.json') } + let(:status) { 200 } + + before do + mocking_signature_and_ts(**params) + stub_binance_sign_request(:get, path, status, body, params) + end + + context 'validation' do + where(:params) do + [ + { email: '' } + ] + end + with_them do + it 'should raise validation error without mandatory params' do + expect { spot_client_signed.sub_account_futures_asset_details(**params) }.to raise_error(Binance::RequiredParameterError) + end + end + end + + context 'with params' do + let(:params) { { email: 'test@test.com' } } + it 'should return managed sub account futures asset details' do + spot_client_signed.sub_account_futures_asset_details(**params) + expect(send_a_request_with_signature(:get, path, params)).to have_been_made + end + end +end diff --git a/spec/binance/spot/subaccount/sub_account_list.rb b/spec/binance/spot/subaccount/sub_account_list.rb new file mode 100644 index 0000000..bdd80e1 --- /dev/null +++ b/spec/binance/spot/subaccount/sub_account_list.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Binance::Spot::Convert, '#sub_account_list' do + let(:path) { '/sapi/v1/managed-subaccount/info' } + let(:body) { fixture('response.json') } + let(:status) { 200 } + + before do + stub_binance_sign_request(:get, path, status, body) + end + + it 'should return investors managed sub-account list' do + spot_client_signed.sub_account_list + expect(send_a_request_with_signature(:get, path)).to have_been_made + end +end diff --git a/spec/binance/spot/subaccount/sub_account_margin_asset_details.rb b/spec/binance/spot/subaccount/sub_account_margin_asset_details.rb new file mode 100644 index 0000000..1a18293 --- /dev/null +++ b/spec/binance/spot/subaccount/sub_account_margin_asset_details.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Binance::Spot::Convert, '#sub_account_margin_asset_details' do + let(:path) { '/sapi/v1/managed-subaccount/marginAsset' } + let(:body) { fixture('response.json') } + let(:status) { 200 } + + before do + mocking_signature_and_ts(**params) + stub_binance_sign_request(:get, path, status, body, params) + end + + context 'validation' do + where(:params) do + [ + { email: '' } + ] + end + with_them do + it 'should raise validation error without mandatory params' do + expect { spot_client_signed.sub_account_margin_asset_details(**params) }.to raise_error(Binance::RequiredParameterError) + end + end + end + + context 'with params' do + let(:params) { { email: 'test@test.com' } } + it 'should return managed sub account margin asset details' do + spot_client_signed.sub_account_margin_asset_details(**params) + expect(send_a_request_with_signature(:get, path, params)).to have_been_made + end + end +end diff --git a/spec/binance/spot/subaccount/sub_account_transaction_statistics.rb b/spec/binance/spot/subaccount/sub_account_transaction_statistics.rb new file mode 100644 index 0000000..5277321 --- /dev/null +++ b/spec/binance/spot/subaccount/sub_account_transaction_statistics.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Binance::Spot::Convert, '#sub_account_transaction_statistics' do + let(:path) { '/sapi/v1/sub-account/transaction-statistics' } + let(:body) { fixture('response.json') } + let(:status) { 200 } + + before do + mocking_signature_and_ts(**params) + stub_binance_sign_request(:get, path, status, body, params) + end + + context 'validation' do + where(:params) do + [ + { email: '' } + ] + end + with_them do + it 'should raise validation error without mandatory params' do + expect { spot_client_signed.sub_account_transaction_statistics(**params) }.to raise_error(Binance::RequiredParameterError) + end + end + end + + context 'with params' do + let(:params) { { email: 'test@test.com' } } + it 'should return Sub-account transaction statistics' do + spot_client_signed.sub_account_transaction_statistics(**params) + expect(send_a_request_with_signature(:get, path, params)).to have_been_made + end + end +end diff --git a/spec/binance/spot/subaccount/sub_account_transfer_log.rb b/spec/binance/spot/subaccount/sub_account_transfer_log.rb new file mode 100644 index 0000000..2db1063 --- /dev/null +++ b/spec/binance/spot/subaccount/sub_account_transfer_log.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Binance::Spot::Convert, '#sub_account_transfer_log' do + let(:path) { '/sapi/v1/managed-subaccount/queryTransLogForTradeParent' } + let(:body) { fixture('response.json') } + let(:status) { 200 } + + before do + mocking_signature_and_ts(**params) + stub_binance_sign_request(:get, path, status, body, params) + end + + context 'validation' do + where(:params) do + [ + { email: '', startTime: 1_640_998_861_000, endTime: 1_646_096_461_000, page: 1, limit: 10 }, + { email: 'test@test.com', startTime: '', endTime: 1_646_096_461_000, page: 1, limit: 10 }, + { email: 'test@test.com', startTime: 1_640_998_861_000, endTime: '', page: 1, limit: 10 }, + { email: 'test@test.com', startTime: 1_640_998_861_000, endTime: 1_646_096_461_000, page: '', limit: 10 }, + { email: 'test@test.com', startTime: 1_640_998_861_000, endTime: 1_646_096_461_000, page: 1, limit: '' } + ] + end + with_them do + it 'should raise validation error without mandatory params' do + expect { spot_client_signed.sub_account_transfer_log(**params) }.to raise_error(Binance::RequiredParameterError) + end + end + end + + context 'with params' do + let(:params) { { email: 'test@test.com', startTime: 1_640_998_861_000, endTime: 1_646_096_461_000, page: 1, limit: 10 } } + it 'should return managed sub account transfer log' do + spot_client_signed.sub_account_transfer_log(**params) + expect(send_a_request_with_signature(:get, path, params)).to have_been_made + end + end +end diff --git a/spec/binance/spot/subaccount/sub_account_transfer_log_investor.rb b/spec/binance/spot/subaccount/sub_account_transfer_log_investor.rb new file mode 100644 index 0000000..e529b99 --- /dev/null +++ b/spec/binance/spot/subaccount/sub_account_transfer_log_investor.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Binance::Spot::Convert, '#sub_account_transfer_log_investor' do + let(:path) { '/sapi/v1/managed-subaccount/queryTransLogForInvestor' } + let(:body) { fixture('response.json') } + let(:status) { 200 } + + before do + mocking_signature_and_ts(**params) + stub_binance_sign_request(:get, path, status, body, params) + end + + context 'validation' do + where(:params) do + [ + { email: '', startTime: 1_640_998_861_000, endTime: 1_646_096_461_000, page: 1, limit: 10 }, + { email: 'test@test.com', startTime: '', endTime: 1_646_096_461_000, page: 1, limit: 10 }, + { email: 'test@test.com', startTime: 1_640_998_861_000, endTime: '', page: 1, limit: 10 }, + { email: 'test@test.com', startTime: 1_640_998_861_000, endTime: 1_646_096_461_000, page: '', limit: 10 }, + { email: 'test@test.com', startTime: 1_640_998_861_000, endTime: 1_646_096_461_000, page: 1, limit: '' } + ] + end + with_them do + it 'should raise validation error without mandatory params' do + expect { spot_client_signed.sub_account_transfer_log_investor(**params) }.to raise_error(Binance::RequiredParameterError) + end + end + end + + context 'with params' do + let(:params) { { email: 'test@test.com', startTime: 1_640_998_861_000, endTime: 1_646_096_461_000, page: 1, limit: 10 } } + it 'should return managed sub account transfer log for investor master account' do + spot_client_signed.sub_account_transfer_log_investor(**params) + expect(send_a_request_with_signature(:get, path, params)).to have_been_made + end + end +end diff --git a/spec/binance/spot/subaccount/sub_account_transfer_log_sub_account.rb b/spec/binance/spot/subaccount/sub_account_transfer_log_sub_account.rb new file mode 100644 index 0000000..1bce855 --- /dev/null +++ b/spec/binance/spot/subaccount/sub_account_transfer_log_sub_account.rb @@ -0,0 +1,38 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Binance::Spot::Convert, '#sub_account_transfer_log_sub_account' do + let(:path) { '/sapi/v1/managed-subaccount/query-trans-log' } + let(:body) { fixture('response.json') } + let(:status) { 200 } + + before do + mocking_signature_and_ts(**params) + stub_binance_sign_request(:get, path, status, body, params) + end + + context 'validation' do + where(:params) do + [ + { startTime: '', endTime: 1_646_096_461_000, page: 1, limit: 10 }, + { startTime: 1_640_998_861_000, endTime: '', page: 1, limit: 10 }, + { startTime: 1_640_998_861_000, endTime: 1_646_096_461_000, page: '', limit: 10 }, + { startTime: 1_640_998_861_000, endTime: 1_646_096_461_000, page: 1, limit: '' } + ] + end + with_them do + it 'should raise validation error without mandatory params' do + expect { spot_client_signed.sub_account_transfer_log_sub_account(**params) }.to raise_error(Binance::RequiredParameterError) + end + end + end + + context 'with params' do + let(:params) { { startTime: 1_640_998_861_000, endTime: 1_646_096_461_000, page: 1, limit: 10 } } + it 'should return managed sub account transfer log for trading team sub account' do + spot_client_signed.sub_account_transfer_log_sub_account(**params) + expect(send_a_request_with_signature(:get, path, params)).to have_been_made + end + end +end diff --git a/spec/binance/spot/trade/commission_rate.rb b/spec/binance/spot/trade/commission_rate.rb new file mode 100644 index 0000000..23be522 --- /dev/null +++ b/spec/binance/spot/trade/commission_rate.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Binance::Spot::Convert, '#commission_rate' do + let(:path) { '/api/v3/account/commission' } + let(:body) { fixture('response.json') } + let(:status) { 200 } + + before do + mocking_signature_and_ts(**params) + stub_binance_sign_request(:get, path, status, body, params) + end + + context 'validation' do + where(:params) do + [ + { symbol: '' } + ] + end + with_them do + it 'should raise validation error without mandatory params' do + expect { spot_client_signed.commission_rate(**params) }.to raise_error(Binance::RequiredParameterError) + end + end + end + + context 'with params' do + let(:params) { { symbol: 'BNBUSDT' } } + it 'should return current account commission rates' do + spot_client_signed.commission_rate(**params) + expect(send_a_request_with_signature(:get, path, params)).to have_been_made + end + end +end diff --git a/spec/binance/spot/trade/my_allocations.rb b/spec/binance/spot/trade/my_allocations.rb new file mode 100644 index 0000000..edc0043 --- /dev/null +++ b/spec/binance/spot/trade/my_allocations.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Binance::Spot::Convert, '#my_allocations' do + let(:path) { '/api/v3/myAllocations' } + let(:body) { fixture('response.json') } + let(:status) { 200 } + + before do + mocking_signature_and_ts(**params) + stub_binance_sign_request(:get, path, status, body, params) + end + + context 'validation' do + where(:params) do + [ + { symbol: '' } + ] + end + with_them do + it 'should raise validation error without mandatory params' do + expect { spot_client_signed.my_allocations(**params) }.to raise_error(Binance::RequiredParameterError) + end + end + end + + context 'with params' do + let(:params) { { symbol: 'BNBUSDT' } } + it 'should return allocations resulting from SOR order placement' do + spot_client_signed.my_allocations(**params) + expect(send_a_request_with_signature(:get, path, params)).to have_been_made + end + end +end diff --git a/spec/binance/spot/trade/my_prevented_matches.rb b/spec/binance/spot/trade/my_prevented_matches.rb new file mode 100644 index 0000000..e73b5f7 --- /dev/null +++ b/spec/binance/spot/trade/my_prevented_matches.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Binance::Spot::Convert, '#my_prevented_matches' do + let(:path) { '/api/v3/myPreventedMatches' } + let(:body) { fixture('response.json') } + let(:status) { 200 } + + before do + mocking_signature_and_ts(**params) + stub_binance_sign_request(:get, path, status, body, params) + end + + context 'validation' do + where(:params) do + [ + { symbol: '' } + ] + end + with_them do + it 'should raise validation error without mandatory params' do + expect { spot_client_signed.my_prevented_matches(**params) }.to raise_error(Binance::RequiredParameterError) + end + end + end + + context 'with params' do + let(:params) { { symbol: 'BNBUSDT' } } + it 'should displays the list of orders that were expired due to STP' do + spot_client_signed.my_prevented_matches(**params) + expect(send_a_request_with_signature(:get, path, params)).to have_been_made + end + end +end diff --git a/spec/binance/spot/trade/new_oco_order_spec.rb b/spec/binance/spot/trade/new_oco_order_spec.rb index 4f4be43..d599a23 100644 --- a/spec/binance/spot/trade/new_oco_order_spec.rb +++ b/spec/binance/spot/trade/new_oco_order_spec.rb @@ -11,8 +11,8 @@ symbol: 'BNBUSDT', side: 'BUY', quantity: 10, - price: 20, - stopPrice: 30 + aboveType: 'LIMIT_MAKER', + belowType: 'LIMIT_MAKER' } end @@ -24,11 +24,11 @@ context 'validation' do where(:params) do [ - { symbol: '', side: 'BUY', quantity: 10, price: 20, stopPrice: 30 }, - { symbol: 'BNBUSDT', side: '', quantity: 10, price: 20, stopPrice: 30 }, - { symbol: 'BNBUSDT', side: 'BUY', quantity: '', price: 20, stopPrice: 30 }, - { symbol: 'BNBUSDT', side: 'BUY', quantity: 10, price: '', stopPrice: 30 }, - { symbol: 'BNBUSDT', side: 'BUY', quantity: 10, price: 20, stopPrice: '' } + { symbol: '', side: 'BUY', quantity: 10, aboveType: 'LIMIT_MAKER', belowType: 'LIMIT_MAKER' }, + { symbol: 'BNBUSDT', side: '', quantity: 10, aboveType: 'LIMIT_MAKER', belowType: 'LIMIT_MAKER' }, + { symbol: 'BNBUSDT', side: 'BUY', quantity: '', aboveType: 'LIMIT_MAKER', belowType: 'LIMIT_MAKER' }, + { symbol: 'BNBUSDT', side: 'BUY', quantity: 10, aboveType: '', belowType: 'LIMIT_MAKER' }, + { symbol: 'BNBUSDT', side: 'BUY', quantity: 10, aboveType: 'LIMIT_MAKER', belowType: '' } ] end with_them do @@ -51,15 +51,10 @@ price: '1000', side: 'BUY', quantity: 1, - stopPrice: 30, - listClientOrderId: 'aaa', - limitClientOrderId: 'bbbb', - limitIcebergQty: 2, - stopClientOrderId: 'ccc', - stopLimitPrice: 35, - stopIcebergQty: 3, - stopLimitTimeInForce: 'GTC', - newOrderRespType: 'RESULT', + aboveType: 'LIMIT_MAKER', + belowType: 'LIMIT_MAKER', + abovePrice: 600, + belowPrice: 590, recvWindow: 50_000 } end diff --git a/spec/binance/spot/wallet/account_info.rb b/spec/binance/spot/wallet/account_info.rb new file mode 100644 index 0000000..e842990 --- /dev/null +++ b/spec/binance/spot/wallet/account_info.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Binance::Spot::Convert, '#account_info' do + let(:path) { '/sapi/v1/account/info' } + let(:body) { fixture('response.json') } + let(:status) { 200 } + + before do + stub_binance_sign_request(:get, path, status, body) + end + + it 'should return account info detail' do + spot_client_signed.account_info + expect(send_a_request_with_signature(:get, path)).to have_been_made + end +end diff --git a/spec/binance/spot/wallet/cloud_mining_payment_and_refund_history.rb b/spec/binance/spot/wallet/cloud_mining_payment_and_refund_history.rb new file mode 100644 index 0000000..5921285 --- /dev/null +++ b/spec/binance/spot/wallet/cloud_mining_payment_and_refund_history.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Binance::Spot::Convert, '#cloud_mining_payment_and_refund_history' do + let(:path) { '/sapi/v1/asset/ledger-transfer/cloud-mining/queryByPage' } + let(:body) { fixture('response.json') } + let(:status) { 200 } + + before do + stub_binance_sign_request(:get, path, status, body) + end + + it 'should return Cloud-Mining payment and refund history' do + spot_client_signed.cloud_mining_payment_and_refund_history + expect(send_a_request_with_signature(:get, path)).to have_been_made + end +end diff --git a/spec/binance/spot/wallet/delist_schedule.rb b/spec/binance/spot/wallet/delist_schedule.rb new file mode 100644 index 0000000..1bfd9f5 --- /dev/null +++ b/spec/binance/spot/wallet/delist_schedule.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Binance::Spot::Convert, '#delist_schedule' do + let(:path) { '/sapi/v1/spot/delist-schedule' } + let(:body) { fixture('response.json') } + let(:status) { 200 } + + before do + stub_binance_sign_request(:get, path, status, body) + end + + it 'should return symbols delist schedule for spot' do + spot_client_signed.delist_schedule + expect(send_a_request_with_signature(:get, path)).to have_been_made + end +end diff --git a/spec/binance/spot/wallet/deposit_address_list.rb b/spec/binance/spot/wallet/deposit_address_list.rb new file mode 100644 index 0000000..70b3010 --- /dev/null +++ b/spec/binance/spot/wallet/deposit_address_list.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Binance::Spot::Convert, '#deposit_address_list' do + let(:path) { '/sapi/v1/capital/deposit/address/list' } + let(:body) { fixture('response.json') } + let(:status) { 200 } + + before do + mocking_signature_and_ts(**params) + stub_binance_sign_request(:get, path, status, body, params) + end + + context 'validation' do + where(:params) do + [ + { coin: '' } + ] + end + with_them do + it 'should raise validation error without mandatory params' do + expect { spot_client_signed.deposit_address_list(**params) }.to raise_error(Binance::RequiredParameterError) + end + end + end + + context 'with params' do + let(:params) { { coin: 'BNB' } } + it 'should return deposit address list with network' do + spot_client_signed.deposit_address_list(**params) + expect(send_a_request_with_signature(:get, path, params)).to have_been_made + end + end +end diff --git a/spec/binance/spot/wallet/get_assets_converted_into_bnb.rb b/spec/binance/spot/wallet/get_assets_converted_into_bnb.rb new file mode 100644 index 0000000..345cec9 --- /dev/null +++ b/spec/binance/spot/wallet/get_assets_converted_into_bnb.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Binance::Spot::Convert, '#get_assets_converted_into_bnb' do + let(:path) { '/sapi/v1/asset/dust-btc' } + let(:body) { fixture('response.json') } + let(:status) { 200 } + + before do + stub_binance_sign_request(:post, path, status, body) + end + + it 'should return assets that can be converted into BNB' do + spot_client_signed.get_assets_converted_into_bnb + expect(send_a_request_with_signature(:post, path)).to have_been_made + end +end diff --git a/spec/binance/spot/wallet/one_click_arrival_deposit_apply.rb b/spec/binance/spot/wallet/one_click_arrival_deposit_apply.rb new file mode 100644 index 0000000..b94b32e --- /dev/null +++ b/spec/binance/spot/wallet/one_click_arrival_deposit_apply.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Binance::Spot::Convert, '#one_click_arrival_deposit_apply' do + let(:path) { '/sapi/v1/capital/deposit/credit-apply' } + let(:body) { fixture('response.json') } + let(:status) { 200 } + + before do + stub_binance_sign_request(:post, path, status, body) + end + + it 'should apply deposit credit for expired address' do + spot_client_signed.one_click_arrival_deposit_apply + expect(send_a_request_with_signature(:post, path)).to have_been_made + end +end diff --git a/spec/binance/spot/wallet/user_delegation_history.rb b/spec/binance/spot/wallet/user_delegation_history.rb new file mode 100644 index 0000000..704448a --- /dev/null +++ b/spec/binance/spot/wallet/user_delegation_history.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Binance::Spot::Convert, '#user_delegation_history' do + let(:path) { '/sapi/v1/asset/custody/transfer-history' } + let(:body) { fixture('response.json') } + let(:status) { 200 } + + before do + stub_binance_sign_request(:get, path, status, body) + end + + it 'should return user delegation History' do + spot_client_signed.user_delegation_history + expect(send_a_request_with_signature(:get, path)).to have_been_made + end +end diff --git a/spec/binance/spot/wallet/wallet_balance.rb b/spec/binance/spot/wallet/wallet_balance.rb new file mode 100644 index 0000000..ecd239c --- /dev/null +++ b/spec/binance/spot/wallet/wallet_balance.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Binance::Spot::Convert, '#wallet_balance' do + let(:path) { '/sapi/v1/asset/wallet/balance' } + let(:body) { fixture('response.json') } + let(:status) { 200 } + + before do + stub_binance_sign_request(:get, path, status, body) + end + + it 'should return user wallet balance' do + spot_client_signed.wallet_balance + expect(send_a_request_with_signature(:get, path)).to have_been_made + end +end