com.binance.connector.client.impl.spot.Wallet Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of binance-connector-java Show documentation
Show all versions of binance-connector-java Show documentation
lightweight connector to API
package com.binance.connector.client.impl.spot;
import java.util.ArrayList;
import java.util.Map;
import com.binance.connector.client.enums.HttpMethod;
import com.binance.connector.client.utils.ParameterChecker;
import com.binance.connector.client.utils.ProxyAuth;
import com.binance.connector.client.utils.RequestHandler;
import com.binance.connector.client.utils.signaturegenerator.HmacSignatureGenerator;
import com.binance.connector.client.utils.signaturegenerator.SignatureGenerator;
/**
* Wallet Endpoints
* All endpoints under the
* Wallet Endpoint
* section of the API documentation will be implemented in this class.
*
* Response will be returned in String format.
*/
public class Wallet {
private final String baseUrl;
private final RequestHandler requestHandler;
private final boolean showLimitUsage;
public Wallet(String baseUrl, String apiKey, String secretKey, boolean showLimitUsage, ProxyAuth proxy) {
this.baseUrl = baseUrl;
this.requestHandler = new RequestHandler(apiKey, new HmacSignatureGenerator(secretKey), proxy);
this.showLimitUsage = showLimitUsage;
}
public Wallet(String baseUrl, String apiKey, SignatureGenerator signatureGenerator, boolean showLimitUsage, ProxyAuth proxy) {
this.baseUrl = baseUrl;
this.requestHandler = new RequestHandler(apiKey, signatureGenerator, proxy);
this.showLimitUsage = showLimitUsage;
}
private final String SYSTEM_STATUS = "/sapi/v1/system/status";
/**
* Fetch system status.
*
* GET /sapi/v1/system/status
*
* @return String
* @see
* https://developers.binance.com/docs/wallet/others/system-status
*/
public String systemStatus() {
return requestHandler.sendPublicRequest(baseUrl, SYSTEM_STATUS, null, HttpMethod.GET, showLimitUsage);
}
private final String COIN_INFO = "/sapi/v1/capital/config/getall";
/**
* Get information of coins (available for deposit and withdraw) for user.
*
* GET /sapi/v1/capital/config/getall
*
* @param
* parameters Map of String,Object pair
* where String is the name of the parameter and Object is the value of the parameter
*
* recvWindow -- optional/long
* @return String
* @see
* https://developers.binance.com/docs/wallet/capital/all-coins-info
*/
public String coinInfo(Map parameters) {
return requestHandler.sendSignedRequest(baseUrl, COIN_INFO, parameters, HttpMethod.GET, showLimitUsage);
}
private final String ACCOUNT_SNAPSHOT = "/sapi/v1/accountSnapshot";
/**
* - The query time period must be less than 30 days
* - Support query within the last one month only
* - If startTime and endTime are both not sent, records from the last 7 days are returned by default
*
* GET /sapi/v1/accountSnapshot
*
* @param
* parameters Map of String,Object pair
* where String is the name of the parameter and Object is the value of the parameter
*
* type -- mandatory/string -- "SPOT", "MARGIN", "FUTURES"
* startTime -- optional/long
* endTime -- optional/long
* limit -- optional/int -- min 5, max 30, default 5
* recvWindow -- optional/long
* @return String
* @see
* https://developers.binance.com/docs/wallet/account/daily-account-snapshoot
*/
public String accountSnapshot(Map parameters) {
ParameterChecker.checkParameter(parameters, "type", String.class);
return requestHandler.sendSignedRequest(baseUrl, ACCOUNT_SNAPSHOT, parameters, HttpMethod.GET, showLimitUsage);
}
private final String DISABLE_FAST_WITHDRAW = "/sapi/v1/account/disableFastWithdrawSwitch";
/**
* - This request will disable fastwithdraw switch under your account.
* - You need to enable "trade" option for the api key which requests this endpoint.
*
* POST /sapi/v1/account/disableFastWithdrawSwitch
*
* @param
* parameters Map of String,Object pair
* where String is the name of the parameter and Object is the value of the parameter
*
* recvWindow -- optional/long
* @return String
* @see
* https://developers.binance.com/docs/wallet/account/disable-fast-withdraw-switch
*/
public String disableFastWithdraw(Map parameters) {
return requestHandler.sendSignedRequest(baseUrl, DISABLE_FAST_WITHDRAW, parameters, HttpMethod.POST, showLimitUsage);
}
private final String ENABLE_FAST_WITHDRAW = "/sapi/v1/account/enableFastWithdrawSwitch";
/**
* - This request will enable fastwithdraw switch under your account. You need to enable "trade" option for the api key which requests this endpoint.
* - When Fast Withdraw Switch is on, transferring funds to a Binance account will be done instantly. There is no on-chain transaction, no transaction ID and no withdrawal fee.
*
* POST /sapi/v1/account/enableFastWithdrawSwitch
*
* @param
* parameters Map of String,Object pair
* where String is the name of the parameter and Object is the value of the parameter
*
* recvWindow -- optional/long
* @return String
* @see
* https://developers.binance.com/docs/wallet/account/enable-fast-withdraw-switch
*/
public String enableFastWithdraw(Map parameters) {
return requestHandler.sendSignedRequest(baseUrl, ENABLE_FAST_WITHDRAW, parameters, HttpMethod.POST, showLimitUsage);
}
private final String WITHDRAW = "/sapi/v1/capital/withdraw/apply";
/**
* Submit a withdraw request.
*
* - If `network` not send, return with default network of the coin.
* - You can get `network` and `isDefault` in `networkList` of a coin in the response of `Get /sapi/v1/capital/config/getall (HMAC SHA256)`.
*
* POST /sapi/v1/capital/withdraw/apply
*
* @param
* parameters Map of String,Object pair
* where String is the name of the parameter and Object is the value of the parameter
*
* coin -- mandatory/string
* withdrawOrderId -- optional/string -- Client ID for withdraw
* network -- optional/string
* address -- mandatory/string
* addressTag -- optional/string -- Secondary address identifier for coins like XRP,XMR etc.
* amount -- mandatory/decimal
* transactionFeeFlag -- optional/boolean -- When making internal transfer, true for returning the fee to the destination account;
* false for returning the fee back to the departure account. Default false.
* name -- optional/string -- Description of the address. Space in name should be encoded into %20.
* walletType -- optional/int -- The wallet type for withdraw, 0-spot wallet , 1-funding wallet.Default spot wallet
* recvWindow -- optional/long
* @return String
* @see
* https://developers.binance.com/docs/wallet/capital/withdraw
*/
public String withdraw(Map parameters) {
ParameterChecker.checkParameter(parameters, "coin", String.class);
ParameterChecker.checkParameter(parameters, "address", String.class);
ParameterChecker.checkRequiredParameter(parameters, "amount");
return requestHandler.sendSignedRequest(baseUrl, WITHDRAW, parameters, HttpMethod.POST, showLimitUsage);
}
private final String DEPOSIT_HISTORY = "/sapi/v1/capital/deposit/hisrec";
/**
* Fetch deposit history.
*
* - Please notice the default `startTime` and `endTime` to make sure that time interval is within 0-90 days.
* - If both `startTime` and `endTime` are sent, time between `startTime` and `endTime` must be less than 90 days.
*
* GET /sapi/v1/capital/deposit/hisrec
*
* @param
* parameters Map of String,Object pair
* where String is the name of the parameter and Object is the value of the parameter
*
* coin -- optional/string
* status -- optional/int -- 0(0:pending,6: credited but cannot withdraw, 1:success)
* startTime -- optional/long -- Default: 90 days from current timestamp
* endTime -- optional/long -- Default: present timestamp
* offset -- optional/int -- Default:0
* limit -- optional/int -- Default:1000, Max:1000
* recvWindow -- optional/long
* @return String
* @see
* https://developers.binance.com/docs/wallet/capital/deposite-history
*/
public String depositHistory(Map parameters) {
return requestHandler.sendSignedRequest(baseUrl, DEPOSIT_HISTORY, parameters, HttpMethod.GET, showLimitUsage);
}
private final String WITHDRAW_HISTORY = "/sapi/v1/capital/withdraw/history";
/**
* Fetch withdraw history.
*
* This endpoint specifically uses per second UID rate limit, user's total second level IP rate limit is 180000/second. Response from the endpoint contains header key X-SAPI-USED-UID-WEIGHT-1S, which defines weight used by the current IP.
*
* - `network` may not be in the response for old withdraw.
* - Please notice the default `startTime` and `endTime` to make sure that time interval is within 0-90 days.
* - If both `startTime` and `endTime` are sent, time between `startTime` and `endTime` must be less than 90 days
* - If withdrawOrderId is sent, time between startTime and endTime must be less than 7 days.
* - If withdrawOrderId is sent, startTime and endTime are not sent, will return last 7 days records by default.
*
* GET /sapi/v1/capital/withdraw/history
*
* @param
* parameters Map of String,Object pair
* where String is the name of the parameter and Object is the value of the parameter
*
* coin -- optional/string
* withdrawOrderId -- optional/string
* status -- optional/int -- 0(0:Email Sent,1:Cancelled 2:Awaiting Approval 3:Rejected 4:Processing 5:Failure 6:Completed)
* startTime -- optional/long -- Default: 90 days from current timestamp
* endTime -- optional/long -- Default: present timestamp
* offset -- optional/int
* limit -- optional/int -- Default:1000, Max:1000
* recvWindow -- optional/long
* @return String
* @see
* https://developers.binance.com/docs/wallet/capital/withdraw-history
*/
public String withdrawHistory(Map parameters) {
return requestHandler.sendSignedRequest(baseUrl, WITHDRAW_HISTORY, parameters, HttpMethod.GET, showLimitUsage);
}
private final String DEPOSIT_ADDRESS = "/sapi/v1/capital/deposit/address";
/**
* Fetch deposit address with network.
*
* - If network is not send, return with default network of the coin.
* - You can get network and isDefault in networkList in the response of Get /sapi/v1/capital/config/getall.
*
* GET /sapi/v1/capital/deposit/address
*
* @param
* parameters Map of String,Object pair
* where String is the name of the parameter and Object is the value of the parameter
*
* coin -- mandatory/string
* network -- optional/string
* amount -- optional/decimal -- mandatory if using LIGHTNING network
* recvWindow -- optional/long
* @return String
* @see
* https://developers.binance.com/docs/wallet/capital/deposite-address
*/
public String depositAddress(Map parameters) {
ParameterChecker.checkParameter(parameters, "coin", String.class);
return requestHandler.sendSignedRequest(baseUrl, DEPOSIT_ADDRESS, parameters, HttpMethod.GET, showLimitUsage);
}
private final String DEPOSIT_ADDRESSES = "/sapi/v1/capital/deposit/address/list";
/**
* Fetch deposit address list with network.
*
* - If network is not send, return with default network of the coin.
* - You can get network and isDefault in networkList in the response of Get /sapi/v1/capital/config/getall.
*
* GET /sapi/v1/capital/deposit/address/list
*
* @param
* parameters Map of String,Object pair
* where String is the name of the parameter and Object is the value of the parameter
*
* coin -- mandatory/string
* network -- optional/string
* recvWindow -- optional/long -- The value cannot be greater than 60000
* @return String
* @see
* https://developers.binance.com/docs/wallet/capital/fetch-deposit-address-list-with-network
*/
public String depositAddresses(Map parameters) {
ParameterChecker.checkParameter(parameters, "coin", String.class);
return requestHandler.sendSignedRequest(baseUrl, DEPOSIT_ADDRESSES, parameters, HttpMethod.GET, showLimitUsage);
}
private final String ACCOUNT_STATUS = "/sapi/v1/account/status";
/**
* Fetch account status detail.
*
* GET /sapi/v1/account/status
*
* @param
* parameters Map of String,Object pair
* where String is the name of the parameter and Object is the value of the parameter
*
* recvWindow -- optional/long
* @return String
* @see
* https://developers.binance.com/docs/wallet/account/account-status
*/
public String accountStatus(Map parameters) {
return requestHandler.sendSignedRequest(baseUrl, ACCOUNT_STATUS, parameters, HttpMethod.GET, showLimitUsage);
}
private final String API_TRADE_STATUS = "/sapi/v1/account/apiTradingStatus";
/**
* Fetch account API trading status with details.
*
* GET /sapi/v1/account/apiTradingStatus
*
* @param
* parameters Map of String,Object pair
* where String is the name of the parameter and Object is the value of the parameter
*
* recvWindow -- optional/long
* @return String
* @see
* https://developers.binance.com/docs/wallet/account/account-api-trading-status
*/
public String apiTradingStatus(Map parameters) {
return requestHandler.sendSignedRequest(baseUrl, API_TRADE_STATUS, parameters, HttpMethod.GET, showLimitUsage);
}
private final String DUST_LOG = "/sapi/v1/asset/dribblet";
/**
* GET /sapi/v1/asset/dribblet
*
* @param
* parameters Map of String,Object pair
* where String is the name of the parameter and Object is the value of the parameter
*
* startTime -- optional/long
* endTime -- optional/long
* recvWindow -- optional/long
* @return String
* @see
* https://developers.binance.com/docs/wallet/asset/dust-log
*/
public String dustLog(Map parameters) {
return requestHandler.sendSignedRequest(baseUrl, DUST_LOG, parameters, HttpMethod.GET, showLimitUsage);
}
private final String BNB_CONVERTIBLE_ASSETS = "/sapi/v1/asset/dust-btc";
/**
* POST /sapi/v1/asset/dust-btc
*
* @param
* parameters Map of String,Object pair
* where String is the name of the parameter and Object is the value of the parameter
*
* recvWindow -- optional/long
* @return String
* @see
* https://developers.binance.com/docs/wallet/asset/assets-can-convert-bnb
*/
public String bnbConvertableAssets(Map parameters) {
return requestHandler.sendSignedRequest(baseUrl, BNB_CONVERTIBLE_ASSETS, parameters, HttpMethod.POST, showLimitUsage);
}
private final String DUST_TRANSFER = "/sapi/v1/asset/dust";
/**
* Convert dust assets to BNB.
*
* POST /sapi/v1/asset/dust
*
* @param
* parameters Map of String,Object pair
* where String is the name of the parameter and Object is the value of the parameter
*
* asset -- mandatory/array -- The asset being converted. For example: asset=BTC&asset=USDT
* recvWindow -- optional/long
* @return String
* @see
* https://developers.binance.com/docs/wallet/asset/dust-transfer
*/
public String dustTransfer(Map parameters) {
ParameterChecker.checkParameter(parameters, "asset", ArrayList.class);
return requestHandler.sendSignedRequest(baseUrl, DUST_TRANSFER, parameters, HttpMethod.POST, showLimitUsage);
}
private final String ASSET_DIVIDEND = "/sapi/v1/asset/assetDividend";
/**
* Query asset dividend record.
*
* GET /sapi/v1/asset/assetDividend
*
* @param
* parameters Map of String,Object pair
* where String is the name of the parameter and Object is the value of the parameter
*
* asset -- optional/string
* startTime -- optional/long
* endTime -- optional/long
* limit -- optional/int -- Default 20, max 500
* recvWindow -- optional/long
* @return String
* @see
* https://developers.binance.com/docs/wallet/asset/assets-divided-record
*/
public String assetDividend(Map parameters) {
return requestHandler.sendSignedRequest(baseUrl, ASSET_DIVIDEND, parameters, HttpMethod.GET, showLimitUsage);
}
private final String ASSET_DETAIL = "/sapi/v1/asset/assetDetail";
/**
* Fetch details of assets supported on Binance.
*
* - Please get network and other deposit or withdraw details from `GET /sapi/v1/capital/config/getall`.
*
* GET /sapi/v1/asset/assetDetail
*
* @param
* parameters Map of String,Object pair
* where String is the name of the parameter and Object is the value of the parameter
*
* asset -- optional/string
* recvWindow -- optional/long
* @return String
* @see
* https://developers.binance.com/docs/wallet/asset/asset-detail
*/
public String assetDetail(Map parameters) {
return requestHandler.sendSignedRequest(baseUrl, ASSET_DETAIL, parameters, HttpMethod.GET, showLimitUsage);
}
private final String TRADE_FEE = "/sapi/v1/asset/tradeFee";
/**
* Fetch trade fee.
*
* GET /sapi/v1/asset/tradeFee
*
* @param
* parameters Map of String,Object pair
* where String is the name of the parameter and Object is the value of the parameter
*
* symbol -- optional/string
* recvWindow -- optional/long
* @return String
* @see
* https://developers.binance.com/docs/wallet/asset/trade-fee
*/
public String tradeFee(Map parameters) {
return requestHandler.sendSignedRequest(baseUrl, TRADE_FEE, parameters, HttpMethod.GET, showLimitUsage);
}
private final String UNIVERSAL_TRANSFER = "/sapi/v1/asset/transfer";
/**
* You need to enable Permits Universal Transfer option for the api key which requests this endpoint.
*
* POST /sapi/v1/asset/transfer
*
* @param
* parameters Map of String,Object pair
* where String is the name of the parameter and Object is the value of the parameter
*
* type -- mandatory/enum -- Universal transfer type
* asset -- mandatory/string
* amount -- mandatory/decimal
* fromSymbol -- optional/string
* toSymbol -- optional/string
* recvWindow -- optional/long
* @return String
* @see
* https://developers.binance.com/docs/wallet/asset/user-universal-transfer
*/
public String universalTransfer(Map parameters) {
ParameterChecker.checkParameter(parameters, "type", String.class);
ParameterChecker.checkParameter(parameters, "asset", String.class);
ParameterChecker.checkRequiredParameter(parameters, "amount");
return requestHandler.sendSignedRequest(baseUrl, UNIVERSAL_TRANSFER, parameters, HttpMethod.POST, showLimitUsage);
}
/**
* GET /sapi/v1/asset/transfer
*
* @param
* parameters Map of String,Object pair
* where String is the name of the parameter and Object is the value of the parameter
*
* type -- mandatory/enum
* startTime -- optional/long
* endTime -- optional/long
* current -- optional/int -- Default 1
* size -- optional/int -- Default 10, Max 100
* fromSymbol -- optional/string
* toSymbol -- optional/string
* recvWindow -- optional/long
* @return String
* @see
* https://developers.binance.com/docs/wallet/asset/query-user-universal-transfer
*/
public String queryUniversalTransfer(Map parameters) {
ParameterChecker.checkParameter(parameters, "type", String.class);
return requestHandler.sendSignedRequest(baseUrl, UNIVERSAL_TRANSFER, parameters, HttpMethod.GET, showLimitUsage);
}
private final String FUNDING_WALLET = "/sapi/v1/asset/get-funding-asset";
/**
* POST /sapi/v1/asset/get-funding-asset
*
* @param
* parameters Map of String,Object pair
* where String is the name of the parameter and Object is the value of the parameter
*
* asset -- optional/string
* needBtcValuation -- optional/string -- true or false
* recvWindow -- optional/long
* @return String
* @see
* https://developers.binance.com/docs/wallet/asset/funding-wallet
*/
public String fundingWallet(Map parameters) {
return requestHandler.sendSignedRequest(baseUrl, FUNDING_WALLET, parameters, HttpMethod.POST, showLimitUsage);
}
private final String API_PERMISSION = "/sapi/v1/account/apiRestrictions";
/**
* GET /sapi/v1/account/apiRestrictions
*
* @param
* parameters Map of String,Object pair
* where String is the name of the parameter and Object is the value of the parameter
*
* recvWindow -- optional/long
* @return String
* @see
* https://developers.binance.com/docs/wallet/account/api-key-permission
*/
public String apiPermission(Map parameters) {
return requestHandler.sendSignedRequest(baseUrl, API_PERMISSION, parameters, HttpMethod.GET, showLimitUsage);
}
private final String USER_ASSET = "/sapi/v3/asset/getUserAsset";
/**
* Get user assets, just for positive data.
*
* POST /sapi/v3/asset/getUserAsset
*
* @param
* parameters Map of String,Object pair
* where String is the name of the parameter and Object is the value of the parameter
*
* asset -- optional/string -- If asset is blank, then query all positive assets user have.
* needBtcValuation -- optional/boolean -- Whether need btc valuation or not.
* recvWindow -- optional/long
* @return String
* @see
* https://developers.binance.com/docs/wallet/asset/user-assets
*/
public String getUserAsset(Map parameters) {
return requestHandler.sendSignedRequest(baseUrl, USER_ASSET, parameters, HttpMethod.POST, showLimitUsage);
}
private final String CLOUD_MINING_HISTORY = "/sapi/v1/asset/ledger-transfer/cloud-mining/queryByPage";
/**
* The query of Cloud-Mining payment and refund history
*
* GET /sapi/v1/asset/ledger-transfer/cloud-mining/queryByPage
*
* @param
* parameters Map of String,Object pair
* where String is the name of the parameter and Object is the value of the parameter
*
*
* startTime -- mandatory/long -- inclusive, unit: ms
* endTime -- mandatory/long -- exclusive, unit: ms
* tranId -- optional/long -- The transaction id
* clientTranId -- optional/string -- The unique flag
* asset -- optional/string -- If not sent, we will query all assets.
* current -- optional/integer -- current page, default 1, the min value is 1
* size -- optional/integer -- page size, default 10, the max value is 100
* recvWindow -- optional/long
* @return String
* @see
* https://developers.binance.com/docs/wallet/asset/cloud-mining-payment-and-refund-history
*/
public String cloudMiningHistory(Map parameters) {
ParameterChecker.checkParameter(parameters, "startTime", Long.class);
ParameterChecker.checkParameter(parameters, "endTime", Long.class);
return requestHandler.sendSignedRequest(baseUrl, CLOUD_MINING_HISTORY, parameters, HttpMethod.GET, showLimitUsage);
}
private final String APPLY_ONE_CLICK_ARRIVAL_DEPOSIT = "/sapi/v1/capital/deposit/credit-apply";
/**
* Apply deposit credit for expired address (One click arrival)
*
*
* POST /sapi/v1/capital/deposit/credit-apply
*
* @param
* parameters Map of String,Object pair
* where String is the name of the parameter and Object is the value of the parameter
*
* depositId -- optional/long -- Deposit record ID, priority use
* txId -- optional/string -- Deposit txId, used when depositId is not specified
* subAccountId -- optional/long
* subUserId -- optional/long
* recvWindow -- optional/long -- The value cannot be greater than 60000
* @return String
* @see
* https://developers.binance.com/docs/wallet/capital/one-click-arrival-deposite-apply
*/
public String applyOneClickArrivalDeposit(Map parameters) {
return requestHandler.sendSignedRequest(baseUrl, APPLY_ONE_CLICK_ARRIVAL_DEPOSIT, parameters, HttpMethod.POST, showLimitUsage);
}
private final String WALLET_BALANCE = "/sapi/v1/asset/wallet/balance";
/**
* Query User Wallet Balance
*
*
* GET /sapi/v1/asset/wallet/balance
*
* @param
* parameters Map of String,Object pair
* where String is the name of the parameter and Object is the value of the parameter
*
* recvWindow -- optional/long -- The value cannot be greater than 60000
* @return String
* @see
* https://developers.binance.com/docs/wallet/asset/query-user-wallet-balance
*/
public String walletBalance(Map parameters) {
return requestHandler.sendSignedRequest(baseUrl, WALLET_BALANCE, parameters, HttpMethod.GET, showLimitUsage);
}
private final String QUERY_USER_DELEGATION_HISTORY = "/sapi/v1/asset/custody/transfer-history";
/**
* Query User Delegation History
*
* You need to open Enable Spot and Margin Trading permission for the API Key which requests this endpoint
*
*
* GET /sapi/v1/asset/custody/transfer-history
*
* @param
* parameters Map of String,Object pair
* where String is the name of the parameter and Object is the value of the parameter
*
* email -- mandatory/string
* startTime -- mandatory/long
* endTime -- mandatory/long
* type -- optional/enum -- "Delegate" or "Undelegate"
* asset -- optional/string
* current -- optional/integer -- Current querying page. Start from 1. Default:1
* size -- optional/integer -- Default:10 Max:100
* recvWindow -- optional/long -- The value cannot be greater than 60000
* @return String
* @see
* https://developers.binance.com/docs/wallet/asset/query-user-delegation
*/
public String delegationHistory(Map parameters) {
ParameterChecker.checkParameter(parameters, "email", String.class);
ParameterChecker.checkParameter(parameters, "startTime", Long.class);
ParameterChecker.checkParameter(parameters, "endTime", Long.class);
return requestHandler.sendSignedRequest(baseUrl, QUERY_USER_DELEGATION_HISTORY, parameters, HttpMethod.GET, showLimitUsage);
}
}