Skip to content

Commit 1853a5d

Browse files
committed
add wallet subcommand
1 parent ba728fc commit 1853a5d

13 files changed

Lines changed: 368 additions & 64 deletions

File tree

README.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ All commands are to be used in the following format:
2121
./binance-cli [Module] [Subcommand] [Arguments]
2222
2323
Available Commands:
24-
futures Futures
25-
help Help about any command
26-
portfolio Portfolio
27-
spot Spot
28-
universal-transfer Transfer asset and history
24+
futures Futures
25+
help Help about any command
26+
portfolio Portfolio
27+
spot Spot
28+
wallet Wallet
2929
```
3030

3131
### Spot Module
@@ -80,5 +80,15 @@ Available Commands:
8080
```
8181
**[View detailed documentation](docs/portfolio_margin.md)**
8282

83+
### Wallet Module
84+
Exec: `./binance-cli wallet [Subcommand] [Arguments]`
85+
```shell
86+
Available Commands:
87+
dust dust asset conversion and history
88+
fee BNB payment fee
89+
universal-transfer Transfer asset and history
90+
```
91+
**[View detailed documentation](docs/wallet.md)**
92+
8393
## License
8494
UnipayFI/binance-cli is released under the [MIT License](https://opensource.org/licenses/MIT).

cmd/spot.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,5 @@ func init() {
1717
SpotCmd.AddCommand(spot.InitAssetCmds()...)
1818
SpotCmd.AddCommand(spot.InitDividendCmds()...)
1919
SpotCmd.AddCommand(spot.InitOrderCmds()...)
20-
SpotCmd.AddCommand(spot.InitFeeCmds()...)
2120
RootCmd.AddCommand(SpotCmd)
2221
}

cmd/wallet.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package cmd
2+
3+
import (
4+
"github.com/UnipayFI/binance-cli/cmd/wallet"
5+
"github.com/spf13/cobra"
6+
)
7+
8+
var (
9+
walletCmd = &cobra.Command{
10+
Use: "wallet",
11+
Short: "Wallet",
12+
}
13+
)
14+
15+
func init() {
16+
walletCmd.AddCommand(wallet.InitDustCmds()...)
17+
walletCmd.AddCommand(wallet.InitFeeCmds()...)
18+
walletCmd.AddCommand(wallet.InitUniversalTransferCmds()...)
19+
RootCmd.AddCommand(walletCmd)
20+
}

cmd/wallet/dust.go

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
package wallet
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/UnipayFI/binance-cli/config"
7+
"github.com/UnipayFI/binance-cli/exchange"
8+
"github.com/UnipayFI/binance-cli/exchange/wallet"
9+
"github.com/UnipayFI/binance-cli/printer"
10+
"github.com/spf13/cobra"
11+
)
12+
13+
var (
14+
dustCmd = &cobra.Command{
15+
Use: "dust",
16+
Short: "dust asset conversion and history",
17+
}
18+
19+
showDustCmd = &cobra.Command{
20+
Use: "show",
21+
Short: "Get assets that can be converted into BNB",
22+
Long: `Get assets that can be converted into BNB.
23+
24+
Docs Link: https://developers.binance.com/docs/wallet/asset/assets-can-convert-bnb`,
25+
Run: showDust,
26+
}
27+
28+
convertDustCmd = &cobra.Command{
29+
Use: "convert",
30+
Short: "Convert dust assets to BNB.",
31+
Long: `Convert dust assets to BNB.
32+
33+
Docs Link: https://developers.binance.com/docs/wallet/asset/dust-transfer`,
34+
Run: convertDust,
35+
}
36+
37+
historyDustCmd = &cobra.Command{
38+
Use: "history",
39+
Short: "Dust conversion history",
40+
Long: `Dust conversion history.
41+
* Only return last 100 records
42+
* Only return records after 2020/12/01
43+
44+
Docs Link: https://developers.binance.com/docs/wallet/asset/dust-log`,
45+
Run: historyDust,
46+
}
47+
)
48+
49+
func InitDustCmds() []*cobra.Command {
50+
showDustCmd.Flags().StringP("accountType", "a", "SPOT", "SPOT or MARGIN")
51+
52+
convertDustCmd.Flags().StringP("asset", "s", "", "The asset list being converted. For example: BTC,USDT")
53+
convertDustCmd.Flags().StringP("accountType", "a", "SPOT", "SPOT or MARGIN")
54+
convertDustCmd.MarkFlagRequired("asset")
55+
56+
historyDustCmd.Flags().Int64P("startTime", "s", 0, "start time")
57+
historyDustCmd.Flags().Int64P("endTime", "e", 0, "end time")
58+
59+
dustCmd.AddCommand(showDustCmd, convertDustCmd, historyDustCmd)
60+
return []*cobra.Command{dustCmd}
61+
}
62+
63+
func showDust(cmd *cobra.Command, args []string) {
64+
accountType, _ := cmd.Flags().GetString("accountType")
65+
client := wallet.Client{Client: exchange.NewClient(config.Config.APIKey, config.Config.APISecret)}
66+
list, totalBTC, totalBNB, percentage, err := client.ShowDust(accountType)
67+
if err != nil {
68+
fmt.Println("Error getting dust list:", err)
69+
return
70+
}
71+
printer.PrintTable(&list)
72+
fmt.Printf("\nTotal BTC: %s, Total BNB: %s, Percentage: %s\n", totalBTC, totalBNB, percentage)
73+
}
74+
75+
func convertDust(cmd *cobra.Command, args []string) {
76+
asset, _ := cmd.Flags().GetString("asset")
77+
accountType, _ := cmd.Flags().GetString("accountType")
78+
79+
client := wallet.Client{Client: exchange.NewClient(config.Config.APIKey, config.Config.APISecret)}
80+
list, totalServiceCharge, totalTransfered, err := client.ConvertDust(asset, accountType)
81+
if err != nil {
82+
fmt.Println("Error converting dust:", err)
83+
return
84+
}
85+
printer.PrintTable(&list)
86+
fmt.Printf("\nTotal Service Charge: %s, Total Transfered: %s\n", totalServiceCharge, totalTransfered)
87+
}
88+
89+
func historyDust(cmd *cobra.Command, args []string) {
90+
startTime, _ := cmd.Flags().GetInt64("startTime")
91+
endTime, _ := cmd.Flags().GetInt64("endTime")
92+
93+
client := wallet.Client{Client: exchange.NewClient(config.Config.APIKey, config.Config.APISecret)}
94+
list, err := client.HistoryDust(startTime, endTime)
95+
if err != nil {
96+
fmt.Println("Error getting history dust:", err)
97+
return
98+
}
99+
printer.PrintTable(&list)
100+
}

cmd/spot/fee.go renamed to cmd/wallet/fee.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
package spot
1+
package wallet
22

33
import (
44
"fmt"
55
"log"
66

77
"github.com/UnipayFI/binance-cli/config"
88
"github.com/UnipayFI/binance-cli/exchange"
9-
"github.com/UnipayFI/binance-cli/exchange/spot"
9+
"github.com/UnipayFI/binance-cli/exchange/wallet"
1010
"github.com/spf13/cobra"
1111
)
1212

@@ -48,7 +48,7 @@ func InitFeeCmds() []*cobra.Command {
4848
}
4949

5050
func feeBurnStatus(cmd *cobra.Command, _ []string) {
51-
client := spot.Client{Client: exchange.NewClient(config.Config.APIKey, config.Config.APISecret)}
51+
client := wallet.Client{Client: exchange.NewClient(config.Config.APIKey, config.Config.APISecret)}
5252
burnStatus, err := client.GetFeeBurnStatus()
5353
if err != nil {
5454
log.Fatalf("futures fee burn status error: %v", err)
@@ -59,7 +59,7 @@ func feeBurnStatus(cmd *cobra.Command, _ []string) {
5959
func setFeeBurnStatus(cmd *cobra.Command, _ []string) {
6060
spotBNBBurn, _ := cmd.Flags().GetBool("spotBNBBurn")
6161
interestBNBBurn, _ := cmd.Flags().GetBool("interestBNBBurn")
62-
client := spot.Client{Client: exchange.NewClient(config.Config.APIKey, config.Config.APISecret)}
62+
client := wallet.Client{Client: exchange.NewClient(config.Config.APIKey, config.Config.APISecret)}
6363
burnStatus, err := client.SetFeeBurnStatus(spotBNBBurn, interestBNBBurn)
6464
if err != nil {
6565
log.Fatalf("futures fee burn status change error: %v", err)
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
package cmd
1+
package wallet
22

33
import (
44
"fmt"
55
"log"
66

77
"github.com/UnipayFI/binance-cli/config"
88
"github.com/UnipayFI/binance-cli/exchange"
9-
universaltransfer "github.com/UnipayFI/binance-cli/exchange/universal_transfer"
9+
"github.com/UnipayFI/binance-cli/exchange/wallet"
1010
"github.com/UnipayFI/binance-cli/printer"
1111
"github.com/spf13/cobra"
1212
)
@@ -52,7 +52,7 @@ Docs Link: https://developers.binance.com/docs/wallet/asset/user-universal-trans
5252
}
5353
)
5454

55-
func init() {
55+
func InitUniversalTransferCmds() []*cobra.Command {
5656
universalTransferListCmd.Flags().String("type", "", "transfer type")
5757
universalTransferListCmd.Flags().Int64("startTime", 0, "start time")
5858
universalTransferListCmd.Flags().Int64("endTime", 0, "end time")
@@ -67,7 +67,7 @@ func init() {
6767
transferCmd.Flags().String("fromSymbol", "", "from symbol")
6868
transferCmd.Flags().String("toSymbol", "", "to symbol")
6969
universalTransferCmd.AddCommand(universalTransferListCmd, transferCmd)
70-
RootCmd.AddCommand(universalTransferCmd)
70+
return []*cobra.Command{universalTransferCmd}
7171
}
7272

7373
func universalTransferList(cmd *cobra.Command, args []string) {
@@ -79,7 +79,7 @@ func universalTransferList(cmd *cobra.Command, args []string) {
7979
fromSymbol, _ := cmd.Flags().GetString("fromSymbol")
8080
toSymbol, _ := cmd.Flags().GetString("toSymbol")
8181

82-
client := universaltransfer.Client{Client: exchange.NewClient(config.Config.APIKey, config.Config.APISecret)}
82+
client := wallet.Client{Client: exchange.NewClient(config.Config.APIKey, config.Config.APISecret)}
8383
list, err := client.List(transferType, startTime, endTime, current, size, fromSymbol, toSymbol)
8484
if err != nil {
8585
log.Fatal(err)
@@ -94,7 +94,7 @@ func universalTransfer(cmd *cobra.Command, args []string) {
9494
fromSymbol, _ := cmd.Flags().GetString("fromSymbol")
9595
toSymbol, _ := cmd.Flags().GetString("toSymbol")
9696

97-
client := universaltransfer.Client{Client: exchange.NewClient(config.Config.APIKey, config.Config.APISecret)}
97+
client := wallet.Client{Client: exchange.NewClient(config.Config.APIKey, config.Config.APISecret)}
9898
err := client.Transfer(transferType, asset, amount, fromSymbol, toSymbol)
9999
if err != nil {
100100
log.Fatal(err)

docs/spot.md

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
- [Account](#account--show-account-info)
55
- [Asset](#asset---show-account-assets)
66
- [Dividend](#dividend---query-asset-dividend-record)
7-
- [Fee](#fee)
8-
- [Get BNB Burn Status](#fee---get-bnb-burn-status)
9-
- [Set BNB Burn Status](#fee---set-bnb-burn-status)
107
- [Order](#order)
118
- [Create Market Order](#order---create-market-order)
129
- [Create Limit Order](#order---create-limit-order)
@@ -53,20 +50,6 @@ Exec: `./binance-cli spot dividend ls`
5350
└─────────────────────┴───────┴──────────┴─────────────────────┴────────────────────┴────────────────┘
5451
```
5552

56-
57-
## Fee
58-
### Fee - Get BNB Burn Status
59-
Exec: `./binance-cli spot fee status`
60-
```shell
61-
fee burn spotBNBBurn: true, interestBNBBurn: false
62-
```
63-
64-
### Fee - Set BNB Burn Status
65-
Exec: `./binance-cli spot fee set --spotBNBBurn=true --interestBNBBurn=true`
66-
```shell
67-
fee burn spotBNBBurn: true, interestBNBBurn: true
68-
```
69-
7053
## Order
7154
> support all docs parameters
7255
> Docs Link: https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#new-order-trade

docs/wallet.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Wallet Module
2+
3+
## Quick Navigation
4+
- [Dust](#dust)
5+
- [Get assets that can be converted into BNB](#dust---get-assets-that-can-be-converted-into-bnb)
6+
- [Convert dust assets to BNB](#dust---convert)
7+
- [Dust conversion history](#dust---history)
8+
- [Fee](#fee)
9+
- [Get BNB Burn Status](#fee---get-bnb-burn-status)
10+
- [Set BNB Burn Status](#fee---set-bnb-burn-status)
11+
- [Universal Transfer](#universal-transfer)
12+
- [Transfer between accounts](#universal-transfer---transfer)
13+
- [Transfer history](#universal-transfer---history)
14+
15+
## Dust
16+
### Dust - Get assets that can be converted into BNB
17+
Exec: `./binance-cli wallet dust show`
18+
```shell
19+
┌────────────┬────────────┬──────────────┬───────────────────────┬────────────────────┬─────────────────────┐
20+
│ FROM ASSET │ AMOUNT │ TRANSFER ID │ SERVICE CHARGE AMOUNT │ TRANSFERRED AMOUNT │ OPERATE TIME │
21+
├────────────┼────────────┼──────────────┼───────────────────────┼────────────────────┼─────────────────────┤
22+
│ BFUSD │ 0.4254 │ 327477161221 │ 0.00000923 │ 0.00046158 │ 2025-11-19 06:21:09 │
23+
│ ETH │ 0.00003919 │ 327477161221 │ 0.00000257 │ 0.00012861 │ 2025-11-19 06:21:09 │
24+
└────────────┴────────────┴──────────────┴───────────────────────┴────────────────────┴─────────────────────┘
25+
26+
Total Service Charge: 0.0000118, Total Transfered: 0.00059019
27+
```
28+
29+
### Dust - Convert
30+
Exec: `./binance-cli wallet dust convert --asset=BFUSD,ETH`
31+
```shell
32+
┌────────────┬────────────┬──────────────┬───────────────────────┬────────────────────┬─────────────────────┐
33+
│ FROM ASSET │ AMOUNT │ TRANSFER ID │ SERVICE CHARGE AMOUNT │ TRANSFERRED AMOUNT │ OPERATE TIME │
34+
├────────────┼────────────┼──────────────┼───────────────────────┼────────────────────┼─────────────────────┤
35+
│ BFUSD │ 0.4254 │ 327477161221 │ 0.00000923 │ 0.00046158 │ 2025-11-19 06:21:09 │
36+
│ ETH │ 0.00003919 │ 327477161221 │ 0.00000257 │ 0.00012861 │ 2025-11-19 06:21:09 │
37+
└────────────┴────────────┴──────────────┴───────────────────────┴────────────────────┴─────────────────────┘
38+
39+
Total Service Charge: 0.0000118, Total Transfered: 0.00059019
40+
```
41+
42+
### Dust - History
43+
Exec: `./binance-cli wallet dust history`
44+
```shell
45+
┌────────────┬────────────┬──────────────┬───────────────────────┬────────────────────┬─────────────────────┐
46+
│ FROM ASSET │ AMOUNT │ TRANSFER ID │ SERVICE CHARGE AMOUNT │ TRANSFERRED AMOUNT │ OPERATE TIME │
47+
├────────────┼────────────┼──────────────┼───────────────────────┼────────────────────┼─────────────────────┤
48+
│ BFUSD │ 0.4254 │ 327477161221 │ 0.00000923 │ 0.00046158 │ 2025-11-19 06:21:10 │
49+
│ ETH │ 0.00003919 │ 327477161221 │ 0.00000257 │ 0.00012861 │ 2025-11-19 06:21:10 │
50+
└────────────┴────────────┴──────────────┴───────────────────────┴────────────────────┴─────────────────────┘
51+
```
52+
53+
## Fee
54+
### Fee - Get BNB Burn Status
55+
Exec: `./binance-cli spot fee status`
56+
```shell
57+
fee burn spotBNBBurn: true, interestBNBBurn: false
58+
```
59+
60+
### Fee - Set BNB Burn Status
61+
Exec: `./binance-cli spot fee set --spotBNBBurn=true --interestBNBBurn=true`
62+
```shell
63+
fee burn spotBNBBurn: true, interestBNBBurn: true
64+
```
65+
66+
## Universal-transfer
67+
### Universal-transfer - transfer
68+
Exec: `./binance-cli wallet universal-transfer --type={type} --asset={asset} --amount={x}`
69+
70+
### Universal-transfer - History
71+
Exec: `./binance-cli universal-transfer ls --type={type}`
72+
```shell
73+
┌───────┬────────┬───────────────────────┬───────────┬──────────────┬─────────────────────┐
74+
│ ASSET │ AMOUNT │ TYPE │ STATUS │ TRAN ID │ TIMESTAMP │
75+
├───────┼────────┼───────────────────────┼───────────┼──────────────┼─────────────────────┤
76+
│ USDC │ 400000 │ MAIN_PORTFOLIO_MARGIN │ CONFIRMED │ 324539848979 │ 2025-11-13 03:37:24 │
77+
└───────┴────────┴───────────────────────┴───────────┴──────────────┴─────────────────────┘
78+
```

exchange/universal_transfer/model.go

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)