├── .github └── workflows │ └── connector.yml ├── .gitignore ├── CHANGELOG.md ├── LICENSE.md ├── README.md ├── account.go ├── account_test.go ├── client.go ├── client_test.go ├── consts.go ├── examples ├── account │ ├── CancelOCO │ │ └── CancelOCO.go │ ├── CancelOpenOrders │ │ └── CancelOpenOrders.go │ ├── CancelOrder │ │ └── CancelOrder.go │ ├── CancelReplace │ │ └── CancelReplace.go │ ├── CreateOrder │ │ └── CreateOrder.go │ ├── GetAccount │ │ └── GetAccount.go │ ├── GetAllOrders │ │ └── GetAllOrders.go │ ├── GetMyTrades │ │ └── GetMyTrades.go │ ├── GetOpenOrders │ │ └── GetOpenOrders.go │ ├── GetOrder │ │ └── GetOrder.go │ ├── NewOCO │ │ └── NewOCO.go │ ├── QueryAllOCO │ │ └── QueryAllOCO.go │ ├── QueryCurrentOrderCountUsage │ │ └── QueryCurrentOrderCountUsage.go │ ├── QueryOCO │ │ └── QueryOCO.go │ ├── QueryOpenOCO │ │ └── QueryOpenOCO.go │ ├── QueryPreventedMatches │ │ └── QueryPreventedMatches.go │ └── TestNewOrder │ │ └── TestNewOrder.go ├── fiat │ ├── GetFiatDepositWithdrawHistory │ │ └── GetFiatDepositWithdrawHistory.go │ └── GetFiatPaymentHistory │ │ └── GetFiatPaymentHistory.go ├── margin │ ├── AllIsolatedMarginSymbol │ │ └── AllIsolatedMarginSymbol.go │ ├── CrossMarginAccountDetail │ │ └── CrossMarginAccountDetail.go │ ├── CrossMarginTransferHistory │ │ └── CrossMarginTransferHistory.go │ ├── ForceLiquidationRecord │ │ └── ForceLiquidationRecord.go │ ├── GetAllMarginAssets │ │ └── GetAllMarginAssets.go │ ├── GetAllMarginPairs │ │ └── GetAllMarginPairs.go │ ├── InterestHistory │ │ └── InterestHistory.go │ ├── MarginAccountAdjustCrossMaxLeverage │ │ └── MarginAccountAdjustCrossMaxLeverage.go │ ├── MarginAccountAllOrder │ │ └── MarginAccountAllOrder.go │ ├── MarginAccountCancelAllOrders │ │ └── MarginAccountCancelAllOrders.go │ ├── MarginAccountCancelOCO │ │ └── MarginAccountCancelOCO.go │ ├── MarginAccountCancelOrder │ │ └── MarginAccountCancelOrder.go │ ├── MarginAccountNewOCO │ │ └── MarginAccountNewOCO.go │ ├── MarginAccountNewOTO │ │ └── MarginAccountNewOTO.go │ ├── MarginAccountNewOTOCO │ │ └── MarginAccountNewOTOCO.go │ ├── MarginAccountNewOrder │ │ └── MarginAccountNewOrder.go │ ├── MarginAccountOpenOrder │ │ └── MarginAccountOpenOrder.go │ ├── MarginAccountOrder │ │ └── MarginAccountOrder.go │ ├── MarginAccountQueryAllOCO │ │ └── MarginAccountQueryAllOCO.go │ ├── MarginAccountQueryMaxBorrow │ │ └── MarginAccountQueryMaxBorrow.go │ ├── MarginAccountQueryMaxTransferOutAmount │ │ └── MarginAccountQueryMaxTransferOut.go │ ├── MarginAccountQueryOCO │ │ └── MarginAccountQueryOCO.go │ ├── MarginAccountQueryOpenOCO │ │ └── MarginAccountQueryOpenOCO.go │ ├── MarginAccountQueryTradeList │ │ └── MarginAccountQueryTradeList.go │ ├── MarginAccountSummary │ │ └── MarginAccountSummary.go │ ├── MarginBnbBurnStatus │ │ └── MarginBnbBurnStatus.go │ ├── MarginCrossCollateralRatio │ │ └── MarginCrossCollateralRatio.go │ ├── MarginCrossMarginFee │ │ └── MarginCrossMarginFee.go │ ├── MarginCurrentOrderCount │ │ └── MarginCurrentOrderCount.go │ ├── MarginInterestRateHistory │ │ └── MarginInterestRateHistory.go │ ├── MarginIsolatedAccountDisable │ │ └── MarginIsolatedAccountDisable.go │ ├── MarginIsolatedAccountEnable │ │ └── MarginisolatedAccountEnable.go │ ├── MarginIsolatedAccountInfo │ │ └── MarginIsolatedAccountInfo.go │ ├── MarginIsolatedAccountLimit │ │ └── MarginIsolatedAccountLimit.go │ ├── MarginIsolatedCapitalFlow │ │ └── MarginIsolatedCapitalFlow.go │ ├── MarginIsolatedMarginFee │ │ └── MarginIsolatedMarginFee.go │ ├── MarginIsolatedMarginTier │ │ └── MarginIsolatedMarginTier.go │ ├── MarginManualLiquidation │ │ └── MarginManualLiquidation.go │ ├── MarginSmallLiabilityExchange │ │ └── MarginSmallLiabilityExchange.go │ ├── MarginSmallLiabilityExchangeCoinList │ │ └── MarginSmallLiabilityExchangeCoinList.go │ ├── MarginSmallLiabilityExchangeHistory │ │ └── MarginSmallLiabilityExchangeHistory.go │ ├── MarginToggleBnbBurn │ │ └── MarginToggleBnbBurn.go │ ├── QueryLiabilityCoinLeverageBracket │ │ └── QueryLiabilityCoinLeverageBracket.go │ ├── QueryMarginAvailableInventory │ │ └── QueryMarginAvailableInventory.go │ └── QueryMarginPriceIndex │ │ └── QueryMarginPriceIndex.go ├── market │ ├── AggTradesList │ │ └── AggTradesList.go │ ├── AvgPrice │ │ └── AvgPrice.go │ ├── ExchangeInfo │ │ └── ExchangeInfo.go │ ├── HistoricalTradeLookup │ │ └── HistoricalTradeLookup.go │ ├── Klines │ │ └── Klines.go │ ├── OrderBook │ │ └── OrderBook.go │ ├── Ping │ │ └── Ping.go │ ├── RecentTradesList │ │ └── RecentTradesList.go │ ├── ServerTime │ │ └── ServerTime.go │ ├── Ticker │ │ └── Ticker.go │ ├── Ticker24hr │ │ └── Ticker24hr.go │ ├── TickerBookTicker │ │ └── TickerBookTicker.go │ ├── TickerPrice │ │ └── TickerPrice.go │ └── UiKlines │ │ └── UiKlines.go ├── subaccount │ ├── CreateSubAccount │ │ └── CreateSubAccount.go │ ├── DeleteIPListForSubAccountAPIKey │ │ └── DeleteIPListForSubAccountAPIKey.go │ ├── DepositAssetsIntoManagedSubAccount │ │ └── DepositAssetsIntoManagedSubAccount.go │ ├── EnableFuturesForSubAccount │ │ └── EnableFuturesForSubAccount.go │ ├── EnableLeverageTokenForSubAccount │ │ └── EnableLeverageTokenForSubAccount.go │ ├── EnableMarginForSubAccount │ │ └── EnableMarginForSubAccount.go │ ├── FuturesTransferForSubAccount │ │ └── FuturesTransferForSubAccount.go │ ├── GetDetailOnSubAccountFuturesAccount │ │ └── GetDetailOnSubAccountFuturesAccount.go │ ├── GetDetailOnSubAccountFuturesAccountV2 │ │ └── GetDetailOnSubAccountFuturesAccountV2.go │ ├── GetDetailOnSubAccountMarginAccount │ │ └── GetDetailOnSubAccountMarginAccount.go │ ├── GetFuturesPositionRiskOfSubAccount │ │ └── GetFuturesPositionRiskOfSubAccount.go │ ├── GetFuturesPositionRiskOfSubAccountV2 │ │ └── GetFuturesPositionRiskOfSubAccountV2.go │ ├── GetIPRestrictionForSubAccountAPIKey │ │ └── GetIPRestrictionForSubAccountAPIKey.go │ ├── GetManagedSubAccountDepositAddress │ │ └── GetManagedSubAccountDepositAddress.go │ ├── GetSubAccountDepositAddress │ │ └── GetSubAccountDepositAddress.go │ ├── GetSubAccountDepositHistory │ │ └── GetSubAccountDepositHistory.go │ ├── GetSubAccountStatus │ │ └── GetSubAccountStatus.go │ ├── GetSummaryOfSubAccountFuturesAccount │ │ └── GetSummaryOfSubAccountFuturesAccount.go │ ├── GetSummaryOfSubAccountFuturesAccountV2 │ │ └── GetSummaryOfSubAccountFuturesAccountV2.go │ ├── GetSummaryOfSubAccountMarginAccount │ │ └── GetSummaryOfSubAccountMarginAccount.go │ ├── MarginTransferForSubAccount │ │ └── MarginTransferForSubAccount.go │ ├── QueryManagedSubAccountAssetDetails │ │ └── QueryManagedSubAccountAssetDetails.go │ ├── QueryManagedSubAccountFuturesAssetDetails │ │ └── QueryManagedSubAccountFuturesAssetDetails.go │ ├── QueryManagedSubAccountList │ │ └── QueryManagedSubAccountList.go │ ├── QueryManagedSubAccountMarginAssetDetails │ │ └── QueryManagedSubAccountMarginAssetDetails.go │ ├── QueryManagedSubAccountSnapshot │ │ └── QueryManagedSubAccountSnapshot.go │ ├── QueryManagedSubAccountTransferLog │ │ └── QueryManagedSubAccountTransferLog.go │ ├── QueryManagedSubAccountTransferLogForTradingTeam │ │ └── QueryManagedSubAccountTransferLogForTradingTeam.go │ ├── QuerySubAccountAssets │ │ └── QuerySubAccountAssets.go │ ├── QuerySubAccountAssetsForMasterAccount │ │ └── QuerySubAccountAssetsForMasterAccount.go │ ├── QuerySubAccountSpotAssetsSummary │ │ └── QuerySubAccountSpotAssetsSummary.go │ ├── QuerySubAccountTransactionTatistics │ │ └── QuerySubAccountTransactionTatistics.go │ ├── QueryUniversalTransferHistory │ │ └── QueryUniversalTransferHistory.go │ ├── SubAccountFuturesAssetTransfer │ │ └── SubAccountFuturesAssetTransfer.go │ ├── SubAccountFuturesAssetTransferHistory │ │ └── SubAccountFuturesAssetTransferHistory.go │ ├── SubAccountList │ │ └── SubAccountList.go │ ├── SubAccountSpotAssetTransferHistory │ │ └── SubAccountSpotAssetTransferHistory.go │ ├── SubAccountTransferHistory │ │ └── SubAccountTransferHistory.go │ ├── TransferToMaster │ │ └── TransferToMaster.go │ ├── TransferToSubAccountOfSameMaster │ │ └── TransferToSubAccountOfSameMaster.go │ ├── UniversalTransfer │ │ └── UniversalTransfer.go │ ├── UpdateIPRestrictionForSubAccountAPIKey │ │ └── UpdateIPRestrictionForSubAccountAPIKey.go │ └── WithdrawAssetsFromTheManagedSubAccount │ │ └── WithdrawAssetsFromTheManagedSubAccount.go ├── user_stream │ ├── CloseUserStream │ │ └── CloseUserStream.go │ ├── CreateNewListenKey │ │ └── CreateListenKey.go │ └── PingUserStream │ │ └── PingUserStream.go ├── wallet │ ├── APIKeyPermission │ │ └── APIKeyPermission.go │ ├── AccountAPITradingStatus │ │ └── AccountAPITradingStatus.go │ ├── AccountInfo │ │ └── AccountInfo.go │ ├── AccountStatus │ │ └── AccountStatus.go │ ├── AssetDetail │ │ └── AssetDetail.go │ ├── AssetDetailV2 │ │ └── AssetDetailV2.go │ ├── AssetDividendRecord │ │ └── AssetDividendRecord.go │ ├── BUSDConvertHistory │ │ └── BUSDConvertHistory.go │ ├── CloudMiningPaymentHistory │ │ └── CloudMiningPaymentHistory.go │ ├── DepositAddress │ │ └── DepositAddress.go │ ├── DepositAddressList │ │ └── DepositAddressList.go │ ├── DepositHistory │ │ └── DepositHistory.go │ ├── DisableFastWithdrawSwitch │ │ └── DisableFastWithdrawSwitch.go │ ├── DustLog │ │ └── DustLog.go │ ├── DustTransfer │ │ └── DustTransfer.go │ ├── EnableFastWithdrawSwitch │ │ └── EnableFastWithdrawSwitch.go │ ├── FundingWallet │ │ └── FundingWallet.go │ ├── GetAccountSnapshot │ │ └── GetAccountSnapshot.go │ ├── GetAllCoinsInfo │ │ └── GetAllCoinsInfo.go │ ├── GetSymbolsDelistSchedule │ │ └── GetSymbolsDelistSchedule.go │ ├── GetSystemStatus │ │ └── GetSystemStatus.go │ ├── TradeFee │ │ └── TradeFee.go │ ├── UserAsset │ │ └── UserAsset.go │ ├── UserDelegationHistory │ │ └── UserDelegationHistory.go │ ├── UserUniversalTransfer │ │ └── UserUniversalTransfer.go │ ├── UserUniversalTransferHistory │ │ └── UserUniversalTransferHistory.go │ ├── WalletBalance │ │ └── WalletBalance.go │ ├── Withdraw │ │ └── Withdraw.go │ └── WithdrawHistory │ │ └── WithdrawHistory.go ├── websocket │ ├── AllMarketMiniTickers │ │ └── AllMarketMiniTickers.go │ ├── AllMarketTickers │ │ └── AllMarketTickers.go │ ├── CombinedDepth │ │ └── CombinedDepth.go │ ├── MarketMiniTickers │ │ └── MarketMiniTickers.go │ ├── UserDataStream │ │ └── UserDataStream.go │ ├── aggtrades │ │ └── aggtrades.go │ ├── bookticker │ │ └── bookticker.go │ ├── depth │ │ └── depth.go │ ├── kline │ │ └── kline.go │ └── trades │ │ └── trades.go └── websocket_api │ ├── account │ ├── AccountInformation │ │ └── AccountInformation.go │ ├── OCOHistory │ │ └── OCOHistory.go │ ├── OrderHistory │ │ └── OrderHistory.go │ ├── OrderRateLimits │ │ └── OrderRateLimits.go │ ├── PreventedMatches │ │ └── PreventedMatches.go │ └── TradeHistory │ │ └── TradeHistory.go │ ├── combined │ └── WsStreamAndWsAPI │ │ └── WsStreamAndWsAPI.go │ ├── market │ ├── AggregateTrades │ │ └── AggregateTrades.go │ ├── AvgPrice │ │ └── AvgPrice.go │ ├── Depth │ │ └── Depth.go │ ├── HistoricalTrades │ │ └── HistoricalTrades.go │ ├── Klines │ │ └── Klines.go │ ├── RecentTrades │ │ └── RecentTrades.go │ ├── Ticker │ │ └── Ticker.go │ ├── Ticker24hr │ │ └── Ticker24hr.go │ ├── TickerBook │ │ └── TickerBook.go │ ├── TickerPrice │ │ └── TickerPrice.go │ └── UiKlines │ │ └── UiKlines.go │ ├── trading │ ├── CancelOCO │ │ └── CancelOCO.go │ ├── CancelOpenOrders │ │ └── CancelOpenOrders.go │ ├── CancelOrder │ │ └── CancelOrder.go │ ├── CancelReplaceOrder │ │ └── CancelReplaceOrder.go │ ├── CurrentOpenOCO │ │ └── CurrentOpenOCO.go │ ├── CurrentOpenOrders │ │ └── CurrentOpenOrders.go │ ├── PlaceNewOCO │ │ └── PlaceNewOCO.go │ ├── PlaceNewOrder │ │ └── PlaceNewOrder.go │ ├── QueryOCO │ │ └── QueryOCO.go │ ├── QueryOrder │ │ └── QueryOrder.go │ └── TestNewOrder │ │ └── TestNewOrder.go │ └── user_data │ ├── PingUserDataStream │ └── PingUserDataStream.go │ ├── StartUserDataStream │ └── StartUserDataStream.go │ └── StopUserDataStream │ └── StopUserDataStream.go ├── fiat.go ├── fiat_test.go ├── go.mod ├── go.sum ├── handlers └── errors.go ├── margin.go ├── margin_test.go ├── market.go ├── market_test.go ├── request.go ├── subaccount.go ├── subaccount_test.go ├── user_stream.go ├── user_stream_test.go ├── wallet.go ├── wallet_test.go ├── websocket.go ├── websocket_api.go ├── websocket_api_account.go ├── websocket_api_market.go ├── websocket_api_trade.go ├── websocket_api_userdata.go ├── websocket_service.go └── websocket_service_test.go /.github/workflows/connector.yml: -------------------------------------------------------------------------------- 1 | name: Run Tests 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | - main 8 | pull_request: 9 | branches: 10 | - master 11 | - main 12 | - rc-** 13 | 14 | jobs: 15 | Checks: 16 | runs-on: ubuntu-latest 17 | env: 18 | GO111MODULE: on 19 | steps: 20 | - uses: actions/checkout@v3 21 | - name: Setup Go 22 | uses: actions/setup-go@v4 23 | with: 24 | go-version-file: './go.mod' 25 | - name: Check Formatting 26 | run: go fmt ./... 27 | - name: Vet Project 28 | run: go vet ./... 29 | - name: Initialise StaticCheck 30 | run: go get honnef.co/go/tools/cmd/staticcheck@latest && go install honnef.co/go/tools/cmd/staticcheck@latest 31 | - name: StaticCheck - Check for unused functions, duplicate imports + more 32 | run: staticcheck ./... 33 | - name: Initialise DeadCode 34 | run: go get github.com/remyoudompheng/go-misc/deadcode && go install github.com/remyoudompheng/go-misc/deadcode 35 | - name: DeadCode - Check for unused variables 36 | run: deadcode -test 37 | - name: Initialise ErrCheck 38 | run: go get github.com/kisielk/errcheck@latest && go install github.com/kisielk/errcheck@latest 39 | - name: Install GoSec 40 | run: go get github.com/securego/gosec/v2/cmd/gosec@latest && go install github.com/securego/gosec/v2/cmd/gosec@latest 41 | - name: GoSec - Scan for potential security issues with gosec 42 | run: gosec -tests -confidence high ./... 43 | UnitTest: 44 | runs-on: ubuntu-latest 45 | steps: 46 | - uses: actions/checkout@v3 47 | - name: Setup Go 48 | uses: actions/setup-go@v4 49 | with: 50 | go-version-file: './go.mod' 51 | - name: Run Unit Tests 52 | run: go test -v -race -covermode=atomic . 53 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | coverage.txt 2 | *.DS_Store 3 | .idea 4 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change log 2 | 3 | ## v0.8.0 - 2024-11-20 4 | 5 | ### Added 6 | - Added `Wallet` Endpoints: 7 | - `GET /sapi/v1/account/info` - Fetch account info detail 8 | - `GET /sapi/v1/asset/custody/transfer-history` - Query user delegation history 9 | - `GET /sapi/v1/asset/wallet/balance` - Query user wallet balance 10 | - `GET /sapi/v1/capital/deposit/address/list` - Fetch deposit address list with network 11 | - `GET /sapi/v1/spot/delist-schedule` - Query spot delist schedule 12 | 13 | - Added `Margin` Endpoints: 14 | - `GET /sapi/v1/margin/available-inventory` 15 | - `GET /sapi/v1/margin/capital-flow` 16 | - `GET /sapi/v1/margin/leverageBracket` 17 | - `POST /sapi/v1/margin/manual-liquidation` 18 | - `POST /sapi/v1/margin/max-leverage` 19 | - `POST /sapi/v1/margin/order/oto` 20 | - `POST /sapi/v1/margin/order/otoco` 21 | 22 | ### Fixed 23 | - Fixed `TestConnectivityResponse.RateLimits` type - updated to array 24 | - Fixed `NewTickerPriceService.Do` unmarshaling issue 25 | - Fixed `SystemStatusResponse` type 26 | - Fixed variable named `CumulativeQuoteQty` to `CummulativeQuoteQty` 27 | - Fixed `SubAccountTransferHistoryService` response type 28 | - Fixed field `Fills` type in `CancelReplaceResponse` 29 | 30 | ### Updated 31 | - Added the parameters `symbol`, `symbols`, `permissions` , `showPermissionSets` and `symbolStatus` to endpoint `GET /api/v3/exchangeInfo` 32 | - Added parameter `accountType` to endpoint `POST /sapi/v1/asset/dust-btc` 33 | - Added response fields `Created`, `CollateralMarginLevel`, `TotalCollateralValueInUSDT`, `TransferInEnabled`, `TransferOutEnabled` and `AccountType` to endpoint `GET /sapi/v1/margin/account` 34 | - Added response fields `EnableFixApiTrade`, `EnableFixReadOnly` and `EnablePortfolioMarginTrading` to endpoint `GET /sapi/v1/account/apiRestrictions` 35 | - Updated `SymbolInfo` and `SymbolFilter` types 36 | - Removed response field `resetAddressStatus` and added fields `contractAddressUrl` and `contractAddress` from endpoint `GET /sapi/v1/capital/config/getall` 37 | 38 | 39 | ### Removed 40 | - Removed `Wallet` endpoints: 41 | - `GET /sapi/v1/capital/contract/convertible-coins` 42 | - `POST /sapi/v1/asset/convert-transfer` 43 | 44 | ## v0.7.0 - 2024-08-23 45 | 46 | ### Added 47 | - SPOT `FIAT` Endpoints: 48 | - `GET /sapi/v1/fiat/orders` - Get Fiat Deposit/Withdraw History 49 | - `GET /sapi/v1/fiat/payments` - Get Fiat Payments History 50 | - Websocket Stream: 51 | - `@miniTicker` - Individual Symbol Mini Ticker Stream 52 | 53 | ### Updated 54 | - Updated `SymbolInfo` and `SymbolFilter` types 55 | 56 | ### Fixed 57 | - Fixed issue with `stopCh` not stopping the WebSocket connection 58 | - Fixed the `stop` method for `userDataStream` 59 | - Fixed symbols method for `NewTicker24hrService` 60 | 61 | ## v0.6.0 - 2024-06-19 62 | 63 | ### Fixed 64 | - Fixed following `Margin` endpoints to correctly return their response: 65 | - `MarginAccountOpenOrder` 66 | - `MarginAccountAllOrder` 67 | - `MarginAccountQueryAllOCO` 68 | - `MarginAccountQueryOpenOCO` 69 | - `MarginAccountQueryTradeList` 70 | - Fixed example files for the following endpoints: 71 | - `MarginAccountQueryTradeList` 72 | - `MarginInterestRateHistory` 73 | - `MarginAccountQueryOCO` 74 | - `MarginAccountOrder` 75 | - Added signature to `TestNewOrder` endpoint 76 | - Fixed typo of `InterestHistoryResponse` parameters 77 | - Fixed type of `MarginInterestRateHistoryResponse` parameter 78 | 79 | ### Updated 80 | - Updated Dependencies 81 | - Updated Go version to `1.22` 82 | 83 | ### Removed 84 | - Removed `Margin` endpoints: 85 | - `POST /sapi/v1/margin/transfer` 86 | - `POST /sapi/v1/margin/isolated/transfer` 87 | - `POST /sapi/v1/margin/loan` 88 | - `POST /sapi/v1/margin/repay` 89 | - `GET /sapi/v1/margin/isolated/transfer` 90 | - `GET /sapi/v1/margin/asset` 91 | - `GET /sapi/v1/margin/pair` 92 | - `GET /sapi/v1/margin/isolated/pair` 93 | - `GET /sapi/v1/margin/loan` 94 | - `GET /sapi/v1/margin/repay` 95 | - `GET /sapi/v1/margin/dribblet` 96 | - `GET /sapi/v1/margin/dust` 97 | - `POST /sapi/v1/margin/dust` 98 | 99 | - Removed `Staking` endpoints: 100 | - `GET /sapi/v1/staking/productList` 101 | - `POST /sapi/v1/staking/purchase` 102 | - `POST /sapi/v1/staking/redeem` 103 | - `GET /sapi/v1/staking/position` 104 | - `GET /sapi/v1/staking/stakingRecord` 105 | - `POST /sapi/v1/staking/setAutoStaking` 106 | - `GET /sapi/v1/staking/personalLeftQuota` 107 | 108 | ## v0.5.2 - 2023-08-22 109 | 110 | ### Fixed 111 | - Fixed formatting issues causing JSON Unmarshal error in some `wallet` methods. 112 | 113 | ## v0.5.1 - 2023-08-21 114 | 115 | ### Fixed 116 | - Implemented a fix for the automatic conversion to scientific notation when handling large `quantity` values. 117 | 118 | ## v0.5.0 - 2023-06-30 119 | 120 | ### Added 121 | - Added Websocket API Endpoints 122 | - Added User-Agent header to Websocket and Websocket API 123 | 124 | ### Fixed 125 | - bookTickerService Endpoint fixed to correctly support individual `symbol` parameter. 126 | 127 | ## v0.4.0 - 2023-05-08 128 | 129 | ### Added 130 | - Staking Endpoints Implemented 131 | 132 | ## v0.3.0 - 2023-05-02 133 | 134 | ### Added 135 | - New Endpoint, `NewGetManagedSubAccountDepositAddressService()`: `GET /sapi/v1/managed-subaccount/deposit/address` - Get Managed Sub-account Deposit Address (For Investor Master Account) (USER_DATA) 136 | 137 | ### Fixed 138 | - Added separate USDT-M and COIN-M Response Types for relevant Subaccount Endpoints 139 | - Added support for Conditional Fields in relevant responses on Account Endpoints 140 | - Responses for `POST /api/v3/order/cancelReplace` support all 4 Response Types 141 | - Support for specifying `recvWindow` via `WithRecvWindow()` function 142 | - `strategyId` and `strategyType` parameters added to `TestNewOrder` and `CreateOrderService` endpoints 143 | - `UiKlines`: corrected `limit` parameter to not be sent as `interval` 144 | 145 | ## v0.2.0 - 2023-04-21 146 | 147 | ### Added 148 | - WebsocketStreamClient 149 | - Websocket Client can be initialized with 2 parameters, `NewWebsocketStreamClient(isCombined, baseURL)`: 150 | - `isCombined` is a MANDATORY boolean value that specifies whether you are calling a combined stream or not. 151 | - If `isCombined` is set to `true`, `"/stream?streams="` will be appended to the `baseURL` to allow for Combining streams. 152 | - Otherwise, if set to `false`, `"/ws/"` will be appended to the `baseURL`. 153 | - `baseURL` is an OPTIONAL string value that determines the base URL to use for the websocket connection. 154 | - If `baseURL` is not set, it will default to the Live Exchange URL: `"wss://stream.binance.com:9443"`. 155 | 156 | ### Fixed 157 | - Order Response Types for `CreateOrderService` - `POST /api/v3/order` 158 | - Added support for all 3 Order Response Types - `ACK`, `RESULT` and `FULL` 159 | - Order Response Types for `MarginAccountNewOrderService` - `POST /sapi/v1/margin/order` 160 | - Added support for all 3 Order Response Types - `ACK`, `RESULT` and `FULL` 161 | - Different Response Types for `MarginIsolatedAccountInfoService` - `GET /sapi/v1/margin/isolated/account` 162 | - Added support for both Response Types, depending on whether `symbols` is set or not. 163 | 164 | ### Changed 165 | - Renamed `WsAllMiniMarketsStatServe` to `WsAllMarketMiniTickersStatServe`. 166 | - Renamed `WsMarketsStatServe` to `WsMarketTickersStatServe`. 167 | - Renamed `WsAllMarketsStatServe` to `WsAllMarketTickersStatServe`. 168 | - Updated Github Action `UnitTest`. 169 | 170 | ### Removed 171 | - Removed unused `setFormParam`, `setFormParams`, `WithRecvWindow`, `WithHeader` and `WithHeaders` functions from `request.go`. 172 | 173 | ## v0.1.0 - 2023-03-31 174 | 175 | - First release 176 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Binance 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /client_test.go: -------------------------------------------------------------------------------- 1 | package binance_connector 2 | 3 | import ( 4 | "bytes" 5 | "context" 6 | "io" 7 | "net/http" 8 | "net/url" 9 | "testing" 10 | "time" 11 | 12 | "github.com/stretchr/testify/assert" 13 | "github.com/stretchr/testify/mock" 14 | "github.com/stretchr/testify/require" 15 | "github.com/stretchr/testify/suite" 16 | ) 17 | 18 | type baseTestSuite struct { 19 | suite.Suite 20 | client *mockedClient 21 | apiKey string 22 | secretKey string 23 | baseURL string 24 | } 25 | 26 | func (s *baseTestSuite) r() *require.Assertions { 27 | return s.Require() 28 | } 29 | 30 | func (s *baseTestSuite) SetupTest() { 31 | s.apiKey = "dummyAPIKey" 32 | s.secretKey = "dummySecretKey" 33 | s.baseURL = "https://dummyapi.com" 34 | s.client = newMockedClient(s.apiKey, s.secretKey, s.baseURL) 35 | } 36 | 37 | func (s *baseTestSuite) mockDo(data []byte, err error, statusCode ...int) { 38 | s.client.Client.do = s.client.do 39 | code := http.StatusOK 40 | if len(statusCode) > 0 { 41 | code = statusCode[0] 42 | } 43 | s.client.On("do", anyHTTPRequest()).Return(newHTTPResponse(data, code), err) 44 | } 45 | 46 | func (s *baseTestSuite) assertDo() { 47 | s.client.AssertCalled(s.T(), "do", anyHTTPRequest()) 48 | } 49 | 50 | func (s *baseTestSuite) assertReq(f func(r *request)) { 51 | s.client.assertReq = f 52 | } 53 | 54 | func (s *baseTestSuite) assertRequestEqual(e, a *request) { 55 | s.assertURLValuesEqual(e.query, a.query) 56 | s.assertURLValuesEqual(e.form, a.form) 57 | } 58 | 59 | func (s *baseTestSuite) assertURLValuesEqual(e, a url.Values) { 60 | var eKeys, aKeys []string 61 | for k := range e { 62 | eKeys = append(eKeys, k) 63 | } 64 | for k := range a { 65 | aKeys = append(aKeys, k) 66 | } 67 | r := s.r() 68 | r.Len(aKeys, len(eKeys)) 69 | for k := range a { 70 | switch k { 71 | case timestampKey, signatureKey: 72 | r.NotEmpty(a.Get(k)) 73 | continue 74 | } 75 | r.Equal(e[k], a[k], k) 76 | } 77 | } 78 | 79 | func anythingOfType(t string) mock.AnythingOfTypeArgument { 80 | return mock.AnythingOfType(t) 81 | } 82 | 83 | func newContext() context.Context { 84 | return context.Background() 85 | } 86 | 87 | func anyHTTPRequest() mock.AnythingOfTypeArgument { 88 | return anythingOfType("*http.Request") 89 | } 90 | 91 | func newHTTPResponse(data []byte, statusCode int) *http.Response { 92 | return &http.Response{ 93 | Body: io.NopCloser(bytes.NewBuffer(data)), 94 | StatusCode: statusCode, 95 | } 96 | } 97 | 98 | func newRequest() *request { 99 | r := &request{ 100 | query: url.Values{}, 101 | form: url.Values{}, 102 | } 103 | return r 104 | } 105 | 106 | func newSignedRequest() *request { 107 | return newRequest().setParams(params{ 108 | timestampKey: "", 109 | signatureKey: "", 110 | }) 111 | } 112 | 113 | type assertReqFunc func(r *request) 114 | 115 | type mockedClient struct { 116 | mock.Mock 117 | *Client 118 | assertReq assertReqFunc 119 | } 120 | 121 | func newMockedClient(apiKey, secretKey, baseURL string) *mockedClient { 122 | m := new(mockedClient) 123 | m.Client = NewClient(apiKey, secretKey, baseURL) 124 | return m 125 | } 126 | 127 | func (m *mockedClient) do(req *http.Request) (*http.Response, error) { 128 | if m.assertReq != nil { 129 | r := newRequest() 130 | r.query = req.URL.Query() 131 | if req.Body != nil { 132 | bs := make([]byte, req.ContentLength) 133 | for { 134 | n, _ := req.Body.Read(bs) 135 | if n == 0 { 136 | break 137 | } 138 | } 139 | form, err := url.ParseQuery(string(bs)) 140 | if err != nil { 141 | panic(err) 142 | } 143 | r.form = form 144 | } 145 | m.assertReq(r) 146 | } 147 | args := m.Called(req) 148 | return args.Get(0).(*http.Response), args.Error(1) 149 | } 150 | 151 | func TestFormatTimestamp(t *testing.T) { 152 | tm, _ := time.Parse("2006-01-02 15:04:05", "2018-06-01 01:01:01") 153 | assert.Equal(t, int64(1527814861000), FormatTimestamp(tm)) 154 | } 155 | -------------------------------------------------------------------------------- /consts.go: -------------------------------------------------------------------------------- 1 | package binance_connector 2 | 3 | const Name = "binance-connector-go" 4 | 5 | const Version = "0.8.0" 6 | -------------------------------------------------------------------------------- /examples/account/CancelOCO/CancelOCO.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | CancelOCO() 12 | } 13 | 14 | func CancelOCO() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // Binance Cancel OCO (TRADE) - DELETE /api/v3/orderList 22 | cancelOCO, err := client.NewCancelOCOService().Symbol("BTCUSDT"). 23 | Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(cancelOCO)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/account/CancelOpenOrders/CancelOpenOrders.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | CancelOpenOrders() 12 | } 13 | 14 | func CancelOpenOrders() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // Binance Cancel all open orders on a symbol - DELETE /api/v3/openOrders 22 | cancelOpenOrders, err := client.NewCancelOpenOrdersService().Symbol("BTCUSDT"). 23 | Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(cancelOpenOrders)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/account/CancelOrder/CancelOrder.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | CancelOrder() 12 | } 13 | 14 | func CancelOrder() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // Binance Cancel Order endpoint - DELETE /api/v3/order 22 | cancelOrder, err := client.NewCancelOrderService().Symbol("BTCUSDT"). 23 | Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(cancelOrder)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/account/CancelReplace/CancelReplace.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | CancelReplace() 12 | } 13 | 14 | func CancelReplace() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // Cancel an Existing Order and Send a New Order (TRADE) - POST /api/v3/order/cancelReplace 22 | cancelReplace, err := client.NewCancelReplaceService(). 23 | Symbol("BTCUSDT").Side("BUY").OrderType("LIMIT").CancelReplaceMode("STOP_ON_FAILURE").CancelOrderId(13341128). 24 | TimeInForce("GTC").Quantity(0.001).Price(20000.0).Do(context.Background()) 25 | if err != nil { 26 | fmt.Println(err) 27 | return 28 | } 29 | fmt.Println(binance_connector.PrettyPrint(cancelReplace)) 30 | } 31 | -------------------------------------------------------------------------------- /examples/account/CreateOrder/CreateOrder.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | NewOrder() 12 | } 13 | 14 | func NewOrder() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // Binance New Order endpoint - POST /api/v3/order 22 | newOrder, err := client.NewCreateOrderService().Symbol("BTCUSDT"). 23 | Side("BUY").Type("MARKET").Quantity(0.001). 24 | Do(context.Background()) 25 | if err != nil { 26 | fmt.Println(err) 27 | return 28 | } 29 | fmt.Println(binance_connector.PrettyPrint(newOrder)) 30 | } 31 | -------------------------------------------------------------------------------- /examples/account/GetAccount/GetAccount.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | AccountInformation() 12 | } 13 | 14 | func AccountInformation() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // Binance Account Information (USER_DATA) - GET /api/v3/account 22 | accountInformation, err := client.NewGetAccountService().Do(context.Background()) 23 | if err != nil { 24 | fmt.Println(err) 25 | return 26 | } 27 | fmt.Println(binance_connector.PrettyPrint(accountInformation)) 28 | } 29 | -------------------------------------------------------------------------------- /examples/account/GetAllOrders/GetAllOrders.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | GetAllOrders() 12 | } 13 | 14 | func GetAllOrders() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // Binance Get all account orders; active, canceled, or filled - GET /api/v3/allOrders 22 | getAllOrders, err := client.NewGetAllOrdersService().Symbol("BTCUSDT"). 23 | Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(getAllOrders)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/account/GetMyTrades/GetMyTrades.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | GetMyTrades() 12 | } 13 | 14 | func GetMyTrades() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // Binance Get trades for a specific account and symbol (USER_DATA) - GET /api/v3/myTrades 22 | getMyTradesService, err := client.NewGetMyTradesService(). 23 | Symbol("BTCUSDT").Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(getMyTradesService)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/account/GetOpenOrders/GetOpenOrders.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | GetCurrentOpenOrders() 12 | } 13 | 14 | func GetCurrentOpenOrders() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // Binance Get current open orders - GET /api/v3/openOrders 22 | getCurrentOpenOrders, err := client.NewGetOpenOrdersService().Symbol("BTCUSDT"). 23 | Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(getCurrentOpenOrders)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/account/GetOrder/GetOrder.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | QueryOrder() 12 | } 13 | 14 | func QueryOrder() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // Binance Query Order (USER_DATA) - GET /api/v3/order 22 | queryOrder, err := client.NewGetOrderService().Symbol("BTCUSDT"). 23 | OrderId(20064739).Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(queryOrder)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/account/NewOCO/NewOCO.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | NewOCO() 12 | } 13 | 14 | func NewOCO() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // Binance New OCO (TRADE) - POST /api/v3/order/oco 22 | newOCO, err := client.NewNewOCOService().Symbol("LTCBNB"). 23 | Side("BUY").Quantity(0.1).Price(0.28).StopPrice(0.22). 24 | Do(context.Background()) 25 | if err != nil { 26 | fmt.Println(err) 27 | return 28 | } 29 | fmt.Println(binance_connector.PrettyPrint(newOCO)) 30 | } 31 | -------------------------------------------------------------------------------- /examples/account/QueryAllOCO/QueryAllOCO.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | QueryAllOCO() 12 | } 13 | 14 | func QueryAllOCO() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // Binance Query all OCO (USER_DATA) (GET /api/v3/allOrderList) 22 | queryAllOCO, err := client.NewQueryAllOCOService(). 23 | Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(queryAllOCO)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/account/QueryCurrentOrderCountUsage/QueryCurrentOrderCountUsage.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | QueryCurrentOrderCountUsage() 12 | } 13 | 14 | func QueryCurrentOrderCountUsage() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // Query Current Order Count Usage (TRADE) 22 | getQueryCurrentOrderCountUsageService, err := client.NewGetQueryCurrentOrderCountUsageService(). 23 | Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(getQueryCurrentOrderCountUsageService)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/account/QueryOCO/QueryOCO.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | QueryOCO() 12 | } 13 | 14 | func QueryOCO() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // Binance Query OCO (USER_DATA) - GET /api/v3/orderList 22 | queryOCO, err := client.NewQueryOCOService().Do(context.Background()) 23 | if err != nil { 24 | fmt.Println(err) 25 | return 26 | } 27 | fmt.Println(binance_connector.PrettyPrint(queryOCO)) 28 | } 29 | -------------------------------------------------------------------------------- /examples/account/QueryOpenOCO/QueryOpenOCO.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | QueryOpenOCO() 12 | } 13 | 14 | func QueryOpenOCO() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // Binance Query open OCO (USER_DATA) - GET /api/v3/openOrderList 22 | queryOpenOCO, err := client.NewQueryOpenOCOService().Do(context.Background()) 23 | if err != nil { 24 | fmt.Println(err) 25 | return 26 | } 27 | fmt.Println(binance_connector.PrettyPrint(queryOpenOCO)) 28 | } 29 | -------------------------------------------------------------------------------- /examples/account/QueryPreventedMatches/QueryPreventedMatches.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | QueryPreventedMatches() 12 | } 13 | 14 | func QueryPreventedMatches() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // Query Prevented Matches (USER_DATA) - GET /api/v3/preventedMatches 22 | getQueryPreventedMatchesService, err := client.NewGetQueryPreventedMatchesService(). 23 | Symbol("BTCUSDT").Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(getQueryPreventedMatchesService)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/account/TestNewOrder/TestNewOrder.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | TestNewOrder() 12 | } 13 | 14 | func TestNewOrder() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // Binance Test New Order endpoint - POST /api/v3/order/test 22 | testNewOrder, err := client.NewTestNewOrder().Symbol("BTCUSDT"). 23 | Side("BUY").OrderType("MARKET").Quantity(0.001). 24 | Do(context.Background()) 25 | if err != nil { 26 | fmt.Println(err) 27 | return 28 | } 29 | fmt.Println(binance_connector.PrettyPrint(testNewOrder)) 30 | } 31 | -------------------------------------------------------------------------------- /examples/fiat/GetFiatDepositWithdrawHistory/GetFiatDepositWithdrawHistory.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | GetFiatDepositWithdrawHistory() 12 | } 13 | 14 | func GetFiatDepositWithdrawHistory() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // GetFiatDepositWithdrawHistoryService - /sapi/v1/fiat/orders 22 | getFiatDepositWithdrawHistory, err := client.NewGetFiatDepositWithdrawHistoryService(). 23 | TransactionType("0"). 24 | Do(context.Background()) 25 | if err != nil { 26 | fmt.Println(err) 27 | return 28 | } 29 | fmt.Println(binance_connector.PrettyPrint(getFiatDepositWithdrawHistory)) 30 | } 31 | -------------------------------------------------------------------------------- /examples/fiat/GetFiatPaymentHistory/GetFiatPaymentHistory.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | GetFiatPaymentHistory() 12 | } 13 | 14 | func GetFiatPaymentHistory() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // GetFiatPaymentHistoryService - /sapi/v1/fiat/payments 22 | getFiatPaymentHistory, err := client.NewGetFiatPaymentHistoryService(). 23 | TransactionType("0"). 24 | Do(context.Background()) 25 | if err != nil { 26 | fmt.Println(err) 27 | return 28 | } 29 | fmt.Println(binance_connector.PrettyPrint(getFiatPaymentHistory)) 30 | } 31 | -------------------------------------------------------------------------------- /examples/margin/AllIsolatedMarginSymbol/AllIsolatedMarginSymbol.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | AllIsolatedMarginSymbol() 12 | } 13 | 14 | func AllIsolatedMarginSymbol() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // AllIsolatedMarginSymbolService - /sapi/v1/margin/isolated/allPairs 22 | allIsolatedMarginSymbol, err := client.NewAllIsolatedMarginSymbolService(). 23 | Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(allIsolatedMarginSymbol)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/margin/CrossMarginAccountDetail/CrossMarginAccountDetail.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | CrossMarginAccountDetail() 12 | } 13 | 14 | func CrossMarginAccountDetail() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // CrossMarginAccountDetailService - /sapi/v1/margin/account 22 | crossMarginAccountDetail, err := client.NewCrossMarginAccountDetailService().Do(context.Background()) 23 | if err != nil { 24 | fmt.Println(err) 25 | return 26 | } 27 | fmt.Println(binance_connector.PrettyPrint(crossMarginAccountDetail)) 28 | } 29 | -------------------------------------------------------------------------------- /examples/margin/CrossMarginTransferHistory/CrossMarginTransferHistory.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | CrossMarginTransferHistory() 12 | } 13 | 14 | func CrossMarginTransferHistory() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // CrossMarginTransferHistoryService - /sapi/v1/margin/transfer 22 | crossMarginTransferHistory, err := client.NewCrossMarginTransferHistoryService(). 23 | Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(crossMarginTransferHistory)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/margin/ForceLiquidationRecord/ForceLiquidationRecord.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | ForceLiquidationRecord() 12 | } 13 | 14 | func ForceLiquidationRecord() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // ForceLiquidationRecordService - /sapi/v1/margin/forceLiquidationRec 22 | forceLiquidationRecord, err := client.NewForceLiquidationRecordService(). 23 | Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(forceLiquidationRecord)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/margin/GetAllMarginAssets/GetAllMarginAssets.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | GetAllMarginAssets() 12 | } 13 | 14 | func GetAllMarginAssets() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // GetAllMarginAssetsService - /sapi/v1/margin/allAssets 22 | getAllMarginAssets, err := client.NewGetAllMarginAssetsService().Do(context.Background()) 23 | if err != nil { 24 | fmt.Println(err) 25 | return 26 | } 27 | fmt.Println(binance_connector.PrettyPrint(getAllMarginAssets)) 28 | } 29 | -------------------------------------------------------------------------------- /examples/margin/GetAllMarginPairs/GetAllMarginPairs.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | GetAllMarginPairs() 12 | } 13 | 14 | func GetAllMarginPairs() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // GetAllMarginPairsService - /sapi/v1/margin/allPairs 22 | getAllMarginPairs, err := client.NewGetAllMarginPairsService().Do(context.Background()) 23 | if err != nil { 24 | fmt.Println(err) 25 | return 26 | } 27 | fmt.Println(binance_connector.PrettyPrint(getAllMarginPairs)) 28 | } 29 | -------------------------------------------------------------------------------- /examples/margin/InterestHistory/InterestHistory.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | InterestHistory() 12 | } 13 | 14 | func InterestHistory() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // InterestHistoryService - /sapi/v1/margin/interestHistory 22 | interestHistory, err := client.NewInterestHistoryService().Asset("USDT").Do(context.Background()) 23 | if err != nil { 24 | fmt.Println(err) 25 | return 26 | } 27 | fmt.Println(binance_connector.PrettyPrint(interestHistory)) 28 | } 29 | -------------------------------------------------------------------------------- /examples/margin/MarginAccountAdjustCrossMaxLeverage/MarginAccountAdjustCrossMaxLeverage.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | MarginAccountAdjustCrossMaxLeverage() 12 | } 13 | 14 | func MarginAccountAdjustCrossMaxLeverage() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // MarginAccountAdjustCrossMaxLeverageService - /sapi/v1/margin/max-leverage 22 | marginAccountAdjustCrossMaxLeverage, err := client.NewMarginAccountAdjustCrossMaxLeverageService(). 23 | MaxLeverage(5).Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(marginAccountAdjustCrossMaxLeverage)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/margin/MarginAccountAllOrder/MarginAccountAllOrder.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | MarginAccountAllOrder() 12 | } 13 | 14 | func MarginAccountAllOrder() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // MarginAccountAllOrderService - /sapi/v1/margin/allOrders 22 | marginAccountAllOrder, err := client.NewMarginAccountAllOrderService().Symbol("BTCUSDT"). 23 | Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(marginAccountAllOrder)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/margin/MarginAccountCancelAllOrders/MarginAccountCancelAllOrders.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | MarginAccountCancelAllOrders() 12 | } 13 | 14 | func MarginAccountCancelAllOrders() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // MarginAccountCancelAllOrdersService - /sapi/v1/margin/openOrders 22 | marginAccountCancelAllOrders, err := client.NewMarginAccountCancelAllOrdersService().Symbol("BTCUSDT"). 23 | Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(marginAccountCancelAllOrders)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/margin/MarginAccountCancelOCO/MarginAccountCancelOCO.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | MarginAccountCancelOCO() 12 | } 13 | 14 | func MarginAccountCancelOCO() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // MarginAccountCancelOCOService - /sapi/v1/margin/orderList 22 | marginAccountCancelOCO, err := client.NewMarginAccountCancelOCOService().Symbol("BTCUSDT"). 23 | Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(marginAccountCancelOCO)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/margin/MarginAccountCancelOrder/MarginAccountCancelOrder.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | MarginAccountCancelOrder() 12 | } 13 | 14 | func MarginAccountCancelOrder() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // MarginAccountCancelOrderService - /sapi/v1/margin/order 22 | marginAccountCancelOrder, err := client.NewMarginAccountCancelOrderService().Symbol("BTCUSDT"). 23 | Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(marginAccountCancelOrder)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/margin/MarginAccountNewOCO/MarginAccountNewOCO.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | MarginAccountNewOCO() 12 | } 13 | 14 | func MarginAccountNewOCO() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // MarginAccountNewOCOService - /sapi/v1/margin/order/oco 22 | marginAccountNewOCO, err := client.NewMarginAccountNewOCOService().Symbol("BTCUSDT"). 23 | Side("BUY").Quantity(0.01).Price(20000).StopPrice(18000). 24 | Do(context.Background()) 25 | if err != nil { 26 | fmt.Println(err) 27 | return 28 | } 29 | fmt.Println(binance_connector.PrettyPrint(marginAccountNewOCO)) 30 | } 31 | -------------------------------------------------------------------------------- /examples/margin/MarginAccountNewOTO/MarginAccountNewOTO.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | MarginAccountNewOTO() 12 | } 13 | 14 | func MarginAccountNewOTO() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // MarginAccountNewOTOService - /sapi/v1/margin/order/oto 22 | marginAccountNewOTO, err := client.NewMarginAccountNewOTOService(). 23 | Symbol("BNBUSDT").WorkingType("LIMIT").WorkingSide("BUY").WorkingPrice(600).WorkingQuantity(1). 24 | PendingType("LIMIT").PendingSide("BUY").PendingQuantity(1).WorkingTimeInForce("GTC"). 25 | PendingPrice(595).PendingTimeInForce("GTC").WorkingIcebergQty(0.1).Do(context.Background()) 26 | if err != nil { 27 | fmt.Println(err) 28 | return 29 | } 30 | fmt.Println(binance_connector.PrettyPrint(marginAccountNewOTO)) 31 | } 32 | -------------------------------------------------------------------------------- /examples/margin/MarginAccountNewOTOCO/MarginAccountNewOTOCO.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | MarginAccountNewOTOCO() 12 | } 13 | 14 | func MarginAccountNewOTOCO() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // MarginAccountNewOTOCOService - /sapi/v1/margin/order/otoco 22 | marginAccountNewOTOCO, err := client.NewMarginAccountNewOTOCOService(). 23 | Symbol("BNBUSDT").WorkingType("LIMIT").WorkingSide("BUY").WorkingPrice(600).WorkingQuantity(1). 24 | PendingSide("BUY").PendingQuantity(1).PendingAboveType("LIMIT_MAKER").WorkingTimeInForce("GTC"). 25 | PendingAbovePrice(605).PendingBelowType("LIMIT_MAKER").PendingBelowPrice(595).WorkingIcebergQty(0.1).Do(context.Background()) 26 | if err != nil { 27 | fmt.Println(err) 28 | return 29 | } 30 | fmt.Println(binance_connector.PrettyPrint(marginAccountNewOTOCO)) 31 | } 32 | -------------------------------------------------------------------------------- /examples/margin/MarginAccountNewOrder/MarginAccountNewOrder.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | MarginAccountNewOrder() 12 | } 13 | 14 | func MarginAccountNewOrder() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // MarginAccountNewOrderService - /sapi/v1/margin/order 22 | marginAccountNewOrder, err := client.NewMarginAccountNewOrderService().Symbol("BTCUSDT"). 23 | Side("BUY").OrderType("MARKET").Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(marginAccountNewOrder)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/margin/MarginAccountOpenOrder/MarginAccountOpenOrder.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | MarginAccountOpenOrder() 12 | } 13 | 14 | func MarginAccountOpenOrder() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // MarginAccountOpenOrderService - /sapi/v1/margin/openOrders 22 | marginAccountOpenOrder, err := client.NewMarginAccountOpenOrderService().Symbol("BTCUSDT"). 23 | Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(marginAccountOpenOrder)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/margin/MarginAccountOrder/MarginAccountOrder.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | MarginAccountOrder() 12 | } 13 | 14 | func MarginAccountOrder() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // MarginAccountOrderService - /sapi/v1/margin/order 22 | marginAccountOrder, err := client.NewMarginAccountOrderService().Symbol("BTCUSDT"). 23 | OrderId(1). 24 | Do(context.Background()) 25 | if err != nil { 26 | fmt.Println(err) 27 | return 28 | } 29 | fmt.Println(binance_connector.PrettyPrint(marginAccountOrder)) 30 | } 31 | -------------------------------------------------------------------------------- /examples/margin/MarginAccountQueryAllOCO/MarginAccountQueryAllOCO.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | MarginAccountQueryAllOCO() 12 | } 13 | 14 | func MarginAccountQueryAllOCO() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // MarginAccountQueryAllOCOService - /sapi/v1/margin/allOrderList 22 | marginAccountQueryAllOCO, err := client.NewMarginAccountQueryAllOCOService(). 23 | Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(marginAccountQueryAllOCO)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/margin/MarginAccountQueryMaxBorrow/MarginAccountQueryMaxBorrow.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | MarginAccountQueryMaxBorrow() 12 | } 13 | 14 | func MarginAccountQueryMaxBorrow() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // MarginAccountQueryMaxBorrowService - /sapi/v1/margin/maxBorrowable 22 | marginAccountQueryMaxBorrow, err := client.NewMarginAccountQueryMaxBorrowService().Asset("USDT"). 23 | Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(marginAccountQueryMaxBorrow)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/margin/MarginAccountQueryMaxTransferOutAmount/MarginAccountQueryMaxTransferOut.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | MarginAccountQueryMaxTransferOutAmount() 12 | } 13 | 14 | func MarginAccountQueryMaxTransferOutAmount() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // MarginAccountQueryMaxTransferOutAmountService - /sapi/v1/margin/maxTransferable 22 | marginAccountQueryMaxTransferOutAmount, err := client.NewMarginAccountQueryMaxTransferOutAmountService(). 23 | Asset("USDT").Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(marginAccountQueryMaxTransferOutAmount)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/margin/MarginAccountQueryOCO/MarginAccountQueryOCO.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | MarginAccountQueryOCO() 12 | } 13 | 14 | func MarginAccountQueryOCO() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // MarginAccountQueryOCOService - /sapi/v1/margin/orderList 22 | marginAccountQueryOCO, err := client.NewMarginAccountQueryOCOService().OrigClientOrderId(""). 23 | Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(marginAccountQueryOCO)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/margin/MarginAccountQueryOpenOCO/MarginAccountQueryOpenOCO.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | MarginAccountQueryOpenOCO() 12 | } 13 | 14 | func MarginAccountQueryOpenOCO() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // MarginAccountQueryOpenOCOService - /sapi/v1/margin/openOrderList 22 | marginAccountQueryOpenOCO, err := client.NewMarginAccountQueryOpenOCOService(). 23 | Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(marginAccountQueryOpenOCO)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/margin/MarginAccountQueryTradeList/MarginAccountQueryTradeList.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | MarginAccountQueryTradeList() 12 | } 13 | 14 | func MarginAccountQueryTradeList() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // MarginAccountQueryTradeListService - /sapi/v1/margin/myTrades 22 | marginAccountQueryTradeList, err := client.NewMarginAccountQueryTradeListService().Symbol("BTCUSDT"). 23 | Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(marginAccountQueryTradeList)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/margin/MarginAccountSummary/MarginAccountSummary.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | MarginAccountSummary() 12 | } 13 | 14 | func MarginAccountSummary() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // MarginAccountSummaryService - /sapi/v1/margin/tradeCoeff 22 | marginAccountSummary, err := client.NewMarginAccountSummaryService().Do(context.Background()) 23 | if err != nil { 24 | fmt.Println(err) 25 | return 26 | } 27 | fmt.Println(binance_connector.PrettyPrint(marginAccountSummary)) 28 | } 29 | -------------------------------------------------------------------------------- /examples/margin/MarginBnbBurnStatus/MarginBnbBurnStatus.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | MarginBnbBurnStatus() 12 | } 13 | 14 | func MarginBnbBurnStatus() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // MarginBnbBurnStatusService - /sapi/v1/bnbBurn 22 | marginBnbBurnStatus, err := client.NewMarginBnbBurnStatusService().Do(context.Background()) 23 | if err != nil { 24 | fmt.Println(err) 25 | return 26 | } 27 | fmt.Println(binance_connector.PrettyPrint(marginBnbBurnStatus)) 28 | } 29 | -------------------------------------------------------------------------------- /examples/margin/MarginCrossCollateralRatio/MarginCrossCollateralRatio.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | MarginCrossCollateralRatio() 12 | } 13 | 14 | func MarginCrossCollateralRatio() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // MarginCrossCollateralRatioService - /sapi/v1/margin/crossMarginCollateralRatio 22 | marginCrossCollateralRatio, err := client.NewMarginCrossCollateralRatioService(). 23 | Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(marginCrossCollateralRatio)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/margin/MarginCrossMarginFee/MarginCrossMarginFee.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | MarginCrossMarginFee() 12 | } 13 | 14 | func MarginCrossMarginFee() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // MarginCrossMarginFeeService - /sapi/v1/margin/crossMarginData 22 | marginCrossMarginFee, err := client.NewMarginCrossMarginFeeService(). 23 | Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(marginCrossMarginFee)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/margin/MarginCurrentOrderCount/MarginCurrentOrderCount.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | MarginCurrentOrderCount() 12 | } 13 | 14 | func MarginCurrentOrderCount() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // MarginCurrentOrderCountService - /sapi/v1/margin/rateLimit/order 22 | marginCurrentOrderCount, err := client.NewMarginCurrentOrderCountService(). 23 | Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(marginCurrentOrderCount)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/margin/MarginInterestRateHistory/MarginInterestRateHistory.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | MarginInterestRateHistory() 12 | } 13 | 14 | func MarginInterestRateHistory() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // MarginInterestRateHistoryService - /sapi/v1/margin/interestRateHistory 22 | marginInterestRateHistory, err := client.NewMarginInterestRateHistoryService().Asset("USDT"). 23 | Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(marginInterestRateHistory)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/margin/MarginIsolatedAccountDisable/MarginIsolatedAccountDisable.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | MarginIsolatedAccountDisable() 12 | } 13 | 14 | func MarginIsolatedAccountDisable() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // MarginIsolatedAccountDisableService - /sapi/v1/margin/isolated/account 22 | marginIsolatedAccountDisable, err := client.NewMarginIsolatedAccountDisableService().Symbol("BTCUSDT"). 23 | Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(marginIsolatedAccountDisable)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/margin/MarginIsolatedAccountEnable/MarginisolatedAccountEnable.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | MarginIsolatedAccountEnable() 12 | } 13 | 14 | func MarginIsolatedAccountEnable() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // MarginIsolatedAccountEnableService - /sapi/v1/margin/isolated/account 22 | marginIsolatedAccountEnable, err := client.NewMarginIsolatedAccountEnableService().Symbol("BTCUSDT"). 23 | Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(marginIsolatedAccountEnable)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/margin/MarginIsolatedAccountInfo/MarginIsolatedAccountInfo.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | MarginIsolatedAccountInfo() 12 | } 13 | 14 | func MarginIsolatedAccountInfo() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // MarginIsolatedAccountInfoService - /sapi/v1/margin/isolated/account 22 | marginIsolatedAccountInfo, err := client.NewMarginIsolatedAccountInfoService().Do(context.Background()) 23 | if err != nil { 24 | fmt.Println(err) 25 | return 26 | } 27 | fmt.Println(binance_connector.PrettyPrint(marginIsolatedAccountInfo)) 28 | } 29 | -------------------------------------------------------------------------------- /examples/margin/MarginIsolatedAccountLimit/MarginIsolatedAccountLimit.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | MarginIsolatedAccountLimit() 12 | } 13 | 14 | func MarginIsolatedAccountLimit() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // MarginIsolatedAccountLimitService - /sapi/v1/margin/isolated/accountLimit 22 | marginIsolatedAccountLimit, err := client.NewMarginIsolatedAccountLimitService(). 23 | Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(marginIsolatedAccountLimit)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/margin/MarginIsolatedCapitalFlow/MarginIsolatedCapitalFlow.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | MarginIsolatedCapitalFlow() 12 | } 13 | 14 | func MarginIsolatedCapitalFlow() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // MarginIsolatedCapitalFlowService - /sapi/v1/margin/capital-flow 22 | marginIsolatedCapitalFlow, err := client.NewMarginIsolatedCapitalFlowService().Do(context.Background()) 23 | if err != nil { 24 | fmt.Println(err) 25 | return 26 | } 27 | fmt.Println(binance_connector.PrettyPrint(marginIsolatedCapitalFlow)) 28 | } 29 | -------------------------------------------------------------------------------- /examples/margin/MarginIsolatedMarginFee/MarginIsolatedMarginFee.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | MarginIsolatedMarginFee() 12 | } 13 | 14 | func MarginIsolatedMarginFee() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // MarginIsolatedMarginFeeService - /sapi/v1/margin/isolatedMarginData 22 | marginIsolatedMarginFee, err := client.NewMarginIsolatedMarginFeeService(). 23 | Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(marginIsolatedMarginFee)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/margin/MarginIsolatedMarginTier/MarginIsolatedMarginTier.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | MarginIsolatedMarginTier() 12 | } 13 | 14 | func MarginIsolatedMarginTier() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // MarginIsolatedMarginTierService - /sapi/v1/margin/isolatedMarginTier 22 | marginIsolatedMarginTier, err := client.NewMarginIsolatedMarginTierService(). 23 | Symbol("BTCUSDT").Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(marginIsolatedMarginTier)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/margin/MarginManualLiquidation/MarginManualLiquidation.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | MarginManualLiquidation() 12 | } 13 | 14 | func MarginManualLiquidation() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // MarginManualLiquidationService - /sapi/v1/margin/manual-liquidation 22 | marginManualLiquidation, err := client.NewMarginManualLiquidationService(). 23 | MarginType("MARGIN").Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(marginManualLiquidation)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/margin/MarginSmallLiabilityExchange/MarginSmallLiabilityExchange.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | MarginSmallLiabilityExchange() 12 | } 13 | 14 | func MarginSmallLiabilityExchange() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // MarginSmallLiabilityExchangeService - /sapi/v1/margin/exchange-small-liability 22 | marginSmallLiabilityExchange, err := client.NewMarginSmallLiabilityExchangeService(). 23 | AssetNames("BTC,ETH,BNB").Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(marginSmallLiabilityExchange)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/margin/MarginSmallLiabilityExchangeCoinList/MarginSmallLiabilityExchangeCoinList.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | MarginSmallLiabilityExchangeCoinList() 12 | } 13 | 14 | func MarginSmallLiabilityExchangeCoinList() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // MarginSmallLiabilityExchangeCoinListService - /sapi/v1/margin/exchange-small-liability 22 | marginSmallLiabilityExchangeCoinList, err := client.NewMarginSmallLiabilityExchangeCoinListService(). 23 | Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(marginSmallLiabilityExchangeCoinList)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/margin/MarginSmallLiabilityExchangeHistory/MarginSmallLiabilityExchangeHistory.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | MarginSmallLiabilityExchangeHistory() 12 | } 13 | 14 | func MarginSmallLiabilityExchangeHistory() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // MarginSmallLiabilityExchangeHistoryService - /sapi/v1/margin/exchange-small-liability-history 22 | marginSmallLiabilityExchangeHistory, err := client.NewMarginSmallLiabilityExchangeHistoryService(). 23 | Current(1).Size(10).Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(marginSmallLiabilityExchangeHistory)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/margin/MarginToggleBnbBurn/MarginToggleBnbBurn.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | MarginToggleBnbBurn() 12 | } 13 | 14 | func MarginToggleBnbBurn() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // MarginToggleBnbBurnService - /sapi/v1/bnbBurn 22 | marginToggleBnbBurn, err := client.NewMarginToggleBnbBurnService().Do(context.Background()) 23 | if err != nil { 24 | fmt.Println(err) 25 | return 26 | } 27 | fmt.Println(binance_connector.PrettyPrint(marginToggleBnbBurn)) 28 | } 29 | -------------------------------------------------------------------------------- /examples/margin/QueryLiabilityCoinLeverageBracket/QueryLiabilityCoinLeverageBracket.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | QueryLiabilityCoinLeverageBracket() 12 | } 13 | 14 | func QueryLiabilityCoinLeverageBracket() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // QueryLiabilityCoinLeverageBracketService - /sapi/v1/margin/leverageBracket 22 | queryLiabilityCoinLeverageBracket, err := client.NewQueryLiabilityCoinLeverageBracketService().Do(context.Background()) 23 | if err != nil { 24 | fmt.Println(err) 25 | return 26 | } 27 | fmt.Println(binance_connector.PrettyPrint(queryLiabilityCoinLeverageBracket)) 28 | } 29 | -------------------------------------------------------------------------------- /examples/margin/QueryMarginAvailableInventory/QueryMarginAvailableInventory.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | QueryMarginAvailableInventory() 12 | } 13 | 14 | func QueryMarginAvailableInventory() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // QueryMarginAvailableInventoryService - /sapi/v1/margin/available-inventory 22 | queryMarginAvailableInventory, err := client.NewQueryMarginAvailableInventoryService(). 23 | MarginType("MARGIN").Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(queryMarginAvailableInventory)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/margin/QueryMarginPriceIndex/QueryMarginPriceIndex.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | QueryMarginPriceIndex() 12 | } 13 | 14 | func QueryMarginPriceIndex() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // QueryMarginPriceIndexService - /sapi/v1/margin/priceIndex 22 | queryMarginPriceIndex, err := client.NewQueryMarginPriceIndexService().Symbol("BTCUSDT"). 23 | Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(queryMarginPriceIndex)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/market/AggTradesList/AggTradesList.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | AggTradesList() 12 | } 13 | 14 | func AggTradesList() { 15 | baseURL := "https://api.binance.com" 16 | 17 | client := binance_connector.NewClient("", "", baseURL) 18 | 19 | // AggTradesList 20 | aggTradesList, err := client.NewAggTradesListService(). 21 | Symbol("BTCUSDT").Limit(20).Do(context.Background()) 22 | if err != nil { 23 | fmt.Println(err) 24 | return 25 | } 26 | fmt.Println(binance_connector.PrettyPrint(aggTradesList)) 27 | } 28 | -------------------------------------------------------------------------------- /examples/market/AvgPrice/AvgPrice.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | AvgPrice() 12 | } 13 | 14 | func AvgPrice() { 15 | baseURL := "https://api.binance.com" 16 | 17 | client := binance_connector.NewClient("", "", baseURL) 18 | 19 | // AvgPrice 20 | avgPrice, err := client.NewAvgPriceService(). 21 | Symbol("BTCUSDT").Do(context.Background()) 22 | if err != nil { 23 | fmt.Println(err) 24 | return 25 | } 26 | fmt.Println(binance_connector.PrettyPrint(avgPrice)) 27 | } 28 | -------------------------------------------------------------------------------- /examples/market/ExchangeInfo/ExchangeInfo.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | ExchangeInfo() 12 | } 13 | 14 | func ExchangeInfo() { 15 | baseURL := "https://api.binance.com" 16 | 17 | client := binance_connector.NewClient("", "", baseURL) 18 | 19 | // ExchangeInfo 20 | exchangeInfo, err := client.NewExchangeInfoService().Do(context.Background()) 21 | if err != nil { 22 | fmt.Println(err) 23 | return 24 | } 25 | fmt.Println(binance_connector.PrettyPrint(exchangeInfo)) 26 | } 27 | -------------------------------------------------------------------------------- /examples/market/HistoricalTradeLookup/HistoricalTradeLookup.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | HistoricalTradeLookup() 12 | } 13 | 14 | func HistoricalTradeLookup() { 15 | apiKey := "your api key" 16 | baseURL := "https://api.binance.com" 17 | 18 | client := binance_connector.NewClient(apiKey, "", baseURL) 19 | 20 | historicalTradeLookup, err := client.NewHistoricalTradeLookupService(). 21 | Symbol("BTCUSDT").Do(context.Background()) 22 | if err != nil { 23 | fmt.Println(err) 24 | return 25 | } 26 | fmt.Println(binance_connector.PrettyPrint(historicalTradeLookup)) 27 | } 28 | -------------------------------------------------------------------------------- /examples/market/Klines/Klines.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | Klines() 12 | } 13 | 14 | func Klines() { 15 | baseURL := "https://api.binance.com" 16 | 17 | client := binance_connector.NewClient("", "", baseURL) 18 | 19 | // Klines 20 | klines, err := client.NewKlinesService(). 21 | Symbol("BTCUSDT").Interval("1m").Do(context.Background()) 22 | if err != nil { 23 | fmt.Println(err) 24 | return 25 | } 26 | fmt.Println(binance_connector.PrettyPrint(klines)) 27 | } 28 | -------------------------------------------------------------------------------- /examples/market/OrderBook/OrderBook.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | OrderBook() 12 | } 13 | 14 | func OrderBook() { 15 | baseURL := "https://api.binance.com" 16 | 17 | client := binance_connector.NewClient("", "", baseURL) 18 | 19 | // OrderBook 20 | orderBook, err := client.NewOrderBookService(). 21 | Symbol("BTCUSDT").Do(context.Background()) 22 | if err != nil { 23 | fmt.Println(err) 24 | return 25 | } 26 | fmt.Println(binance_connector.PrettyPrint(orderBook)) 27 | } 28 | -------------------------------------------------------------------------------- /examples/market/Ping/Ping.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | Ping() 12 | } 13 | 14 | func Ping() { 15 | baseURL := "https://api.binance.com" 16 | 17 | client := binance_connector.NewClient("", "", baseURL) 18 | 19 | // NewPingService 20 | ping := client.NewPingService().Do(context.Background()) 21 | if ping == nil { 22 | fmt.Println("Success") 23 | return 24 | } 25 | fmt.Println(binance_connector.PrettyPrint(ping)) 26 | } 27 | -------------------------------------------------------------------------------- /examples/market/RecentTradesList/RecentTradesList.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | RecentTradesList() 12 | } 13 | 14 | func RecentTradesList() { 15 | baseURL := "https://api.binance.com" 16 | 17 | client := binance_connector.NewClient("", "", baseURL) 18 | 19 | // RecentTradesList 20 | recentTradesList, err := client.NewRecentTradesListService(). 21 | Symbol("BTCUSDT").Do(context.Background()) 22 | if err != nil { 23 | fmt.Println(err) 24 | return 25 | } 26 | fmt.Println(binance_connector.PrettyPrint(recentTradesList)) 27 | } 28 | -------------------------------------------------------------------------------- /examples/market/ServerTime/ServerTime.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | ServerTime() 12 | } 13 | 14 | func ServerTime() { 15 | 16 | client := binance_connector.NewClient("", "") 17 | 18 | // set to debug mode 19 | client.Debug = true 20 | 21 | // NewServerTimeService 22 | serverTime, err := client.NewServerTimeService().Do(context.Background()) 23 | if err != nil { 24 | fmt.Println(err) 25 | return 26 | } 27 | fmt.Println(binance_connector.PrettyPrint(serverTime)) 28 | } 29 | -------------------------------------------------------------------------------- /examples/market/Ticker/Ticker.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | Ticker() 12 | } 13 | 14 | func Ticker() { 15 | baseURL := "https://api.binance.com" 16 | 17 | client := binance_connector.NewClient("", "", baseURL) 18 | 19 | // Ticker 20 | ticker, err := client.NewTickerService(). 21 | Symbol("BTCUSDT").Do(context.Background()) 22 | if err != nil { 23 | fmt.Println(err) 24 | return 25 | } 26 | fmt.Println(binance_connector.PrettyPrint(ticker)) 27 | } 28 | -------------------------------------------------------------------------------- /examples/market/Ticker24hr/Ticker24hr.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | Ticker24hr() 12 | } 13 | 14 | func Ticker24hr() { 15 | baseURL := "https://api.binance.com" 16 | 17 | client := binance_connector.NewClient("", "", baseURL) 18 | 19 | // Ticker24hr 20 | ticker24hr, err := client.NewTicker24hrService(). 21 | Symbol("BTCUSDT").Do(context.Background()) 22 | if err != nil { 23 | fmt.Println(err) 24 | return 25 | } 26 | fmt.Println(binance_connector.PrettyPrint(ticker24hr)) 27 | } 28 | -------------------------------------------------------------------------------- /examples/market/TickerBookTicker/TickerBookTicker.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | TickerBookTicker() 12 | } 13 | 14 | func TickerBookTicker() { 15 | baseURL := "https://api.binance.com" 16 | 17 | client := binance_connector.NewClient("", "", baseURL) 18 | 19 | // TickerBookTicker 20 | tickerBookTicker, err := client.NewTickerBookTickerService(). 21 | Symbol("BTCUSDT").Do(context.Background()) 22 | if err != nil { 23 | fmt.Println(err) 24 | return 25 | } 26 | fmt.Println(binance_connector.PrettyPrint(tickerBookTicker)) 27 | } 28 | -------------------------------------------------------------------------------- /examples/market/TickerPrice/TickerPrice.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | TickerPrice() 12 | } 13 | 14 | func TickerPrice() { 15 | baseURL := "https://api.binance.com" 16 | 17 | client := binance_connector.NewClient("", "", baseURL) 18 | 19 | // TickerPrice 20 | tickerPrice, err := client.NewTickerPriceService().Do(context.Background()) 21 | if err != nil { 22 | fmt.Println(err) 23 | return 24 | } 25 | fmt.Println(binance_connector.PrettyPrint(tickerPrice)) 26 | } 27 | -------------------------------------------------------------------------------- /examples/market/UiKlines/UiKlines.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | UiKlines() 12 | } 13 | 14 | func UiKlines() { 15 | baseURL := "https://api.binance.com" 16 | 17 | client := binance_connector.NewClient("", "", baseURL) 18 | 19 | // UiKlines 20 | uiKlines, err := client.NewUIKlinesService(). 21 | Symbol("BTCUSDT").Interval("1m").Do(context.Background()) 22 | if err != nil { 23 | fmt.Println(err) 24 | return 25 | } 26 | fmt.Println(binance_connector.PrettyPrint(uiKlines)) 27 | } 28 | -------------------------------------------------------------------------------- /examples/subaccount/CreateSubAccount/CreateSubAccount.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | CreateSubAccount() 12 | } 13 | 14 | func CreateSubAccount() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // #1 22 | subaccount, err := client.NewCreateSubAccountService().SubAccountString("TestSubaccount1"). 23 | Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(subaccount)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/subaccount/DeleteIPListForSubAccountAPIKey/DeleteIPListForSubAccountAPIKey.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | DeleteIPListForSubAccountAPIKey() 12 | } 13 | 14 | func DeleteIPListForSubAccountAPIKey() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // Delete IP List For a Sub-account API Key (For Master Account) - /sapi/v1/sub-account/subaccountApi/ipRestriction/ipList 22 | deleteIPListForSubAccountAPIKey, err := client.NewDeleteIPListForSubAccountAPIKeyService().Email("email@email.com"). 23 | SubAccountApiKey("123123").IpAddress("127.0.0.1").Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(deleteIPListForSubAccountAPIKey)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/subaccount/DepositAssetsIntoManagedSubAccount/DepositAssetsIntoManagedSubAccount.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | DepositAssetsIntoManagedSubAccount() 12 | } 13 | 14 | func DepositAssetsIntoManagedSubAccount() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // Deposit Assets Into The Managed Sub-account(For Investor Master Account) - /sapi/v1/sub-account/managed-subaccount/deposit 22 | depositAssetsIntoManagedSubAccount, err := client.NewDepositAssetsIntoManagedSubAccountService().ToEmail("to@email.com"). 23 | Asset("BTC").Amount(0.01).Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(depositAssetsIntoManagedSubAccount)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/subaccount/EnableFuturesForSubAccount/EnableFuturesForSubAccount.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | EnableFuturesForSubAccount() 12 | } 13 | 14 | func EnableFuturesForSubAccount() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // Enable Futures for Sub-account (For Master Account) - /sapi/v1/sub-account/futures/enable 22 | enableFuturesForSubAccount, err := client.NewEnableFuturesForSubAccountService().Email("from@email.com"). 23 | Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(enableFuturesForSubAccount)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/subaccount/EnableLeverageTokenForSubAccount/EnableLeverageTokenForSubAccount.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | EnableLeverageTokenForSubAccount() 12 | } 13 | 14 | func EnableLeverageTokenForSubAccount() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // Enable Leverage Token for Sub-account (For Master Account) - /sapi/v1/sub-account/blvt/enable 22 | enableLeverageTokenForSubAccount, err := client.NewEnableLeverageTokenForSubAccountService().Email("email@email.com"). 23 | EnableBlvt(true).Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(enableLeverageTokenForSubAccount)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/subaccount/EnableMarginForSubAccount/EnableMarginForSubAccount.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | EnableMarginForSubAccount() 12 | } 13 | 14 | func EnableMarginForSubAccount() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // Enable Margin for Sub-account (For Master Account) - /sapi/v1/sub-account/margin/enable 22 | enableMarginForSubAccount, err := client.NewEnableMarginForSubAccountService().Email("from@email.com"). 23 | Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(enableMarginForSubAccount)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/subaccount/FuturesTransferForSubAccount/FuturesTransferForSubAccount.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | FuturesTransferForSubAccount() 12 | } 13 | 14 | func FuturesTransferForSubAccount() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // Futures Transfer for Sub-account (For Master Account) - /sapi/v1/sub-account/futures/transfer 22 | futuresTransferForSubAccount, err := client.NewFuturesTransferForSubAccountService().Email("from@email.com").Asset("BTC"). 23 | Amount(0.01).TransferType(1).Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(futuresTransferForSubAccount)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/subaccount/GetDetailOnSubAccountFuturesAccount/GetDetailOnSubAccountFuturesAccount.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | GetDetailOnSubAccountFuturesAccount() 12 | } 13 | 14 | func GetDetailOnSubAccountFuturesAccount() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // Get Detail on Sub-account's Futures Account (For Master Account) - /sapi/v1/sub-account/futures/account 22 | getDetailOnSubAccountFuturesAccount, err := client.NewGetDetailOnSubAccountFuturesAccountService().Email("from@email.com"). 23 | Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(getDetailOnSubAccountFuturesAccount)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/subaccount/GetDetailOnSubAccountFuturesAccountV2/GetDetailOnSubAccountFuturesAccountV2.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | GetDetailOnSubAccountFuturesAccountV2() 12 | } 13 | 14 | func GetDetailOnSubAccountFuturesAccountV2() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // Get Detail on Sub-account's Futures Account V2 (For Master Account) - /sapi/v1/sub-account/futures/internalTransfer 22 | getDetailOnSubAccountFuturesAccountV2, err := client.NewGetDetailOnSubAccountFuturesAccountV2Service().Email("email@email.com"). 23 | FuturesType(1).Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(getDetailOnSubAccountFuturesAccountV2)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/subaccount/GetDetailOnSubAccountMarginAccount/GetDetailOnSubAccountMarginAccount.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | GetDetailOnSubAccountMarginAccount() 12 | } 13 | 14 | func GetDetailOnSubAccountMarginAccount() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // Get Detail on Sub-account's Margin Account (For Master Account) - /sapi/v1/sub-account/margin/account 22 | getDetailOnSubAccountMarginAccount, err := client.NewGetDetailOnSubAccountMarginAccountService().Email("from@email.com"). 23 | Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(getDetailOnSubAccountMarginAccount)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/subaccount/GetFuturesPositionRiskOfSubAccount/GetFuturesPositionRiskOfSubAccount.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | GetFuturesPositionRiskOfSubAccount() 12 | } 13 | 14 | func GetFuturesPositionRiskOfSubAccount() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // Get Futures Position-Risk of Sub-account (For Master Account) - /sapi/v1/sub-account/futures/positionRisk 22 | getFuturesPositionRiskOfSubAccount, err := client.NewGetFuturesPositionRiskOfSubAccountService().Email("from@email.com"). 23 | Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(getFuturesPositionRiskOfSubAccount)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/subaccount/GetFuturesPositionRiskOfSubAccountV2/GetFuturesPositionRiskOfSubAccountV2.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | GetFuturesPositionRiskOfSubAccountV2() 12 | } 13 | 14 | func GetFuturesPositionRiskOfSubAccountV2() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // Get Futures Position-Risk of Sub-account V2 (For Master Account) - /sapi/v1/sub-account/futures/positionRisk 22 | getFuturesPositionRiskOfSubAccountV2, err := client.NewGetFuturesPositionRiskOfSubAccountV2Service().Email("email@email.com"). 23 | FuturesType(1).Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(getFuturesPositionRiskOfSubAccountV2)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/subaccount/GetIPRestrictionForSubAccountAPIKey/GetIPRestrictionForSubAccountAPIKey.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | GetIPRestrictionForSubAccountAPIKey() 12 | } 13 | 14 | func GetIPRestrictionForSubAccountAPIKey() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // Get IP Restriction for a Sub-account API Key (For Master Account) - /sapi/v1/sub-account/subaccountApi/ipRestriction 22 | getIPRestrictionForSubAccountAPIKey, err := client.NewGetIPRestrictionForSubAccountAPIKeyService().Email("email@email.com"). 23 | Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(getIPRestrictionForSubAccountAPIKey)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/subaccount/GetManagedSubAccountDepositAddress/GetManagedSubAccountDepositAddress.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | GetManagedSubAccountDepositAddress() 12 | } 13 | 14 | func GetManagedSubAccountDepositAddress() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // Get Managed Sub-account Deposit Address (For Investor Master Account) - /sapi/v1/managed-subaccount/deposit/address 22 | GetManagedSubAccountDepositAddress, err := client.NewGetManagedSubAccountDepositAddressService().Email("from@email.com"). 23 | Coin("BTC").Network("BTC").Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(GetManagedSubAccountDepositAddress)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/subaccount/GetSubAccountDepositAddress/GetSubAccountDepositAddress.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | GetSubAccountDepositAddress() 12 | } 13 | 14 | func GetSubAccountDepositAddress() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // Get Sub-account Deposit Address (For Master Account) - /sapi/v1/capital/deposit/subAddress 22 | getSubAccountDepositAddress, err := client.NewGetSubAccountDepositAddressService().Email("from@email.com"). 23 | Coin("BTC").Network("BTC").Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(getSubAccountDepositAddress)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/subaccount/GetSubAccountDepositHistory/GetSubAccountDepositHistory.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | GetSubAccountDepositHistory() 12 | } 13 | 14 | func GetSubAccountDepositHistory() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // Get Sub-account Deposit History (For Master Account) - /sapi/v1/capital/deposit/subHisrec 22 | getSubAccountDepositHistory, err := client.NewGetSubAccountDepositHistoryService().Email("from@email.com"). 23 | Coin("BTC").Status(1).StartTime(1234567891011).EndTime(1234567891011).Limit(10).Offset(1).Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(getSubAccountDepositHistory)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/subaccount/GetSubAccountStatus/GetSubAccountStatus.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | GetSubAccountStatus() 12 | } 13 | 14 | func GetSubAccountStatus() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // Get Sub-account's Status on Margin/Futures (For Master Account) - /sapi/v1/sub-account/status 22 | getSubAccountStatus, err := client.NewGetSubAccountStatusService().Email("from@email.com"). 23 | Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(getSubAccountStatus)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/subaccount/GetSummaryOfSubAccountFuturesAccount/GetSummaryOfSubAccountFuturesAccount.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | GetSummaryOfSubAccountFuturesAccount() 12 | } 13 | 14 | func GetSummaryOfSubAccountFuturesAccount() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // Get Summary of Sub-account's Futures Account (For Master Account) - /sapi/v1/sub-account/futures/accountSummary 22 | getSummaryOfSubAccountFuturesAccount, err := client.NewGetSummaryOfSubAccountFuturesAccountService(). 23 | Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(getSummaryOfSubAccountFuturesAccount)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/subaccount/GetSummaryOfSubAccountFuturesAccountV2/GetSummaryOfSubAccountFuturesAccountV2.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | GetSummaryOfSubAccountFuturesAccountV2() 12 | } 13 | 14 | func GetSummaryOfSubAccountFuturesAccountV2() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // Get Summary of Sub-account's Futures Account V2 (For Master Account) - /sapi/v1/sub-account/futures/accountSummary 22 | getSummaryOfSubAccountFuturesAccountV2, err := client.NewGetSummaryOfSubAccountFuturesAccountV2Service().FuturesType(1). 23 | Page(1).Limit(10).Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(getSummaryOfSubAccountFuturesAccountV2)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/subaccount/GetSummaryOfSubAccountMarginAccount/GetSummaryOfSubAccountMarginAccount.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | GetSummaryOfSubAccountMarginAccount() 12 | } 13 | 14 | func GetSummaryOfSubAccountMarginAccount() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // Get Summary of Sub-account's Margin Account (For Master Account) - /sapi/v1/sub-account/margin/accountSummary 22 | getSummaryOfSubAccountMarginAccount, err := client.NewGetSummaryOfSubAccountMarginAccountService(). 23 | Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(getSummaryOfSubAccountMarginAccount)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/subaccount/MarginTransferForSubAccount/MarginTransferForSubAccount.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | MarginTransferForSubAccount() 12 | } 13 | 14 | func MarginTransferForSubAccount() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // Margin Transfer for Sub-account (For Master Account) - /sapi/v1/sub-account/margin/transfer 22 | marginTransferForSubAccount, err := client.NewMarginTransferForSubAccountService().Email("from@email.com").Asset("BTC"). 23 | Amount(0.01).TransferType(1).Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(marginTransferForSubAccount)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/subaccount/QueryManagedSubAccountAssetDetails/QueryManagedSubAccountAssetDetails.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | QueryManagedSubAccountAssetDetails() 12 | } 13 | 14 | func QueryManagedSubAccountAssetDetails() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // Query Managed Sub-account Asset Details(For Investor Master Account)- /sapi/v1/sub-account/managed-subaccount/asset 22 | queryManagedSubAccountAssetDetails, err := client.NewQueryManagedSubAccountAssetDetailsService().Email("email@email.com"). 23 | Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(queryManagedSubAccountAssetDetails)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/subaccount/QueryManagedSubAccountFuturesAssetDetails/QueryManagedSubAccountFuturesAssetDetails.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | QueryManagedSubAccountFuturesAssetDetails() 12 | } 13 | 14 | func QueryManagedSubAccountFuturesAssetDetails() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // Query Managed Sub-account Futures Asset Details(For Investor Master Account)(USER_DATA) 22 | queryManagedSubAccountFuturesAssetDetails, err := client.NewQueryManagedSubAccountFuturesAssetDetailsService().Email("email@email.com"). 23 | Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(queryManagedSubAccountFuturesAssetDetails)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/subaccount/QueryManagedSubAccountList/QueryManagedSubAccountList.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | QueryManagedSubAccountList() 12 | } 13 | 14 | func QueryManagedSubAccountList() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | managedSubAccountList, err := client.NewQueryManagedSubAccountList().Do(context.Background()) 22 | if err != nil { 23 | fmt.Println(err) 24 | return 25 | } 26 | fmt.Println(binance_connector.PrettyPrint(managedSubAccountList)) 27 | } 28 | -------------------------------------------------------------------------------- /examples/subaccount/QueryManagedSubAccountMarginAssetDetails/QueryManagedSubAccountMarginAssetDetails.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | QueryManagedSubAccountMarginAssetDetails() 12 | } 13 | 14 | func QueryManagedSubAccountMarginAssetDetails() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // Query Managed Sub-account Margin Asset Details (For Investor Master Account) (USER_DATA) 22 | queryManagedSubAccountMarginAssetDetails, err := client.NewQueryManagedSubAccountMarginAssetDetailsService().Email("email@email.com"). 23 | Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(queryManagedSubAccountMarginAssetDetails)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/subaccount/QueryManagedSubAccountSnapshot/QueryManagedSubAccountSnapshot.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | QueryManagedSubAccountSnapshot() 12 | } 13 | 14 | func QueryManagedSubAccountSnapshot() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | withdrawAssetsFromTheManagedSubAccount, err := client.NewQueryManagedSubAccountSnapshotService().Email("email@email.com"). 22 | SubType("BTC").StartTime(123123123).EndTime(123132123).Limit(10).Do(context.Background()) 23 | if err != nil { 24 | fmt.Println(err) 25 | return 26 | } 27 | fmt.Println(binance_connector.PrettyPrint(withdrawAssetsFromTheManagedSubAccount)) 28 | } 29 | -------------------------------------------------------------------------------- /examples/subaccount/QueryManagedSubAccountTransferLog/QueryManagedSubAccountTransferLog.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | QueryManagedSubAccountTransferLog() 12 | } 13 | 14 | func QueryManagedSubAccountTransferLog() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // Query Managed Sub Account Transfer Log (Investor) (USER_DATA) 22 | queryManagedSubAccountTransferLog, err := client.NewQueryManagedSubAccountTransferLogService().Email("email@email.com"). 23 | StartTime(123123).EndTime(123123).Page(1).Limit(10).Transfers("").TransferFunctionAccountType("").Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(queryManagedSubAccountTransferLog)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/subaccount/QueryManagedSubAccountTransferLogForTradingTeam/QueryManagedSubAccountTransferLogForTradingTeam.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | QueryManagedSubAccountTransferLogForTradingTeam() 12 | } 13 | 14 | func QueryManagedSubAccountTransferLogForTradingTeam() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // Query Managed Sub Account Transfer Log (Trading Team) (USER_DATA) 22 | queryManagedSubAccountTransferLogForTradingTeam, err := client.NewQueryManagedSubAccountTransferLogForTradingTeamService().Email("email@email.com"). 23 | StartTime(123123).EndTime(123123).Page(1).Limit(10).Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(queryManagedSubAccountTransferLogForTradingTeam)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/subaccount/QuerySubAccountAssets/QuerySubAccountAssets.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | QuerySubAccountAssets() 12 | } 13 | 14 | func QuerySubAccountAssets() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // Query Sub-account Assets (For Master Account) - /sapi/v3/sub-account/assets 22 | querySubAccountAssets, err := client.NewQuerySubAccountAssetsService().Email("from@email.com"). 23 | Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(querySubAccountAssets)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/subaccount/QuerySubAccountAssetsForMasterAccount/QuerySubAccountAssetsForMasterAccount.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | QuerySubAccountAssetsForMasterAccount() 12 | } 13 | 14 | func QuerySubAccountAssetsForMasterAccount() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // Query Sub-account Assets (For Master Account)(USER_DATA) 22 | querySubAccountAssetsForMasterAccount, err := client.NewQuerySubAccountAssetsService().Email("from@email.com"). 23 | Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(querySubAccountAssetsForMasterAccount)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/subaccount/QuerySubAccountSpotAssetsSummary/QuerySubAccountSpotAssetsSummary.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | QuerySubAccountSpotAssetsSummary() 12 | } 13 | 14 | func QuerySubAccountSpotAssetsSummary() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // Query Sub-account Spot Assets Summary (For Master Account) - /sapi/v1/sub-account/spotSummary 22 | querySubAccountSpotAssetsSummary, err := client.NewQuerySubAccountSpotAssetsSummaryService().Email("from@email.com"). 23 | Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(querySubAccountSpotAssetsSummary)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/subaccount/QuerySubAccountTransactionTatistics/QuerySubAccountTransactionTatistics.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | QuerySubAccountTransactionTatistics() 12 | } 13 | 14 | func QuerySubAccountTransactionTatistics() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | transactionTatistics, err := client.NewQuerySubAccountTransactionTatistics().Email("email@email.com").Do(context.Background()) 22 | if err != nil { 23 | fmt.Println(err) 24 | return 25 | } 26 | fmt.Println(binance_connector.PrettyPrint(transactionTatistics)) 27 | } 28 | -------------------------------------------------------------------------------- /examples/subaccount/QueryUniversalTransferHistory/QueryUniversalTransferHistory.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | QueryUniversalTransferHistory() 12 | } 13 | 14 | func QueryUniversalTransferHistory() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // Query Universal Transfer History (For Master Account) - /sapi/v1/asset/universalTransfer 22 | queryUniversalTransferHistory, err := client.NewQueryUniversalTransferHistoryService().FromEmail("from@email.com"). 23 | ToEmail("to@email.com").ClientTranId("123123").StartTime(1234567891011).EndTime(1234567891011). 24 | Page(1).Limit(10).Do(context.Background()) 25 | if err != nil { 26 | fmt.Println(err) 27 | return 28 | } 29 | fmt.Println(binance_connector.PrettyPrint(queryUniversalTransferHistory)) 30 | } 31 | -------------------------------------------------------------------------------- /examples/subaccount/SubAccountFuturesAssetTransfer/SubAccountFuturesAssetTransfer.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | SubAccountFuturesAssetTransfer() 12 | } 13 | 14 | func SubAccountFuturesAssetTransfer() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // Sub-account Futures Asset Transfer (For Master Account) - /sapi/v1/sub-account/futures/internalTransfer 22 | subaccountFuturesAssetTransfer, err := client.NewSubAccountFuturesAssetTransferService().FromEmail("from@email.com"). 23 | ToEmail("to@email.com").FuturesType(1).Asset("BTC").Amount(0.01).Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(subaccountFuturesAssetTransfer)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/subaccount/SubAccountFuturesAssetTransferHistory/SubAccountFuturesAssetTransferHistory.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | SubAccountFuturesAssetTransferHistory() 12 | } 13 | 14 | func SubAccountFuturesAssetTransferHistory() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // Query Sub-account Futures Asset Transfer History (For Master Account) - /sapi/v1/sub-account/futures/internalTransfer 22 | subaccountFuturesAssetTransferHistory, err := client.NewQuerySubAccountFuturesAssetTransferHistoryService().Email("from@email.com"). 23 | FuturesType(1).StartTime(1234567891011).EndTime(1).Page(1).Limit(10).Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(subaccountFuturesAssetTransferHistory)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/subaccount/SubAccountList/SubAccountList.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | SubAccountList() 12 | } 13 | 14 | func SubAccountList() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // Query Sub-account List (For Master Account) - /sapi/v1/sub-account/list 22 | subaccountList, err := client.NewQuerySubAccountListService().Email("test@email.com"). 23 | IsFreeze("").Page(1).Limit(10).Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(subaccountList)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/subaccount/SubAccountSpotAssetTransferHistory/SubAccountSpotAssetTransferHistory.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | SubAccountSpotAssetTransferHistory() 12 | } 13 | 14 | func SubAccountSpotAssetTransferHistory() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // Query Sub-account Spot Asset Transfer History (For Master Account) - /sapi/v1/sub-account/sub/transfer/history 22 | subaccountSpotAssetTransferHistory, err := client.NewQuerySubAccountSpotAssetTransferHistoryService().FromEmail("from@email.com"). 23 | ToEmail("to@email.com").StartTime(1234567891011).EndTime(1).Page(1).Limit(10).Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(subaccountSpotAssetTransferHistory)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/subaccount/SubAccountTransferHistory/SubAccountTransferHistory.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | SubAccountTransferHistory() 12 | } 13 | 14 | func SubAccountTransferHistory() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // Sub-account Transfer History (For Sub-account) - /sapi/v1/sub-account/transfer/subUserHistory 22 | subAccountTransferHistory, err := client.NewSubAccountTransferHistoryService().Asset("BTC"). 23 | TransferType(1).StartTime(1234567891011).EndTime(1234567891011).Limit(10).Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(subAccountTransferHistory)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/subaccount/TransferToMaster/TransferToMaster.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | TransferToMaster() 12 | } 13 | 14 | func TransferToMaster() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // Transfer to Master (For Sub-account) - /sapi/v1/sub-account/transfer/subToMaster 22 | transferToMaster, err := client.NewTransferToMasterService().Asset("BTC"). 23 | Amount(0.01).Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(transferToMaster)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/subaccount/TransferToSubAccountOfSameMaster/TransferToSubAccountOfSameMaster.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | TransferToSubAccountOfSameMaster() 12 | } 13 | 14 | func TransferToSubAccountOfSameMaster() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // Transfer to Sub-account of Same Master (For Sub-account) - /sapi/v1/sub-account/transfer/subToSub 22 | transferToSubAccountOfSameMaster, err := client.NewTransferToSubAccountOfSameMasterService().ToEmail("from@email.com").Asset("BTC"). 23 | Amount(0.01).Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(transferToSubAccountOfSameMaster)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/subaccount/UniversalTransfer/UniversalTransfer.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | UniversalTransfer() 12 | } 13 | 14 | func UniversalTransfer() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // Universal Transfer (For Master Account) - /sapi/v1/asset/universalTransfer 22 | universalTransfer, err := client.NewUniversalTransferService().FromEmail("from@email.com").ToEmail("to@email.com"). 23 | FromAccountType("SPOT").ToAccountType("SPOT").ClientTranId("123123").Symbol("BTC").Asset("BTC").Amount(0.01).Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(universalTransfer)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/subaccount/UpdateIPRestrictionForSubAccountAPIKey/UpdateIPRestrictionForSubAccountAPIKey.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | UpdateIPRestrictionForSubAccountAPIKey() 12 | } 13 | 14 | func UpdateIPRestrictionForSubAccountAPIKey() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // Update IP Restriction for Sub-Account API key (For Master Account) - /sapi/v2/sub-account/subaccountApi/ipRestriction 22 | updateIPRestrictionForSubAccountAPIKey, err := client.NewUpdateIPRestrictionForSubAccountAPIKeyService().Email("email@email.com"). 23 | SubAccountApiKey("123123").Status("").IpAddress("127.0.0.1").Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(updateIPRestrictionForSubAccountAPIKey)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/subaccount/WithdrawAssetsFromTheManagedSubAccount/WithdrawAssetsFromTheManagedSubAccount.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | WithdrawAssetsFromTheManagedSubAccount() 12 | } 13 | 14 | func WithdrawAssetsFromTheManagedSubAccount() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | withdrawAssetsFromTheManagedSubAccount, err := client.NewWithdrawAssetsFromTheManagedSubAccountService().FromEmail("email@email.com"). 22 | Asset("BTC").Amount(1.5).TransferDate(123132123).Do(context.Background()) 23 | if err != nil { 24 | fmt.Println(err) 25 | return 26 | } 27 | fmt.Println(binance_connector.PrettyPrint(withdrawAssetsFromTheManagedSubAccount)) 28 | } 29 | -------------------------------------------------------------------------------- /examples/user_stream/CloseUserStream/CloseUserStream.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | CloseUserStream() 12 | } 13 | 14 | func CloseUserStream() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | close := client.NewCloseUserStream().ListenKey("your_listen_key"). 22 | Do(context.Background()) 23 | fmt.Println(close) 24 | } 25 | -------------------------------------------------------------------------------- /examples/user_stream/CreateNewListenKey/CreateListenKey.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | CreateNewListenKey() 12 | } 13 | 14 | func CreateNewListenKey() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | listenKey, err := client.NewCreateListenKeyService(). 22 | Do(context.Background()) 23 | if err != nil { 24 | fmt.Println(err) 25 | return 26 | } 27 | fmt.Println(listenKey) 28 | } 29 | -------------------------------------------------------------------------------- /examples/user_stream/PingUserStream/PingUserStream.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | PingUserStream() 12 | } 13 | 14 | func PingUserStream() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | ping := client.NewPingUserStream().ListenKey("your_listen_key").Do(context.Background()) 22 | fmt.Println(ping) 23 | } 24 | -------------------------------------------------------------------------------- /examples/wallet/APIKeyPermission/APIKeyPermission.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | APIKeyPermission() 12 | } 13 | 14 | func APIKeyPermission() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // APIKeyPermissionService - /sapi/v1/account/apiRestrictions 22 | apiKeyPermission, err := client.NewAPIKeyPermissionService().Do(context.Background()) 23 | if err != nil { 24 | fmt.Println(err) 25 | return 26 | } 27 | fmt.Println(binance_connector.PrettyPrint(apiKeyPermission)) 28 | } 29 | -------------------------------------------------------------------------------- /examples/wallet/AccountAPITradingStatus/AccountAPITradingStatus.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | AccountApiTradingStatus() 12 | } 13 | 14 | func AccountApiTradingStatus() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // AccountApiTradingStatusService - /sapi/v1/account/apiTradingStatus 22 | accountApiTradingStatus, err := client.NewAccountApiTradingStatusService(). 23 | Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(accountApiTradingStatus)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/wallet/AccountInfo/AccountInfo.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | AccountInfo() 12 | } 13 | 14 | func AccountInfo() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // AccountInfoService - /sapi/v1/account/apiTradingStatus 22 | accountInfo, err := client.NewAccountInfoService(). 23 | Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(accountInfo)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/wallet/AccountStatus/AccountStatus.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | AccountStatus() 12 | } 13 | 14 | func AccountStatus() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // AccountStatusService - /sapi/v1/account/status 22 | accountStatus, err := client.NewAccountStatusService().Do(context.Background()) 23 | if err != nil { 24 | fmt.Println(err) 25 | return 26 | } 27 | fmt.Println(binance_connector.PrettyPrint(accountStatus)) 28 | } 29 | -------------------------------------------------------------------------------- /examples/wallet/AssetDetail/AssetDetail.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | AssetDetail() 12 | } 13 | 14 | func AssetDetail() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // AssetDetailService - /sapi/v1/asset/dust-btc 22 | assetDetail, err := client.NewAssetDetailService().Do(context.Background()) 23 | if err != nil { 24 | fmt.Println(err) 25 | return 26 | } 27 | fmt.Println(binance_connector.PrettyPrint(assetDetail)) 28 | } 29 | -------------------------------------------------------------------------------- /examples/wallet/AssetDetailV2/AssetDetailV2.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | AssetDetailV2() 12 | } 13 | 14 | func AssetDetailV2() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // AssetDetailV2Service - /sapi/v1/asset/assetDetail 22 | assetDetailV2, err := client.NewAssetDetailV2Service().Asset("BTC"). 23 | Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(assetDetailV2)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/wallet/AssetDividendRecord/AssetDividendRecord.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | AssetDividendRecord() 12 | } 13 | 14 | func AssetDividendRecord() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // AssetDividendRecordService - /sapi/v1/asset/assetDividend 22 | assetDividendRecord, err := client.NewAssetDividendRecordService().Asset("BTC"). 23 | Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(assetDividendRecord)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/wallet/BUSDConvertHistory/BUSDConvertHistory.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | BUSDConvertHistory() 12 | } 13 | 14 | func BUSDConvertHistory() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // BUSDConvertHistoryService - /sapi/v1/asset/convert-transfer/queryByPage 22 | bUSDConvertHistory, err := client.NewBUSDConvertHistoryService(). 23 | StartTime(1664442061000).EndTime(1664442078000).Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(bUSDConvertHistory)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/wallet/CloudMiningPaymentHistory/CloudMiningPaymentHistory.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | CloudMiningPaymentHistory() 12 | } 13 | 14 | func CloudMiningPaymentHistory() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // CloudMiningPaymentHistoryService - /sapi/v1/asset/ledger-transfer/cloud-mining/queryByPage 22 | cloudMiningPaymentHistory, err := client.NewCloudMiningPaymentHistoryService(). 23 | StartTime(1664442061000).EndTime(1664442078000).Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(cloudMiningPaymentHistory)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/wallet/DepositAddress/DepositAddress.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | DepositAddress() 12 | } 13 | 14 | func DepositAddress() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // DepositAddressService - /sapi/v1/capital/deposit/address 22 | depositAddress, err := client.NewDepositAddressService().Coin("BTC"). 23 | Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(depositAddress)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/wallet/DepositAddressList/DepositAddressList.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | DepositAddressList() 12 | } 13 | 14 | func DepositAddressList() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // DepositAddressListService - /sapi/v1/capital/deposit/address/list 22 | depositAddressList, err := client.NewDepositAddressListService().Coin("BTC"). 23 | Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(depositAddressList)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/wallet/DepositHistory/DepositHistory.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | DepositHistory() 12 | } 13 | 14 | func DepositHistory() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // DepositHistoryService - /sapi/v1/capital/deposit/hisrec 22 | depositHistory, err := client.NewDepositHistoryService().Coin("BTC"). 23 | Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(depositHistory)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/wallet/DisableFastWithdrawSwitch/DisableFastWithdrawSwitch.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | DisableFastWithdrawSwitch() 12 | } 13 | 14 | func DisableFastWithdrawSwitch() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // DisableFastWithdrawSwitchService - /sapi/v1/account/disableFastWithdrawSwitch 22 | disableFastWithdrawSwitch, err := client.NewDisableFastWithdrawSwitchService(). 23 | Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(disableFastWithdrawSwitch)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/wallet/DustLog/DustLog.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | DustLog() 12 | } 13 | 14 | func DustLog() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // DustLogService - /sapi/v1/asset/dribblet 22 | dustLog, err := client.NewDustLogService().Do(context.Background()) 23 | if err != nil { 24 | fmt.Println(err) 25 | return 26 | } 27 | fmt.Println(binance_connector.PrettyPrint(dustLog)) 28 | } 29 | -------------------------------------------------------------------------------- /examples/wallet/DustTransfer/DustTransfer.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | DustTransfer() 12 | } 13 | 14 | func DustTransfer() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // DustTransferService - /sapi/v1/asset/dust 22 | dustTransfer, err := client.NewDustTransferService().Asset([]string{"ETH", "LTC", "TRX"}). 23 | Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(dustTransfer)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/wallet/EnableFastWithdrawSwitch/EnableFastWithdrawSwitch.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | EnableFastWithdrawSwitchService() 12 | } 13 | 14 | func EnableFastWithdrawSwitchService() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // EnableFastWithdrawSwitchService - /sapi/v1/account/enableFastWithdrawSwitch 22 | res, err := client.NewEnableFastWithdrawSwitchService(). 23 | Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(res)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/wallet/FundingWallet/FundingWallet.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | FundingWallet() 12 | } 13 | 14 | func FundingWallet() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // FundingWalletService - /sapi/v1/asset/get-funding-asset 22 | fundingWallet, err := client.NewFundingWalletService().Asset("BTC"). 23 | Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(fundingWallet)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/wallet/GetAccountSnapshot/GetAccountSnapshot.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | AccountSnapshot() 12 | } 13 | 14 | func AccountSnapshot() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // GetAccountSnapshotService get all orders from account - /sapi/v1/accountSnapshot 22 | accountSnapshot, err := client.NewGetAccountSnapshotService().MarketType("SPOT"). 23 | Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(accountSnapshot)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/wallet/GetAllCoinsInfo/GetAllCoinsInfo.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | AllCoinsInfo() 12 | } 13 | 14 | func AllCoinsInfo() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // GetAllCoinsInfoService - /sapi/v1/capital/config/getall 22 | allCoinsInfo, err := client.NewGetAllCoinsInfoService().Do(context.Background()) 23 | if err != nil { 24 | fmt.Println(err) 25 | return 26 | } 27 | fmt.Println(binance_connector.PrettyPrint(allCoinsInfo)) 28 | } 29 | -------------------------------------------------------------------------------- /examples/wallet/GetSymbolsDelistSchedule/GetSymbolsDelistSchedule.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | GetSymbolsDelistSchedule() 12 | } 13 | 14 | func GetSymbolsDelistSchedule() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // GetSymbolsDelistScheduleService - /sapi/v1/spot/delist-schedule 22 | getSymbolsDelistSchedule, err := client.NewGetSymbolsDelistScheduleService().Do(context.Background()) 23 | if err != nil { 24 | fmt.Println(err) 25 | return 26 | } 27 | fmt.Println(binance_connector.PrettyPrint(getSymbolsDelistSchedule)) 28 | } 29 | -------------------------------------------------------------------------------- /examples/wallet/GetSystemStatus/GetSystemStatus.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | GetSystemStatus() 12 | } 13 | 14 | func GetSystemStatus() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // GetSystemStatusService get account info - /sapi/v1/system/status 22 | systemStatus, err := client.NewGetSystemStatusService().Do(context.Background()) 23 | if err != nil { 24 | fmt.Println(err) 25 | return 26 | } 27 | fmt.Println(binance_connector.PrettyPrint(systemStatus)) 28 | } 29 | -------------------------------------------------------------------------------- /examples/wallet/TradeFee/TradeFee.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | TradeFee() 12 | } 13 | 14 | func TradeFee() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // TradeFeeService - /sapi/v1/asset/tradeFee 22 | tradeFee, err := client.NewTradeFeeService().Symbol("BTC"). 23 | Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(tradeFee)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/wallet/UserAsset/UserAsset.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | UserAsset() 12 | } 13 | 14 | func UserAsset() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // UserAssetService - /sapi/v3/asset/getUserAsset 22 | userAsset, err := client.NewUserAssetService().Asset("BTC"). 23 | Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(userAsset)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/wallet/UserDelegationHistory/UserDelegationHistory.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | UserDelegationHistory() 12 | } 13 | 14 | func UserDelegationHistory() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // UserDelegationHistoryService - /sapi/v1/asset/custody/transfer-history 22 | userDelegationHistory, err := client.NewUserDelegationHistoryService(). 23 | Email("email@email.com").StartTime(1664442061000).EndTime(1664442078000).Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(userDelegationHistory)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/wallet/UserUniversalTransfer/UserUniversalTransfer.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | UserUniversalTransfer() 12 | } 13 | 14 | func UserUniversalTransfer() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // UserUniversalTransferService - /sapi/v1/asset/transfer 22 | userUniversalTransfer, err := client.NewUserUniversalTransferService(). 23 | TransferType("MAIN_UMFUTURE").Asset("USDT").Amount(20.50).Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(userUniversalTransfer)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/wallet/UserUniversalTransferHistory/UserUniversalTransferHistory.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | UserUniversalTransferHistory() 12 | } 13 | 14 | func UserUniversalTransferHistory() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // UserUniversalTransferHistoryService - /sapi/v1/asset/transfer 22 | userUniversalTransferHistory, err := client.NewUserUniversalTransferHistoryService(). 23 | TransferType("MAIN_UMFUTURE").Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(userUniversalTransferHistory)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/wallet/WalletBalance/WalletBalance.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | WalletBalance() 12 | } 13 | 14 | func WalletBalance() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // WalletBalanceService - /sapi/v1/asset/wallet/balance 22 | walletBalance, err := client.NewWalletBalanceService().Do(context.Background()) 23 | if err != nil { 24 | fmt.Println(err) 25 | return 26 | } 27 | fmt.Println(binance_connector.PrettyPrint(walletBalance)) 28 | } 29 | -------------------------------------------------------------------------------- /examples/wallet/Withdraw/Withdraw.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | Withdraw() 12 | } 13 | 14 | func Withdraw() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // WithdrawService - /sapi/v1/capital/withdraw/apply 22 | withdraw, err := client.NewWithdrawService().Coin("BTC").Address("123123123"). 23 | Amount(0.01).Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(withdraw)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/wallet/WithdrawHistory/WithdrawHistory.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | WithdrawHistory() 12 | } 13 | 14 | func WithdrawHistory() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | // WithdrawHistoryService - /sapi/v1/capital/withdraw/history 22 | withdrawHistory, err := client.NewWithdrawHistoryService(). 23 | Do(context.Background()) 24 | if err != nil { 25 | fmt.Println(err) 26 | return 27 | } 28 | fmt.Println(binance_connector.PrettyPrint(withdrawHistory)) 29 | } 30 | -------------------------------------------------------------------------------- /examples/websocket/AllMarketMiniTickers/AllMarketMiniTickers.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "time" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | WsAllMarketMiniTickers() 12 | } 13 | 14 | func WsAllMarketMiniTickers() { 15 | websocketStreamClient := binance_connector.NewWebsocketStreamClient(false) 16 | wsAllMarketMiniTickersHandler := func(event binance_connector.WsAllMarketMiniTickersStatEvent) { 17 | fmt.Println(binance_connector.PrettyPrint(event)) 18 | } 19 | errHandler := func(err error) { 20 | fmt.Println(err) 21 | } 22 | doneCh, stopCh, err := websocketStreamClient.WsAllMarketMiniTickersStatServe(wsAllMarketMiniTickersHandler, errHandler) 23 | if err != nil { 24 | fmt.Println(err) 25 | return 26 | } 27 | // use stopCh to exit 28 | go func() { 29 | time.Sleep(10 * time.Second) 30 | stopCh <- struct{}{} 31 | }() 32 | <-doneCh 33 | } 34 | -------------------------------------------------------------------------------- /examples/websocket/AllMarketTickers/AllMarketTickers.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "time" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | WsAllMarketTickersExample() 12 | } 13 | 14 | func WsAllMarketTickersExample() { 15 | websocketStreamClient := binance_connector.NewWebsocketStreamClient(false) 16 | wsAllMarketTickersHandler := func(event binance_connector.WsAllMarketTickersStatEvent) { 17 | fmt.Println(binance_connector.PrettyPrint(event)) 18 | } 19 | errHandler := func(err error) { 20 | fmt.Println(err) 21 | } 22 | doneCh, stopCh, err := websocketStreamClient.WsAllMarketTickersStatServe(wsAllMarketTickersHandler, errHandler) 23 | if err != nil { 24 | fmt.Println(err) 25 | return 26 | } 27 | // use stopCh to exit 28 | go func() { 29 | time.Sleep(10 * time.Second) 30 | stopCh <- struct{}{} 31 | }() 32 | <-doneCh 33 | } 34 | -------------------------------------------------------------------------------- /examples/websocket/CombinedDepth/CombinedDepth.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "time" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | WsCombinedDepthHandlerExample() 12 | } 13 | 14 | func WsCombinedDepthHandlerExample() { 15 | websocketStreamClient := binance_connector.NewWebsocketStreamClient(true) 16 | wsCombinedDepthHandler := func(event *binance_connector.WsDepthEvent) { 17 | fmt.Println(binance_connector.PrettyPrint(event)) 18 | } 19 | errHandler := func(err error) { 20 | fmt.Println(err) 21 | } 22 | doneCh, stopCh, err := websocketStreamClient.WsCombinedDepthServe([]string{"LTCBTC", "BTCUSDT", "MATICUSDT"}, wsCombinedDepthHandler, errHandler) 23 | if err != nil { 24 | fmt.Println(err) 25 | return 26 | } 27 | // use stopCh to exit 28 | go func() { 29 | time.Sleep(10 * time.Second) 30 | stopCh <- struct{}{} 31 | }() 32 | // remove this if you do not want to be blocked here 33 | <-doneCh 34 | } 35 | -------------------------------------------------------------------------------- /examples/websocket/MarketMiniTickers/MarketMiniTickers.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "time" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | WsMarketMiniTickers() 12 | } 13 | 14 | func WsMarketMiniTickers() { 15 | websocketStreamClient := binance_connector.NewWebsocketStreamClient(false) 16 | wsMarketMiniTickersHandler := func(event binance_connector.WsMarketMiniTickerStatEvent) { 17 | fmt.Println(binance_connector.PrettyPrint(event)) 18 | } 19 | errHandler := func(err error) { 20 | fmt.Println(err) 21 | } 22 | doneCh, stopCh, err := websocketStreamClient.WsMarketMiniTickersStatServe("BNBBTC", wsMarketMiniTickersHandler, errHandler) 23 | if err != nil { 24 | fmt.Println(err) 25 | return 26 | } 27 | // use stopCh to exit 28 | go func() { 29 | time.Sleep(10 * time.Second) 30 | stopCh <- struct{}{} 31 | }() 32 | <-doneCh 33 | } 34 | -------------------------------------------------------------------------------- /examples/websocket/UserDataStream/UserDataStream.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | WsUserData() 12 | } 13 | 14 | func WsUserData() { 15 | apiKey := "your api key" 16 | secretKey := "your secret key" 17 | baseURL := "https://api.binance.com" 18 | 19 | client := binance_connector.NewClient(apiKey, secretKey, baseURL) 20 | 21 | listenKey, err := client.NewCreateListenKeyService(). 22 | Do(context.Background()) 23 | if err != nil { 24 | fmt.Println(err) 25 | return 26 | } 27 | 28 | websocketStreamClient := binance_connector.NewWebsocketStreamClient(false) 29 | 30 | wsUserDataHandler := func(event *binance_connector.WsUserDataEvent) { 31 | fmt.Println(binance_connector.PrettyPrint(event)) 32 | } 33 | errHandler := func(err error) { 34 | fmt.Println(err) 35 | } 36 | doneCh, _, err := websocketStreamClient.WsUserDataServe(listenKey, wsUserDataHandler, errHandler) 37 | if err != nil { 38 | fmt.Println(err) 39 | return 40 | } 41 | <-doneCh 42 | } 43 | -------------------------------------------------------------------------------- /examples/websocket/aggtrades/aggtrades.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "time" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | AggTradesExample() 12 | } 13 | 14 | func AggTradesExample() { 15 | // Initialise Websocket Client with Testnet base URL and false for "isCombined" parameter 16 | websocketStreamClient := binance_connector.NewWebsocketStreamClient(false, "wss://stream.testnet.binance.vision") 17 | 18 | wsAggTradeHandler := func(event *binance_connector.WsAggTradeEvent) { 19 | fmt.Println(binance_connector.PrettyPrint(event)) 20 | } 21 | errHandler := func(err error) { 22 | fmt.Println(err) 23 | } 24 | doneCh, stopCh, err := websocketStreamClient.WsAggTradeServe("BTCUSDT", wsAggTradeHandler, errHandler) 25 | if err != nil { 26 | fmt.Println(err) 27 | return 28 | } 29 | // use stopCh to exit 30 | go func() { 31 | time.Sleep(10 * time.Second) 32 | stopCh <- struct{}{} 33 | }() 34 | <-doneCh 35 | } 36 | -------------------------------------------------------------------------------- /examples/websocket/bookticker/bookticker.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "time" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | WsBookTickerExample() 12 | } 13 | 14 | func WsBookTickerExample() { 15 | websocketStreamClient := binance_connector.NewWebsocketStreamClient(false) 16 | wsBookTickerHandler := func(event *binance_connector.WsBookTickerEvent) { 17 | fmt.Println(binance_connector.PrettyPrint(event)) 18 | } 19 | errHandler := func(err error) { 20 | fmt.Println(err) 21 | } 22 | doneCh, stopCh, err := websocketStreamClient.WsBookTickerServe("LTCBTC", wsBookTickerHandler, errHandler) 23 | if err != nil { 24 | fmt.Println(err) 25 | return 26 | } 27 | // use stopCh to exit 28 | go func() { 29 | time.Sleep(10 * time.Second) 30 | stopCh <- struct{}{} 31 | }() 32 | <-doneCh 33 | } 34 | -------------------------------------------------------------------------------- /examples/websocket/depth/depth.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "time" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | WsDepthHandlerExample() 12 | } 13 | 14 | func WsDepthHandlerExample() { 15 | websocketStreamClient := binance_connector.NewWebsocketStreamClient(false) 16 | wsDepthHandler := func(event *binance_connector.WsDepthEvent) { 17 | fmt.Println(binance_connector.PrettyPrint(event)) 18 | } 19 | errHandler := func(err error) { 20 | fmt.Println(err) 21 | } 22 | doneCh, stopCh, err := websocketStreamClient.WsDepthServe("LTCBTC", wsDepthHandler, errHandler) 23 | if err != nil { 24 | fmt.Println(err) 25 | return 26 | } 27 | // use stopCh to exit 28 | go func() { 29 | time.Sleep(10 * time.Second) 30 | stopCh <- struct{}{} 31 | }() 32 | // remove this if you do not want to be blocked here 33 | <-doneCh 34 | } 35 | -------------------------------------------------------------------------------- /examples/websocket/kline/kline.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "time" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | WsKlineExample() 12 | } 13 | 14 | func WsKlineExample() { 15 | websocketStreamClient := binance_connector.NewWebsocketStreamClient(false) 16 | wsKlineHandler := func(event *binance_connector.WsKlineEvent) { 17 | fmt.Println(binance_connector.PrettyPrint(event)) 18 | } 19 | errHandler := func(err error) { 20 | fmt.Println(err) 21 | } 22 | doneCh, stopCh, err := websocketStreamClient.WsKlineServe("LTCBTC", "1m", wsKlineHandler, errHandler) 23 | if err != nil { 24 | fmt.Println(err) 25 | return 26 | } 27 | // use stopCh to exit 28 | go func() { 29 | time.Sleep(10 * time.Second) 30 | stopCh <- struct{}{} 31 | }() 32 | <-doneCh 33 | } 34 | -------------------------------------------------------------------------------- /examples/websocket/trades/trades.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "time" 6 | 7 | binance_connector "github.com/binance/binance-connector-go" 8 | ) 9 | 10 | func main() { 11 | WsTradeExample() 12 | } 13 | 14 | func WsTradeExample() { 15 | websocketStreamClient := binance_connector.NewWebsocketStreamClient(false) 16 | wsTradeHandler := func(event *binance_connector.WsTradeEvent) { 17 | fmt.Println(binance_connector.PrettyPrint(event)) 18 | } 19 | errHandler := func(err error) { 20 | fmt.Println(err) 21 | } 22 | doneCh, stopCh, err := websocketStreamClient.WsTradeServe("LTCBTC", wsTradeHandler, errHandler) 23 | if err != nil { 24 | fmt.Println(err) 25 | return 26 | } 27 | // use stopCh to exit 28 | go func() { 29 | time.Sleep(10 * time.Second) 30 | stopCh <- struct{}{} 31 | }() 32 | <-doneCh 33 | } 34 | -------------------------------------------------------------------------------- /examples/websocket_api/account/AccountInformation/AccountInformation.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "log" 7 | 8 | binance_connector "github.com/binance/binance-connector-go" 9 | ) 10 | 11 | func main() { 12 | AccountInformationExample() 13 | } 14 | 15 | func AccountInformationExample() { 16 | client := binance_connector.NewWebsocketAPIClient("api_key", "secret_key") 17 | err := client.Connect() 18 | if err != nil { 19 | log.Printf("Error: %v", err) 20 | return 21 | } 22 | defer client.Close() 23 | 24 | response, err := client.NewAccountInformationService().Do(context.Background()) 25 | if err != nil { 26 | log.Printf("Error: %v", err) 27 | return 28 | } 29 | 30 | fmt.Println(binance_connector.PrettyPrint(response)) 31 | 32 | client.WaitForCloseSignal() 33 | 34 | } 35 | -------------------------------------------------------------------------------- /examples/websocket_api/account/OCOHistory/OCOHistory.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "log" 7 | 8 | binance_connector "github.com/binance/binance-connector-go" 9 | ) 10 | 11 | func main() { 12 | OCOHistoryExample() 13 | } 14 | 15 | func OCOHistoryExample() { 16 | client := binance_connector.NewWebsocketAPIClient("api_key", "secret_key") 17 | err := client.Connect() 18 | if err != nil { 19 | log.Printf("Error: %v", err) 20 | return 21 | } 22 | defer client.Close() 23 | 24 | response, err := client.NewAccountOCOHistoryService().Do(context.Background()) 25 | if err != nil { 26 | log.Printf("Error: %v", err) 27 | return 28 | } 29 | 30 | fmt.Println(binance_connector.PrettyPrint(response)) 31 | 32 | client.WaitForCloseSignal() 33 | } 34 | -------------------------------------------------------------------------------- /examples/websocket_api/account/OrderHistory/OrderHistory.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "log" 7 | 8 | binance_connector "github.com/binance/binance-connector-go" 9 | ) 10 | 11 | func main() { 12 | OrderHistoryExample() 13 | } 14 | 15 | func OrderHistoryExample() { 16 | client := binance_connector.NewWebsocketAPIClient("api_key", "secret_key") 17 | err := client.Connect() 18 | if err != nil { 19 | log.Printf("Error: %v", err) 20 | return 21 | } 22 | defer client.Close() 23 | 24 | response, err := client.NewAccountOrderHistoryService().Symbol("BTCUSDT").StartTime(1684566357000).Do(context.Background()) 25 | if err != nil { 26 | log.Printf("Error: %v", err) 27 | return 28 | } 29 | 30 | fmt.Println(binance_connector.PrettyPrint(response)) 31 | 32 | client.WaitForCloseSignal() 33 | } 34 | -------------------------------------------------------------------------------- /examples/websocket_api/account/OrderRateLimits/OrderRateLimits.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "log" 7 | 8 | binance_connector "github.com/binance/binance-connector-go" 9 | ) 10 | 11 | func main() { 12 | OrderRateLimits() 13 | } 14 | 15 | func OrderRateLimits() { 16 | client := binance_connector.NewWebsocketAPIClient("api_key", "secret_key") 17 | err := client.Connect() 18 | if err != nil { 19 | log.Printf("Error: %v", err) 20 | return 21 | } 22 | defer client.Close() 23 | 24 | response, err := client.NewAccountOrderRateLimitsService().Do(context.Background()) 25 | if err != nil { 26 | log.Printf("Error: %v", err) 27 | return 28 | } 29 | 30 | fmt.Println(binance_connector.PrettyPrint(response)) 31 | 32 | client.WaitForCloseSignal() 33 | } 34 | -------------------------------------------------------------------------------- /examples/websocket_api/account/PreventedMatches/PreventedMatches.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "log" 7 | 8 | binance_connector "github.com/binance/binance-connector-go" 9 | ) 10 | 11 | func main() { 12 | PreventedMatchesExample() 13 | } 14 | 15 | func PreventedMatchesExample() { 16 | client := binance_connector.NewWebsocketAPIClient("api_key", "secret_key") 17 | err := client.Connect() 18 | if err != nil { 19 | log.Printf("Error: %v", err) 20 | return 21 | } 22 | defer client.Close() 23 | 24 | response, err := client.NewAccountPreventedMatchesService().Do(context.Background()) 25 | if err != nil { 26 | log.Printf("Error: %v", err) 27 | return 28 | } 29 | 30 | fmt.Println(binance_connector.PrettyPrint(response)) 31 | 32 | client.WaitForCloseSignal() 33 | } 34 | -------------------------------------------------------------------------------- /examples/websocket_api/account/TradeHistory/TradeHistory.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "log" 7 | 8 | binance_connector "github.com/binance/binance-connector-go" 9 | ) 10 | 11 | func main() { 12 | TradeHistoryExample() 13 | } 14 | 15 | func TradeHistoryExample() { 16 | client := binance_connector.NewWebsocketAPIClient("api_key", "secret_key") 17 | err := client.Connect() 18 | if err != nil { 19 | log.Printf("Error: %v", err) 20 | return 21 | } 22 | defer client.Close() 23 | 24 | response, err := client.NewAccountTradeHistoryService().Do(context.Background()) 25 | if err != nil { 26 | log.Printf("Error: %v", err) 27 | return 28 | } 29 | 30 | fmt.Println(binance_connector.PrettyPrint(response)) 31 | 32 | client.WaitForCloseSignal() 33 | } 34 | -------------------------------------------------------------------------------- /examples/websocket_api/combined/WsStreamAndWsAPI/WsStreamAndWsAPI.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "log" 7 | 8 | binance_connector "github.com/binance/binance-connector-go" 9 | ) 10 | 11 | func main() { 12 | WsStreamAndWsAPI() 13 | } 14 | 15 | func WsStreamAndWsAPI() { 16 | // Websocket Stream 17 | websocketStreamClient := binance_connector.NewWebsocketStreamClient(false) 18 | wsTradeHandler := func(event *binance_connector.WsTradeEvent) { 19 | fmt.Println(binance_connector.PrettyPrint(event)) 20 | } 21 | errHandler := func(err error) { 22 | fmt.Println(err) 23 | } 24 | doneCh, _, err := websocketStreamClient.WsTradeServe("LTCBTC", wsTradeHandler, errHandler) 25 | if err != nil { 26 | fmt.Println(err) 27 | return 28 | } 29 | 30 | // Websocket API 31 | client := binance_connector.NewWebsocketAPIClient("api_key", "secret_key", "wss://ws-api.testnet.binance.vision/ws-api/v3") 32 | err2 := client.Connect() 33 | if err2 != nil { 34 | fmt.Println("Error: ", err2) 35 | return 36 | } 37 | 38 | response, err := client.NewPlaceNewOrderService().Symbol("BTCUSDT").Side("BUY").OrderType("MARKET").Quantity(0.01). 39 | Do(context.Background()) 40 | if err != nil { 41 | log.Printf("Error: %v", err) 42 | return 43 | } 44 | 45 | fmt.Println(binance_connector.PrettyPrint(response)) 46 | 47 | <-doneCh 48 | client.WaitForCloseSignal() 49 | } 50 | -------------------------------------------------------------------------------- /examples/websocket_api/market/AggregateTrades/AggregateTrades.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "log" 7 | 8 | binance_connector "github.com/binance/binance-connector-go" 9 | ) 10 | 11 | func main() { 12 | AggregateTrades() 13 | } 14 | 15 | func AggregateTrades() { 16 | client := binance_connector.NewWebsocketAPIClient("", "", "wss://ws-api.testnet.binance.vision/ws-api/v3") 17 | err := client.Connect() 18 | if err != nil { 19 | log.Printf("Error: %v", err) 20 | return 21 | } 22 | defer client.Close() 23 | 24 | response, err := client.NewAggTradesService().Symbol("BTCUSDT").Do(context.Background()) 25 | if err != nil { 26 | log.Printf("Error: %v", err) 27 | return 28 | } 29 | 30 | fmt.Println(binance_connector.PrettyPrint(response)) 31 | 32 | client.WaitForCloseSignal() 33 | } 34 | -------------------------------------------------------------------------------- /examples/websocket_api/market/AvgPrice/AvgPrice.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "log" 7 | 8 | binance_connector "github.com/binance/binance-connector-go" 9 | ) 10 | 11 | func main() { 12 | AvgPrice() 13 | } 14 | 15 | func AvgPrice() { 16 | client := binance_connector.NewWebsocketAPIClient("", "", "wss://ws-api.testnet.binance.vision/ws-api/v3") 17 | err := client.Connect() 18 | if err != nil { 19 | log.Printf("Error: %v", err) 20 | return 21 | } 22 | defer client.Close() 23 | 24 | response, err := client.NewAvgPriceService().Symbol("BTCUSDT").Do(context.Background()) 25 | if err != nil { 26 | log.Printf("Error: %v", err) 27 | return 28 | } 29 | 30 | fmt.Println(binance_connector.PrettyPrint(response)) 31 | 32 | client.WaitForCloseSignal() 33 | } 34 | -------------------------------------------------------------------------------- /examples/websocket_api/market/Depth/Depth.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "log" 7 | 8 | binance_connector "github.com/binance/binance-connector-go" 9 | ) 10 | 11 | func main() { 12 | DepthExample() 13 | } 14 | 15 | func DepthExample() { 16 | client := binance_connector.NewWebsocketAPIClient("", "", "wss://ws-api.testnet.binance.vision/ws-api/v3") 17 | err := client.Connect() 18 | if err != nil { 19 | log.Printf("Error: %v", err) 20 | return 21 | } 22 | defer client.Close() 23 | 24 | response, err := client.NewDepthService().Symbol("").Do(context.Background()) 25 | if err != nil { 26 | log.Printf("Error: %v", err) 27 | return 28 | } 29 | 30 | fmt.Println(binance_connector.PrettyPrint(response)) 31 | 32 | client.WaitForCloseSignal() 33 | } 34 | -------------------------------------------------------------------------------- /examples/websocket_api/market/HistoricalTrades/HistoricalTrades.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "log" 7 | 8 | binance_connector "github.com/binance/binance-connector-go" 9 | ) 10 | 11 | func main() { 12 | HistoricalTrades() 13 | } 14 | 15 | func HistoricalTrades() { 16 | client := binance_connector.NewWebsocketAPIClient("", "", "wss://ws-api.testnet.binance.vision/ws-api/v3") 17 | err := client.Connect() 18 | if err != nil { 19 | log.Printf("Error: %v", err) 20 | return 21 | } 22 | defer client.Close() 23 | 24 | response, err := client.NewHistoricalTradesService().Symbol("BTCUSDT").Do(context.Background()) 25 | if err != nil { 26 | log.Printf("Error: %v", err) 27 | return 28 | } 29 | 30 | fmt.Println(binance_connector.PrettyPrint(response)) 31 | 32 | client.WaitForCloseSignal() 33 | } 34 | -------------------------------------------------------------------------------- /examples/websocket_api/market/Klines/Klines.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "log" 7 | 8 | binance_connector "github.com/binance/binance-connector-go" 9 | ) 10 | 11 | func main() { 12 | KlinesExample() 13 | } 14 | 15 | func KlinesExample() { 16 | client := binance_connector.NewWebsocketAPIClient("", "", "wss://ws-api.testnet.binance.vision/ws-api/v3") 17 | err := client.Connect() 18 | if err != nil { 19 | log.Printf("Error: %v", err) 20 | return 21 | } 22 | defer client.Close() 23 | 24 | response, err := client.NewKlinesService().Symbol("BTCUSDT").Interval("1m").Do(context.Background()) 25 | if err != nil { 26 | log.Printf("Error: %v", err) 27 | return 28 | } 29 | 30 | fmt.Println(binance_connector.PrettyPrint(response)) 31 | 32 | client.WaitForCloseSignal() 33 | } 34 | -------------------------------------------------------------------------------- /examples/websocket_api/market/RecentTrades/RecentTrades.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "log" 7 | 8 | binance_connector "github.com/binance/binance-connector-go" 9 | ) 10 | 11 | func main() { 12 | RecentTrades() 13 | } 14 | 15 | func RecentTrades() { 16 | client := binance_connector.NewWebsocketAPIClient("", "", "wss://ws-api.testnet.binance.vision/ws-api/v3") 17 | err := client.Connect() 18 | if err != nil { 19 | log.Printf("Error: %v", err) 20 | return 21 | } 22 | defer client.Close() 23 | 24 | response, err := client.NewRecentTradesService().Symbol("BTCUSDT").Do(context.Background()) 25 | if err != nil { 26 | log.Printf("Error: %v", err) 27 | return 28 | } 29 | 30 | fmt.Println(binance_connector.PrettyPrint(response)) 31 | 32 | client.WaitForCloseSignal() 33 | } 34 | -------------------------------------------------------------------------------- /examples/websocket_api/market/Ticker/Ticker.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "log" 7 | 8 | binance_connector "github.com/binance/binance-connector-go" 9 | ) 10 | 11 | func main() { 12 | Ticker() 13 | } 14 | 15 | func Ticker() { 16 | client := binance_connector.NewWebsocketAPIClient("", "", "wss://ws-api.testnet.binance.vision/ws-api/v3") 17 | err := client.Connect() 18 | if err != nil { 19 | log.Printf("Error: %v", err) 20 | return 21 | } 22 | defer client.Close() 23 | 24 | response, err := client.NewTickerService().Symbol("BTCUSDT").Do(context.Background()) 25 | if err != nil { 26 | log.Printf("Error: %v", err) 27 | return 28 | } 29 | 30 | fmt.Println(binance_connector.PrettyPrint(response)) 31 | 32 | client.WaitForCloseSignal() 33 | } 34 | -------------------------------------------------------------------------------- /examples/websocket_api/market/Ticker24hr/Ticker24hr.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "log" 7 | 8 | binance_connector "github.com/binance/binance-connector-go" 9 | ) 10 | 11 | func main() { 12 | Ticker24hr() 13 | } 14 | 15 | func Ticker24hr() { 16 | client := binance_connector.NewWebsocketAPIClient("", "", "wss://ws-api.testnet.binance.vision/ws-api/v3") 17 | err := client.Connect() 18 | if err != nil { 19 | log.Printf("Error: %v", err) 20 | return 21 | } 22 | defer client.Close() 23 | 24 | response, err := client.NewTicker24hrService().Symbol("BTCUSDT").Do(context.Background()) 25 | if err != nil { 26 | log.Printf("Error: %v", err) 27 | return 28 | } 29 | 30 | fmt.Println(binance_connector.PrettyPrint(response)) 31 | 32 | client.WaitForCloseSignal() 33 | } 34 | -------------------------------------------------------------------------------- /examples/websocket_api/market/TickerBook/TickerBook.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "log" 7 | 8 | binance_connector "github.com/binance/binance-connector-go" 9 | ) 10 | 11 | func main() { 12 | TickerBook() 13 | } 14 | 15 | func TickerBook() { 16 | client := binance_connector.NewWebsocketAPIClient("", "", "wss://ws-api.testnet.binance.vision/ws-api/v3") 17 | err := client.Connect() 18 | if err != nil { 19 | log.Printf("Error: %v", err) 20 | return 21 | } 22 | defer client.Close() 23 | 24 | response, err := client.NewTickerBookService().Symbol("BTCUSDT").Do(context.Background()) 25 | if err != nil { 26 | log.Printf("Error: %v", err) 27 | return 28 | } 29 | 30 | fmt.Println(binance_connector.PrettyPrint(response)) 31 | 32 | client.WaitForCloseSignal() 33 | } 34 | -------------------------------------------------------------------------------- /examples/websocket_api/market/TickerPrice/TickerPrice.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "log" 7 | 8 | binance_connector "github.com/binance/binance-connector-go" 9 | ) 10 | 11 | func main() { 12 | TickerPrice() 13 | } 14 | 15 | func TickerPrice() { 16 | client := binance_connector.NewWebsocketAPIClient("", "", "wss://ws-api.testnet.binance.vision/ws-api/v3") 17 | err := client.Connect() 18 | if err != nil { 19 | log.Printf("Error: %v", err) 20 | return 21 | } 22 | defer client.Close() 23 | 24 | response, err := client.NewTickerPriceService().Symbol("BTCUSDT").Do(context.Background()) 25 | if err != nil { 26 | log.Printf("Error: %v", err) 27 | return 28 | } 29 | 30 | fmt.Println(binance_connector.PrettyPrint(response)) 31 | 32 | client.WaitForCloseSignal() 33 | } 34 | -------------------------------------------------------------------------------- /examples/websocket_api/market/UiKlines/UiKlines.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "log" 7 | 8 | binance_connector "github.com/binance/binance-connector-go" 9 | ) 10 | 11 | func main() { 12 | UiKlines() 13 | } 14 | 15 | func UiKlines() { 16 | client := binance_connector.NewWebsocketAPIClient("", "", "wss://ws-api.testnet.binance.vision/ws-api/v3") 17 | err := client.Connect() 18 | if err != nil { 19 | log.Printf("Error: %v", err) 20 | return 21 | } 22 | defer client.Close() 23 | 24 | response, err := client.NewUiKlinesService().Symbol("BTCUSDT").Interval("1m").Do(context.Background()) 25 | if err != nil { 26 | log.Printf("Error: %v", err) 27 | return 28 | } 29 | 30 | fmt.Println(binance_connector.PrettyPrint(response)) 31 | 32 | client.WaitForCloseSignal() 33 | } 34 | -------------------------------------------------------------------------------- /examples/websocket_api/trading/CancelOCO/CancelOCO.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "log" 7 | 8 | binance_connector "github.com/binance/binance-connector-go" 9 | ) 10 | 11 | func main() { 12 | CancelOCOExample() 13 | } 14 | 15 | func CancelOCOExample() { 16 | client := binance_connector.NewWebsocketAPIClient("api_key", "secret_key", "wss://ws-api.testnet.binance.vision/ws-api/v3") 17 | err := client.Connect() 18 | if err != nil { 19 | log.Printf("Error: %v", err) 20 | return 21 | } 22 | defer client.Close() 23 | 24 | response, err := client.NewCancelOCOService().Symbol("BTCUSDT").OrderListId(123321).Do(context.Background()) 25 | if err != nil { 26 | log.Printf("Error: %v", err) 27 | return 28 | } 29 | 30 | fmt.Println(binance_connector.PrettyPrint(response)) 31 | 32 | client.WaitForCloseSignal() 33 | } 34 | -------------------------------------------------------------------------------- /examples/websocket_api/trading/CancelOpenOrders/CancelOpenOrders.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "log" 7 | 8 | binance_connector "github.com/binance/binance-connector-go" 9 | ) 10 | 11 | func main() { 12 | CancelOpenOrdersExample() 13 | } 14 | 15 | func CancelOpenOrdersExample() { 16 | client := binance_connector.NewWebsocketAPIClient("api_key", "secret_key", "wss://ws-api.testnet.binance.vision/ws-api/v3") 17 | err := client.Connect() 18 | if err != nil { 19 | log.Printf("Error: %v", err) 20 | return 21 | } 22 | defer client.Close() 23 | 24 | response, err := client.NewCancelOpenOrdersService().Symbol("BTCUSDT").Do(context.Background()) 25 | if err != nil { 26 | log.Printf("Error: %v", err) 27 | return 28 | } 29 | 30 | fmt.Println(binance_connector.PrettyPrint(response)) 31 | 32 | client.WaitForCloseSignal() 33 | } 34 | -------------------------------------------------------------------------------- /examples/websocket_api/trading/CancelOrder/CancelOrder.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "log" 7 | 8 | binance_connector "github.com/binance/binance-connector-go" 9 | ) 10 | 11 | func main() { 12 | CancelOrderExample() 13 | } 14 | 15 | func CancelOrderExample() { 16 | client := binance_connector.NewWebsocketAPIClient("api_key", "secret_key", "wss://ws-api.testnet.binance.vision/ws-api/v3") 17 | err := client.Connect() 18 | if err != nil { 19 | log.Printf("Error: %v", err) 20 | return 21 | } 22 | defer client.Close() 23 | 24 | response, err := client.NewCancelOrderService().Symbol("BTCUSDT").OrderId(123123123).Do(context.Background()) 25 | if err != nil { 26 | log.Printf("Error: %v", err) 27 | return 28 | } 29 | 30 | fmt.Println(binance_connector.PrettyPrint(response)) 31 | 32 | client.WaitForCloseSignal() 33 | } 34 | -------------------------------------------------------------------------------- /examples/websocket_api/trading/CancelReplaceOrder/CancelReplaceOrder.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "log" 7 | 8 | binance_connector "github.com/binance/binance-connector-go" 9 | ) 10 | 11 | func main() { 12 | CancelReplaceOrderExample() 13 | } 14 | 15 | func CancelReplaceOrderExample() { 16 | client := binance_connector.NewWebsocketAPIClient("api_key", "secret_key", "wss://ws-api.testnet.binance.vision/ws-api/v3") 17 | err := client.Connect() 18 | if err != nil { 19 | log.Printf("Error: %v", err) 20 | return 21 | } 22 | defer client.Close() 23 | 24 | response, err := client.NewCancelReplaceOrderService().Symbol("BTCUSDT").CancelReplaceMode("STOP_ON_FAILURE"). 25 | Side("BUY").OrderType("MARKET").CancelOrderId(123123132).Do(context.Background()) 26 | if err != nil { 27 | log.Printf("Error: %v", err) 28 | return 29 | } 30 | 31 | fmt.Println(binance_connector.PrettyPrint(response)) 32 | 33 | client.WaitForCloseSignal() 34 | } 35 | -------------------------------------------------------------------------------- /examples/websocket_api/trading/CurrentOpenOCO/CurrentOpenOCO.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "log" 7 | 8 | binance_connector "github.com/binance/binance-connector-go" 9 | ) 10 | 11 | func main() { 12 | CurrentOpenOCOExample() 13 | } 14 | 15 | func CurrentOpenOCOExample() { 16 | client := binance_connector.NewWebsocketAPIClient("api_key", "secret_key", "wss://ws-api.testnet.binance.vision/ws-api/v3") 17 | err := client.Connect() 18 | if err != nil { 19 | log.Printf("Error: %v", err) 20 | return 21 | } 22 | defer client.Close() 23 | 24 | response, err := client.NewCurrentOpenOCOService().Do(context.Background()) 25 | if err != nil { 26 | log.Printf("Error: %v", err) 27 | return 28 | } 29 | 30 | fmt.Println(binance_connector.PrettyPrint(response)) 31 | 32 | client.WaitForCloseSignal() 33 | } 34 | -------------------------------------------------------------------------------- /examples/websocket_api/trading/CurrentOpenOrders/CurrentOpenOrders.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "log" 7 | 8 | binance_connector "github.com/binance/binance-connector-go" 9 | ) 10 | 11 | func main() { 12 | CurrentOpenOrdersExample() 13 | } 14 | 15 | func CurrentOpenOrdersExample() { 16 | client := binance_connector.NewWebsocketAPIClient("api_key", "secret_key", "wss://ws-api.testnet.binance.vision/ws-api/v3") 17 | err := client.Connect() 18 | if err != nil { 19 | log.Printf("Error: %v", err) 20 | return 21 | } 22 | defer client.Close() 23 | 24 | response, err := client.NewCurrentOpenOrdersService().Symbol("BTCUSDT").Do(context.Background()) 25 | if err != nil { 26 | log.Printf("Error: %v", err) 27 | return 28 | } 29 | 30 | fmt.Println(binance_connector.PrettyPrint(response)) 31 | 32 | client.WaitForCloseSignal() 33 | } 34 | -------------------------------------------------------------------------------- /examples/websocket_api/trading/PlaceNewOCO/PlaceNewOCO.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "log" 7 | 8 | binance_connector "github.com/binance/binance-connector-go" 9 | ) 10 | 11 | func main() { 12 | PlaceNewOCOExample() 13 | } 14 | 15 | func PlaceNewOCOExample() { 16 | client := binance_connector.NewWebsocketAPIClient("api_key", "secret_key", "wss://ws-api.testnet.binance.vision/ws-api/v3") 17 | err := client.Connect() 18 | if err != nil { 19 | log.Printf("Error: %v", err) 20 | return 21 | } 22 | defer client.Close() 23 | 24 | response, err := client.NewPlaceOCOService().Symbol("BTCUSDT").Do(context.Background()) 25 | if err != nil { 26 | log.Printf("Error: %v", err) 27 | return 28 | } 29 | 30 | fmt.Println(binance_connector.PrettyPrint(response)) 31 | 32 | client.WaitForCloseSignal() 33 | } 34 | -------------------------------------------------------------------------------- /examples/websocket_api/trading/PlaceNewOrder/PlaceNewOrder.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "log" 7 | 8 | binance_connector "github.com/binance/binance-connector-go" 9 | ) 10 | 11 | func main() { 12 | PlaceNewOrderExample() 13 | } 14 | 15 | func PlaceNewOrderExample() { 16 | client := binance_connector.NewWebsocketAPIClient("api_key", "secret_key", "wss://ws-api.testnet.binance.vision/ws-api/v3") 17 | err := client.Connect() 18 | if err != nil { 19 | log.Printf("Error: %v", err) 20 | return 21 | } 22 | defer client.Close() 23 | 24 | response, err := client.NewPlaceNewOrderService().Symbol("BTCUSDT").Side("BUY").OrderType("MARKET").Quantity(0.01). 25 | Do(context.Background()) 26 | if err != nil { 27 | log.Printf("Error: %v", err) 28 | return 29 | } 30 | 31 | fmt.Println(binance_connector.PrettyPrint(response)) 32 | 33 | client.WaitForCloseSignal() 34 | } 35 | -------------------------------------------------------------------------------- /examples/websocket_api/trading/QueryOCO/QueryOCO.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "log" 7 | 8 | binance_connector "github.com/binance/binance-connector-go" 9 | ) 10 | 11 | func main() { 12 | QueryOCOExample() 13 | } 14 | 15 | func QueryOCOExample() { 16 | client := binance_connector.NewWebsocketAPIClient("api_key", "secret_key", "wss://ws-api.testnet.binance.vision/ws-api/v3") 17 | err := client.Connect() 18 | if err != nil { 19 | log.Printf("Error: %v", err) 20 | return 21 | } 22 | defer client.Close() 23 | 24 | response, err := client.NewQueryOCOService().OrderListId(123321).Do(context.Background()) 25 | if err != nil { 26 | log.Printf("Error: %v", err) 27 | return 28 | } 29 | 30 | fmt.Println(binance_connector.PrettyPrint(response)) 31 | 32 | client.WaitForCloseSignal() 33 | } 34 | -------------------------------------------------------------------------------- /examples/websocket_api/trading/QueryOrder/QueryOrder.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "log" 7 | 8 | binance_connector "github.com/binance/binance-connector-go" 9 | ) 10 | 11 | func main() { 12 | QueryOrderExample() 13 | } 14 | 15 | func QueryOrderExample() { 16 | client := binance_connector.NewWebsocketAPIClient("api_key", "secret_key", "wss://ws-api.testnet.binance.vision/ws-api/v3") 17 | err := client.Connect() 18 | if err != nil { 19 | log.Printf("Error: %v", err) 20 | return 21 | } 22 | defer client.Close() 23 | 24 | response, err := client.NewQueryOrderService().Symbol("BTCUSDT").OrderId(123123123).Do(context.Background()) 25 | if err != nil { 26 | log.Printf("Error: %v", err) 27 | return 28 | } 29 | 30 | fmt.Println(binance_connector.PrettyPrint(response)) 31 | 32 | client.WaitForCloseSignal() 33 | } 34 | -------------------------------------------------------------------------------- /examples/websocket_api/trading/TestNewOrder/TestNewOrder.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "log" 7 | 8 | binance_connector "github.com/binance/binance-connector-go" 9 | ) 10 | 11 | func main() { 12 | TestNewOrderExample() 13 | } 14 | 15 | func TestNewOrderExample() { 16 | client := binance_connector.NewWebsocketAPIClient("api_key", "secret_key", "wss://ws-api.testnet.binance.vision/ws-api/v3") 17 | err := client.Connect() 18 | if err != nil { 19 | log.Printf("Error: %v", err) 20 | return 21 | } 22 | defer client.Close() 23 | 24 | response, err := client.NewTestPlaceOrderService().Symbol("BTCUSDT").Side("BUY").OrderType("MARKET").Quantity(0.01). 25 | Do(context.Background()) 26 | if err != nil { 27 | log.Printf("Error: %v", err) 28 | return 29 | } 30 | 31 | fmt.Println(binance_connector.PrettyPrint(response)) 32 | 33 | client.WaitForCloseSignal() 34 | } 35 | -------------------------------------------------------------------------------- /examples/websocket_api/user_data/PingUserDataStream/PingUserDataStream.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "log" 7 | 8 | binance_connector "github.com/binance/binance-connector-go" 9 | ) 10 | 11 | func main() { 12 | PingUserDataStream() 13 | } 14 | 15 | func PingUserDataStream() { 16 | client := binance_connector.NewWebsocketAPIClient("API_KEY", "") 17 | err := client.Connect() 18 | if err != nil { 19 | log.Printf("Error: %v", err) 20 | return 21 | } 22 | defer client.Close() 23 | 24 | response, err := client.NewPingUserDataStreamService().ListenKey("LISTEN_KEY").Do(context.Background()) 25 | if err != nil { 26 | log.Printf("Error: %v", err) 27 | return 28 | } 29 | 30 | fmt.Println(binance_connector.PrettyPrint(response.Response)) 31 | 32 | client.WaitForCloseSignal() 33 | } 34 | -------------------------------------------------------------------------------- /examples/websocket_api/user_data/StartUserDataStream/StartUserDataStream.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "log" 7 | 8 | binance_connector "github.com/binance/binance-connector-go" 9 | ) 10 | 11 | func main() { 12 | StartUserDataStream() 13 | } 14 | 15 | func StartUserDataStream() { 16 | client := binance_connector.NewWebsocketAPIClient("API_KEY", "") 17 | err := client.Connect() 18 | if err != nil { 19 | log.Printf("Error: %v", err) 20 | return 21 | } 22 | 23 | response, err := client.NewStartUserDataStreamService().Do(context.Background()) 24 | if err != nil { 25 | log.Printf("Error: %v", err) 26 | return 27 | } 28 | 29 | fmt.Println(binance_connector.PrettyPrint(response.Result.ListenKey)) 30 | client.WaitForCloseSignal() 31 | } 32 | -------------------------------------------------------------------------------- /examples/websocket_api/user_data/StopUserDataStream/StopUserDataStream.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "log" 7 | 8 | binance_connector "github.com/binance/binance-connector-go" 9 | ) 10 | 11 | func main() { 12 | StopUserDataStream() 13 | } 14 | 15 | func StopUserDataStream() { 16 | client := binance_connector.NewWebsocketAPIClient("api_key", "", "wss://ws-api.testnet.binance.vision/ws-api/v3") 17 | err := client.Connect() 18 | if err != nil { 19 | log.Printf("Error: %v", err) 20 | return 21 | } 22 | defer client.Close() 23 | 24 | response, err := client.NewStopUserDataStreamService().ListenKey("LISTEN_KEY").Do(context.Background()) 25 | if err != nil { 26 | log.Printf("Error: %v", err) 27 | return 28 | } 29 | 30 | fmt.Println(binance_connector.PrettyPrint(response)) 31 | 32 | client.WaitForCloseSignal() 33 | } 34 | -------------------------------------------------------------------------------- /fiat.go: -------------------------------------------------------------------------------- 1 | package binance_connector 2 | 3 | import ( 4 | "context" 5 | "encoding/json" 6 | "net/http" 7 | ) 8 | 9 | const ( 10 | fiatDepositWithdrawHistory = "/sapi/v1/fiat/orders" 11 | ) 12 | 13 | type GetFiatDepositWithdrawHistoryService struct { 14 | c *Client 15 | transactionType *string 16 | beginTime *uint64 17 | endTime *uint64 18 | page *int 19 | rows *int 20 | } 21 | 22 | func (s *GetFiatDepositWithdrawHistoryService) TransactionType(transactionType string) *GetFiatDepositWithdrawHistoryService { 23 | s.transactionType = &transactionType 24 | return s 25 | } 26 | 27 | func (s *GetFiatDepositWithdrawHistoryService) BeginTime(beginTime uint64) *GetFiatDepositWithdrawHistoryService { 28 | s.beginTime = &beginTime 29 | return s 30 | } 31 | 32 | func (s *GetFiatDepositWithdrawHistoryService) EndTime(endTime uint64) *GetFiatDepositWithdrawHistoryService { 33 | s.endTime = &endTime 34 | return s 35 | } 36 | 37 | func (s *GetFiatDepositWithdrawHistoryService) Page(page int) *GetFiatDepositWithdrawHistoryService { 38 | s.page = &page 39 | return s 40 | } 41 | 42 | func (s *GetFiatDepositWithdrawHistoryService) Rows(rows int) *GetFiatDepositWithdrawHistoryService { 43 | s.rows = &rows 44 | return s 45 | } 46 | 47 | func (s *GetFiatDepositWithdrawHistoryService) Do(ctx context.Context) (res *GetFiatDepositWithdrawHistoryResponse, err error) { 48 | r := &request{ 49 | method: http.MethodGet, 50 | endpoint: fiatDepositWithdrawHistory, 51 | secType: secTypeSigned, 52 | } 53 | r.setParam("transactionType", *s.transactionType) 54 | if s.beginTime != nil { 55 | r.setParam("beginTime", *s.beginTime) 56 | } 57 | if s.endTime != nil { 58 | r.setParam("endTime", *s.endTime) 59 | } 60 | if s.page != nil { 61 | r.setParam("page", *s.page) 62 | } 63 | if s.rows != nil { 64 | r.setParam("rows", *s.rows) 65 | } 66 | data, err := s.c.callAPI(ctx, r) 67 | if err != nil { 68 | return nil, err 69 | } 70 | res = new(GetFiatDepositWithdrawHistoryResponse) 71 | err = json.Unmarshal(data, res) 72 | if err != nil { 73 | return nil, err 74 | } 75 | return res, nil 76 | } 77 | 78 | type GetFiatDepositWithdrawHistoryResponse struct { 79 | Code string `json:"code"` 80 | Message string `json:"message"` 81 | Data []struct { 82 | OrderNo string `json:"orderNo"` 83 | FiatCurrency string `json:"fiatCurrency"` 84 | IndicatedAmount string `json:"indicatedAmount"` 85 | Amount string `json:"amount"` 86 | TotalFee string `json:"totalFee"` 87 | Method string `json:"method"` 88 | Status string `json:"status"` 89 | CreateTime uint64 `json:"createTime"` 90 | UpdateTime uint64 `json:"updateTime"` 91 | } 92 | Total int64 `json:"total"` 93 | Success bool `json:"success"` 94 | } 95 | 96 | const ( 97 | fiatPaymentHistory = "/sapi/v1/fiat/payments" 98 | ) 99 | 100 | type GetFiatPaymentHistoryService struct { 101 | c *Client 102 | transactionType *string 103 | beginTime *uint64 104 | endTime *uint64 105 | page *int 106 | rows *int 107 | } 108 | 109 | func (s *GetFiatPaymentHistoryService) TransactionType(transactionType string) *GetFiatPaymentHistoryService { 110 | s.transactionType = &transactionType 111 | return s 112 | } 113 | 114 | func (s *GetFiatPaymentHistoryService) BeginTime(beginTime uint64) *GetFiatPaymentHistoryService { 115 | s.beginTime = &beginTime 116 | return s 117 | } 118 | 119 | func (s *GetFiatPaymentHistoryService) EndTime(endTime uint64) *GetFiatPaymentHistoryService { 120 | s.endTime = &endTime 121 | return s 122 | } 123 | 124 | func (s *GetFiatPaymentHistoryService) Page(page int) *GetFiatPaymentHistoryService { 125 | s.page = &page 126 | return s 127 | } 128 | 129 | func (s *GetFiatPaymentHistoryService) Rows(rows int) *GetFiatPaymentHistoryService { 130 | s.rows = &rows 131 | return s 132 | } 133 | 134 | func (s *GetFiatPaymentHistoryService) Do(ctx context.Context) (res *GetFiatPaymentHistoryResponse, err error) { 135 | r := &request{ 136 | method: http.MethodGet, 137 | endpoint: fiatPaymentHistory, 138 | secType: secTypeSigned, 139 | } 140 | r.setParam("transactionType", *s.transactionType) 141 | if s.beginTime != nil { 142 | r.setParam("beginTime", *s.beginTime) 143 | } 144 | if s.endTime != nil { 145 | r.setParam("endTime", *s.endTime) 146 | } 147 | if s.page != nil { 148 | r.setParam("page", *s.page) 149 | } 150 | if s.rows != nil { 151 | r.setParam("rows", *s.rows) 152 | } 153 | data, err := s.c.callAPI(ctx, r) 154 | if err != nil { 155 | return nil, err 156 | } 157 | res = new(GetFiatPaymentHistoryResponse) 158 | err = json.Unmarshal(data, res) 159 | if err != nil { 160 | return nil, err 161 | } 162 | return res, nil 163 | } 164 | 165 | type GetFiatPaymentHistoryResponse struct { 166 | Code string `json:"code"` 167 | Message string `json:"message"` 168 | Data []struct { 169 | OrderNo string `json:"orderNo"` 170 | SourceAmount string `json:"sourceAmount"` 171 | FiatCurrency string `json:"fiatCurrency"` 172 | ObtainAmount string `json:"obtainAmount"` 173 | CryptoCurrency string `json:"cryptoCurrency"` 174 | TotalFee string `json:"totalFee"` 175 | Price string `json:"price"` 176 | Status string `json:"status"` 177 | PaymentMethod string `json:"paymentMethod"` 178 | CreateTime uint64 `json:"createTime"` 179 | UpdateTime uint64 `json:"updateTime"` 180 | } 181 | Total int64 `json:"total"` 182 | Success bool `json:"success"` 183 | } 184 | -------------------------------------------------------------------------------- /fiat_test.go: -------------------------------------------------------------------------------- 1 | package binance_connector 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/stretchr/testify/suite" 7 | ) 8 | 9 | type fiatTestSuite struct { 10 | baseTestSuite 11 | } 12 | 13 | func TestFiat(t *testing.T) { 14 | suite.Run(t, new(fiatTestSuite)) 15 | } 16 | 17 | func (s *fiatTestSuite) TestGetFiatDepositWithdrawHistory() { 18 | data := []byte(`{ 19 | "code": "000000", 20 | "message": "success", 21 | "data": [ 22 | { 23 | "orderNo":"7d76d611-0568-4f43-afb6-24cac7767365", 24 | "fiatCurrency": "BRL", 25 | "indicatedAmount": "10.00", 26 | "amount": "10.00", 27 | "totalFee": "0.00", 28 | "method": "BankAccount", 29 | "status": "Expired", 30 | "createTime": 1626144956000, 31 | "updateTime": 1626400907000 32 | } 33 | ], 34 | "total": 1, 35 | "success": true 36 | }`) 37 | s.mockDo(data, nil) 38 | defer s.assertDo() 39 | 40 | transactionType := "0" 41 | s.assertReq(func(r *request) { 42 | e := newSignedRequest().setParams(params{ 43 | "transactionType": transactionType, 44 | }) 45 | s.assertRequestEqual(e, r) 46 | }) 47 | 48 | res, err := s.client.NewGetFiatDepositWithdrawHistoryService().TransactionType(transactionType).Do(newContext()) 49 | s.r().NoError(err) 50 | s.Equal("000000", res.Code) 51 | s.Equal("success", res.Message) 52 | s.r().Len(res.Data, 1) 53 | s.Equal("7d76d611-0568-4f43-afb6-24cac7767365", res.Data[0].OrderNo) 54 | s.Equal("BRL", res.Data[0].FiatCurrency) 55 | s.Equal("10.00", res.Data[0].IndicatedAmount) 56 | s.Equal("10.00", res.Data[0].Amount) 57 | s.Equal("0.00", res.Data[0].TotalFee) 58 | s.Equal("BankAccount", res.Data[0].Method) 59 | s.Equal("Expired", res.Data[0].Status) 60 | s.Equal(uint64(1626144956000), res.Data[0].CreateTime) 61 | s.Equal(uint64(1626400907000), res.Data[0].UpdateTime) 62 | s.Equal(int64(1), res.Total) 63 | s.True(res.Success) 64 | } 65 | 66 | func (s *fiatTestSuite) TestGetPaymentFiatHistory() { 67 | data := []byte(`{ 68 | "code": "000000", 69 | "message": "success", 70 | "data": [ 71 | { 72 | "orderNo": "353fca443f06466db0c4dc89f94f027a", 73 | "sourceAmount": "20.0", 74 | "fiatCurrency": "EUR", 75 | "obtainAmount": "4.462", 76 | "cryptoCurrency": "LUNA", 77 | "totalFee": "0.2", 78 | "price": "4.437472", 79 | "status": "Failed", 80 | "paymentMethod": "Credit Card", 81 | "createTime": 1624529919000, 82 | "updateTime": 1624529919000 83 | } 84 | ], 85 | "total": 1, 86 | "success": true 87 | }`) 88 | s.mockDo(data, nil) 89 | defer s.assertDo() 90 | 91 | transactionType := "0" 92 | s.assertReq(func(r *request) { 93 | e := newSignedRequest().setParams(params{ 94 | "transactionType": transactionType, 95 | }) 96 | s.assertRequestEqual(e, r) 97 | }) 98 | 99 | res, err := s.client.NewGetFiatPaymentHistoryService().TransactionType(transactionType).Do(newContext()) 100 | s.r().NoError(err) 101 | s.Equal("000000", res.Code) 102 | s.Equal("success", res.Message) 103 | s.r().Len(res.Data, 1) 104 | s.Equal("353fca443f06466db0c4dc89f94f027a", res.Data[0].OrderNo) 105 | s.Equal("20.0", res.Data[0].SourceAmount) 106 | s.Equal("EUR", res.Data[0].FiatCurrency) 107 | s.Equal("4.462", res.Data[0].ObtainAmount) 108 | s.Equal("LUNA", res.Data[0].CryptoCurrency) 109 | s.Equal("0.2", res.Data[0].TotalFee) 110 | s.Equal("4.437472", res.Data[0].Price) 111 | s.Equal("Failed", res.Data[0].Status) 112 | s.Equal("Credit Card", res.Data[0].PaymentMethod) 113 | s.Equal(uint64(1624529919000), res.Data[0].CreateTime) 114 | s.Equal(uint64(1624529919000), res.Data[0].UpdateTime) 115 | s.Equal(int64(1), res.Total) 116 | s.True(res.Success) 117 | } 118 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/binance/binance-connector-go 2 | 3 | go 1.22 4 | 5 | require ( 6 | github.com/bitly/go-simplejson v0.5.1 7 | github.com/gorilla/websocket v1.5.3 8 | github.com/stretchr/testify v1.8.4 9 | ) 10 | 11 | require ( 12 | github.com/davecgh/go-spew v1.1.1 // indirect 13 | github.com/pmezard/go-difflib v1.0.0 // indirect 14 | github.com/stretchr/objx v0.5.0 // indirect 15 | gopkg.in/yaml.v3 v3.0.1 // indirect 16 | ) 17 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/bitly/go-simplejson v0.5.1 h1:xgwPbetQScXt1gh9BmoJ6j9JMr3TElvuIyjR8pgdoow= 2 | github.com/bitly/go-simplejson v0.5.1/go.mod h1:YOPVLzCfwK14b4Sff3oP1AmGhI9T9Vsg84etUnlyp+Q= 3 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 4 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 5 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 6 | github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg= 7 | github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= 8 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 9 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 10 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 11 | github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= 12 | github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c= 13 | github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= 14 | github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 15 | github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= 16 | github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= 17 | github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= 18 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= 19 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 20 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 21 | gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= 22 | gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 23 | -------------------------------------------------------------------------------- /handlers/errors.go: -------------------------------------------------------------------------------- 1 | package handlers 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | // APIError define API error when response status is 4xx or 5xx 8 | type APIError struct { 9 | Code int64 `json:"code"` 10 | Message string `json:"msg"` 11 | } 12 | 13 | // Error return error code and message 14 | func (e APIError) Error() string { 15 | return fmt.Sprintf(" code=%d, msg=%s", e.Code, e.Message) 16 | } 17 | 18 | // IsAPIError check if e is an API error 19 | func IsAPIError(e error) bool { 20 | _, ok := e.(*APIError) 21 | return ok 22 | } 23 | -------------------------------------------------------------------------------- /request.go: -------------------------------------------------------------------------------- 1 | package binance_connector 2 | 3 | import ( 4 | "fmt" 5 | "io" 6 | "net/http" 7 | "net/url" 8 | ) 9 | 10 | type secType int 11 | 12 | const ( 13 | secTypeNone secType = iota 14 | secTypeAPIKey 15 | secTypeSigned // if the 'timestamp' parameter is required 16 | ) 17 | 18 | type params map[string]interface{} 19 | 20 | // request define an API request 21 | type request struct { 22 | method string 23 | endpoint string 24 | query url.Values 25 | form url.Values 26 | recvWindow int64 27 | secType secType 28 | header http.Header 29 | body io.Reader 30 | fullURL string 31 | } 32 | 33 | // addParam add param with key/value to query string 34 | func (r *request) addParam(key string, value interface{}) *request { 35 | if r.query == nil { 36 | r.query = url.Values{} 37 | } 38 | r.query.Add(key, fmt.Sprintf("%v", value)) 39 | return r 40 | } 41 | 42 | // setParam set param with key/value to query string 43 | func (r *request) setParam(key string, value interface{}) *request { 44 | if r.query == nil { 45 | r.query = url.Values{} 46 | } 47 | r.query.Set(key, fmt.Sprintf("%v", value)) 48 | return r 49 | } 50 | 51 | // setParams set params with key/values to query string 52 | func (r *request) setParams(m params) *request { 53 | for k, v := range m { 54 | r.setParam(k, v) 55 | } 56 | return r 57 | } 58 | 59 | func (r *request) validate() (err error) { 60 | if r.query == nil { 61 | r.query = url.Values{} 62 | } 63 | if r.form == nil { 64 | r.form = url.Values{} 65 | } 66 | return nil 67 | } 68 | 69 | // Append `WithRecvWindow(insert_recvwindow)` to request to modify the default recvWindow value 70 | func WithRecvWindow(recvWindow int64) RequestOption { 71 | return func(r *request) { 72 | r.recvWindow = recvWindow 73 | } 74 | } 75 | 76 | // RequestOption define option type for request 77 | type RequestOption func(*request) 78 | -------------------------------------------------------------------------------- /user_stream.go: -------------------------------------------------------------------------------- 1 | package binance_connector 2 | 3 | import ( 4 | "context" 5 | "net/http" 6 | ) 7 | 8 | // Create Listen Key 9 | type CreateListenKey struct { 10 | c *Client 11 | } 12 | 13 | // Do send request 14 | func (s *CreateListenKey) Do(ctx context.Context, opts ...RequestOption) (listenKey string, err error) { 15 | r := &request{ 16 | method: http.MethodPost, 17 | endpoint: "/api/v3/userDataStream", 18 | secType: secTypeAPIKey, 19 | } 20 | data, err := s.c.callAPI(ctx, r, opts...) 21 | if err != nil { 22 | return "", err 23 | } 24 | j, err := newJSON(data) 25 | if err != nil { 26 | return "", err 27 | } 28 | listenKey = j.Get("listenKey").MustString() 29 | return listenKey, nil 30 | } 31 | 32 | // Keep Alive/Ping User Stream 33 | type PingUserStream struct { 34 | c *Client 35 | listenKey string 36 | } 37 | 38 | // ListenKey set listen key 39 | func (s *PingUserStream) ListenKey(listenKey string) *PingUserStream { 40 | s.listenKey = listenKey 41 | return s 42 | } 43 | 44 | // Do send request 45 | func (s *PingUserStream) Do(ctx context.Context, opts ...RequestOption) (err error) { 46 | r := &request{ 47 | method: http.MethodPut, 48 | endpoint: "/api/v3/userDataStream", 49 | secType: secTypeAPIKey, 50 | } 51 | r.setParam("listenKey", s.listenKey) 52 | _, err = s.c.callAPI(ctx, r, opts...) 53 | return err 54 | } 55 | 56 | // CloseUserStream delete listen key 57 | type CloseUserStream struct { 58 | c *Client 59 | listenKey string 60 | } 61 | 62 | // ListenKey set listen key 63 | func (s *CloseUserStream) ListenKey(listenKey string) *CloseUserStream { 64 | s.listenKey = listenKey 65 | return s 66 | } 67 | 68 | // Do send request 69 | func (s *CloseUserStream) Do(ctx context.Context, opts ...RequestOption) (err error) { 70 | r := &request{ 71 | method: http.MethodDelete, 72 | endpoint: "/api/v3/userDataStream", 73 | secType: secTypeAPIKey, 74 | } 75 | r.setParam("listenKey", s.listenKey) 76 | _, err = s.c.callAPI(ctx, r, opts...) 77 | return err 78 | } 79 | -------------------------------------------------------------------------------- /user_stream_test.go: -------------------------------------------------------------------------------- 1 | package binance_connector 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/stretchr/testify/suite" 7 | ) 8 | 9 | type userStreamTestSuite struct { 10 | baseTestSuite 11 | } 12 | 13 | func TestUserStream(t *testing.T) { 14 | suite.Run(t, new(userStreamTestSuite)) 15 | } 16 | 17 | func (s *userStreamTestSuite) TestStartUserStream() { 18 | data := []byte(`{ 19 | "listenKey": "pqia91ma19a5s61cv6a81va65sdf19v8a65a1a5s61cv6a81va65sdf19v8a65a1" 20 | }`) 21 | s.mockDo(data, nil) 22 | defer s.assertDo() 23 | 24 | s.assertReq(func(r *request) { 25 | s.assertRequestEqual(newRequest(), r) 26 | }) 27 | 28 | listenKey, err := s.client.NewCreateListenKeyService().Do(newContext()) 29 | s.r().NoError(err) 30 | s.r().Equal("pqia91ma19a5s61cv6a81va65sdf19v8a65a1a5s61cv6a81va65sdf19v8a65a1", listenKey) 31 | } 32 | 33 | func (s *userStreamTestSuite) TestKeepaliveUserStream() { 34 | data := []byte(`{}`) 35 | s.mockDo(data, nil) 36 | defer s.assertDo() 37 | 38 | listenKey := "dummykey" 39 | s.assertReq(func(r *request) { 40 | s.assertRequestEqual(newRequest().setParam("listenKey", listenKey), r) 41 | }) 42 | 43 | err := s.client.NewPingUserStream().ListenKey(listenKey).Do(newContext()) 44 | s.r().NoError(err) 45 | } 46 | 47 | func (s *userStreamTestSuite) TestCloseUserStream() { 48 | data := []byte(`{}`) 49 | s.mockDo(data, nil) 50 | defer s.assertDo() 51 | 52 | listenKey := "dummykey" 53 | s.assertReq(func(r *request) { 54 | s.assertRequestEqual(newRequest().setParam("listenKey", listenKey), r) 55 | }) 56 | 57 | err := s.client.NewCloseUserStream().ListenKey(listenKey).Do(newContext()) 58 | s.r().NoError(err) 59 | } 60 | -------------------------------------------------------------------------------- /websocket.go: -------------------------------------------------------------------------------- 1 | package binance_connector 2 | 3 | import ( 4 | "fmt" 5 | "net/http" 6 | "time" 7 | 8 | "github.com/gorilla/websocket" 9 | ) 10 | 11 | // WsHandler handle raw websocket message 12 | type WsHandler func(message []byte) 13 | 14 | // ErrHandler handles errors 15 | type ErrHandler func(err error) 16 | 17 | // WsConfig webservice configuration 18 | type WsConfig struct { 19 | Endpoint string 20 | } 21 | 22 | type WebsocketStreamClient struct { 23 | Endpoint string 24 | IsCombined bool 25 | } 26 | 27 | func NewWebsocketStreamClient(isCombined bool, baseURL ...string) *WebsocketStreamClient { 28 | // Set default base URL to production WS URL 29 | url := "wss://stream.binance.com:9443" 30 | 31 | if len(baseURL) > 0 { 32 | url = baseURL[0] 33 | } 34 | 35 | // Append to baseURL based on whether the client is for combined streams or not 36 | if isCombined { 37 | url += "/stream?streams=" 38 | } else { 39 | url += "/ws" 40 | } 41 | 42 | return &WebsocketStreamClient{ 43 | Endpoint: url, 44 | IsCombined: isCombined, 45 | } 46 | } 47 | 48 | func newWsConfig(endpoint string) *WsConfig { 49 | return &WsConfig{ 50 | Endpoint: endpoint, 51 | } 52 | } 53 | 54 | var wsServe = func(cfg *WsConfig, handler WsHandler, errHandler ErrHandler) (doneCh, stopCh chan struct{}, err error) { 55 | Dialer := websocket.Dialer{ 56 | Proxy: http.ProxyFromEnvironment, 57 | HandshakeTimeout: 45 * time.Second, 58 | EnableCompression: false, 59 | } 60 | headers := http.Header{} 61 | headers.Add("User-Agent", fmt.Sprintf("%s/%s", Name, Version)) 62 | c, _, err := Dialer.Dial(cfg.Endpoint, headers) 63 | if err != nil { 64 | return nil, nil, err 65 | } 66 | c.SetReadLimit(655350) 67 | doneCh = make(chan struct{}) 68 | stopCh = make(chan struct{}) 69 | go func() { 70 | // This function will exit either on error from 71 | // websocket.Conn.ReadMessage or when the stopC channel is 72 | // closed by the client. 73 | defer close(doneCh) 74 | if WebsocketKeepalive { 75 | keepAlive(c, WebsocketTimeout) 76 | } 77 | // Wait for the stopC channel to be closed. We do that in a 78 | // separate goroutine because ReadMessage is a blocking 79 | // operation. 80 | silent := false 81 | go func() { 82 | for { 83 | _, message, err := c.ReadMessage() 84 | if err != nil { 85 | if !silent { 86 | errHandler(err) 87 | } 88 | stopCh <- struct{}{} 89 | return 90 | } 91 | handler(message) 92 | } 93 | }() 94 | 95 | for { 96 | select { 97 | case <-stopCh: 98 | silent = true 99 | return 100 | case <-doneCh: 101 | } 102 | } 103 | }() 104 | return 105 | } 106 | 107 | func keepAlive(c *websocket.Conn, timeout time.Duration) { 108 | ticker := time.NewTicker(timeout) 109 | 110 | lastResponse := time.Now() 111 | c.SetPongHandler(func(msg string) error { 112 | lastResponse = time.Now() 113 | return nil 114 | }) 115 | 116 | go func() { 117 | defer ticker.Stop() 118 | for { 119 | deadline := time.Now().Add(10 * time.Second) 120 | err := c.WriteControl(websocket.PingMessage, []byte{}, deadline) 121 | if err != nil { 122 | return 123 | } 124 | <-ticker.C 125 | if time.Since(lastResponse) > timeout { 126 | return 127 | } 128 | } 129 | }() 130 | } 131 | -------------------------------------------------------------------------------- /websocket_api_userdata.go: -------------------------------------------------------------------------------- 1 | package binance_connector 2 | 3 | import ( 4 | "context" 5 | "encoding/json" 6 | ) 7 | 8 | type StartUserDataStreamService struct { 9 | websocketAPI *WebsocketAPIClient 10 | } 11 | 12 | func (s *StartUserDataStreamService) Do(ctx context.Context) (*StartUserDataStreamResponse, error) { 13 | parameters := map[string]interface{}{ 14 | "apiKey": s.websocketAPI.APIKey, 15 | } 16 | 17 | id := getUUID() 18 | 19 | payload := map[string]interface{}{ 20 | "id": id, 21 | "method": "userDataStream.start", 22 | "params": parameters, 23 | } 24 | 25 | messageCh := make(chan []byte) 26 | s.websocketAPI.ReqResponseMap[id] = messageCh 27 | 28 | err := s.websocketAPI.SendMessage(payload) 29 | if err != nil { 30 | return nil, err 31 | } 32 | 33 | defer delete(s.websocketAPI.ReqResponseMap, id) 34 | 35 | select { 36 | case response := <-messageCh: 37 | var startResponse StartUserDataStreamResponse 38 | err = json.Unmarshal(response, &startResponse) 39 | if err != nil { 40 | return nil, err 41 | } 42 | return &startResponse, nil 43 | case <-ctx.Done(): 44 | return nil, ctx.Err() 45 | } 46 | } 47 | 48 | type StartUserDataStreamResponse struct { 49 | ID string `json:"id"` 50 | Status int `json:"status"` 51 | Error *WsAPIErrorResponse `json:"error,omitempty"` 52 | Result struct { 53 | ListenKey string `json:"listenKey,omitempty"` 54 | } `json:"result,omitempty"` 55 | RateLimits []*WsAPIRateLimit `json:"rateLimits,omitempty"` 56 | } 57 | 58 | type PingUserDataStreamService struct { 59 | websocketAPI *WebsocketAPIClient 60 | listenKey string 61 | } 62 | 63 | func (s *PingUserDataStreamService) ListenKey(listenKey string) *PingUserDataStreamService { 64 | s.listenKey = listenKey 65 | return s 66 | } 67 | 68 | func (s *PingUserDataStreamService) Do(ctx context.Context) (*PingUserDataStreamResponse, error) { 69 | parameters := map[string]interface{}{ 70 | "listenKey": s.listenKey, 71 | "apiKey": s.websocketAPI.APIKey, 72 | } 73 | 74 | id := getUUID() 75 | 76 | payload := map[string]interface{}{ 77 | "id": id, 78 | "method": "userDataStream.ping", 79 | "params": parameters, 80 | } 81 | 82 | messageCh := make(chan []byte) 83 | s.websocketAPI.ReqResponseMap[id] = messageCh 84 | 85 | err := s.websocketAPI.SendMessage(payload) 86 | if err != nil { 87 | return nil, err 88 | } 89 | 90 | defer delete(s.websocketAPI.ReqResponseMap, id) 91 | 92 | select { 93 | case response := <-messageCh: 94 | var pingResponse PingUserDataStreamResponse 95 | err = json.Unmarshal(response, &pingResponse) 96 | if err != nil { 97 | return nil, err 98 | } 99 | return &pingResponse, nil 100 | case <-ctx.Done(): 101 | return nil, ctx.Err() 102 | } 103 | } 104 | 105 | type PingUserDataStreamResponse struct { 106 | ID string `json:"id"` 107 | Status int `json:"status"` 108 | Error *WsAPIErrorResponse `json:"error,omitempty"` 109 | Response struct{} `json:"result,omitempty"` 110 | RateLimits []*WsAPIRateLimit `json:"rateLimits,omitempty"` 111 | } 112 | 113 | type StopUserDataStreamService struct { 114 | websocketAPI *WebsocketAPIClient 115 | listenKey string 116 | } 117 | 118 | func (s *StopUserDataStreamService) ListenKey(listenKey string) *StopUserDataStreamService { 119 | s.listenKey = listenKey 120 | return s 121 | } 122 | 123 | func (s *StopUserDataStreamService) Do(ctx context.Context) (*StopUserDataStreamResponse, error) { 124 | parameters := map[string]interface{}{ 125 | "listenKey": s.listenKey, 126 | "apiKey": s.websocketAPI.APIKey, 127 | } 128 | 129 | id := getUUID() 130 | 131 | payload := map[string]interface{}{ 132 | "id": id, 133 | "method": "userDataStream.stop", 134 | "params": parameters, 135 | } 136 | 137 | messageCh := make(chan []byte) 138 | s.websocketAPI.ReqResponseMap[id] = messageCh 139 | 140 | err := s.websocketAPI.SendMessage(payload) 141 | if err != nil { 142 | return nil, err 143 | } 144 | 145 | defer delete(s.websocketAPI.ReqResponseMap, id) 146 | 147 | select { 148 | case response := <-messageCh: 149 | var stopResponse StopUserDataStreamResponse 150 | err = json.Unmarshal(response, &stopResponse) 151 | if err != nil { 152 | return nil, err 153 | } 154 | return &stopResponse, nil 155 | case <-ctx.Done(): 156 | return nil, ctx.Err() 157 | } 158 | } 159 | 160 | type StopUserDataStreamResponse struct { 161 | ID string `json:"id"` 162 | Status int `json:"status"` 163 | Error *WsAPIErrorResponse `json:"error,omitempty"` 164 | Response struct{} `json:"result,omitempty"` 165 | RateLimits []*WsAPIRateLimit `json:"rateLimits,omitempty"` 166 | } 167 | --------------------------------------------------------------------------------