|
| 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 | +} |
0 commit comments