|
| 1 | +package margin |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "log" |
| 6 | + |
| 7 | + "github.com/UnipayFI/binance-cli/config" |
| 8 | + "github.com/UnipayFI/binance-cli/exchange/portfolio/margin" |
| 9 | + "github.com/UnipayFI/binance-cli/printer" |
| 10 | + "github.com/spf13/cobra" |
| 11 | +) |
| 12 | + |
| 13 | +var ( |
| 14 | + borrowCmd = &cobra.Command{ |
| 15 | + Use: "borrow", |
| 16 | + Short: "Borrow", |
| 17 | + Long: `Query margin max borrow and max withdraw.`, |
| 18 | + } |
| 19 | + |
| 20 | + marginMaxBorrowCmd = &cobra.Command{ |
| 21 | + Use: "max-borrow", |
| 22 | + Short: "Query margin max borrow", |
| 23 | + Long: `Query margin max borrow. |
| 24 | + |
| 25 | +Docs Link: https://developers.binance.com/docs/derivatives/portfolio-margin/account/Margin-Max-Borrow`, |
| 26 | + Run: marginMaxBorrow, |
| 27 | + } |
| 28 | + |
| 29 | + marginMaxWithdrawCmd = &cobra.Command{ |
| 30 | + Use: "max-withdraw", |
| 31 | + Short: "Query Margin Max Withdraw", |
| 32 | + Long: `Query Margin Max Withdraw. |
| 33 | + |
| 34 | +Docs Link: https://developers.binance.com/docs/derivatives/portfolio-margin/account/Query-Margin-Max-Withdraw`, |
| 35 | + Run: marginMaxWithdraw, |
| 36 | + } |
| 37 | +) |
| 38 | + |
| 39 | +func InitBorrowCmds() []*cobra.Command { |
| 40 | + marginMaxBorrowCmd.Flags().StringP("asset", "a", "", "asset") |
| 41 | + marginMaxBorrowCmd.MarkFlagRequired("asset") |
| 42 | + marginMaxWithdrawCmd.Flags().StringP("asset", "a", "", "asset") |
| 43 | + marginMaxWithdrawCmd.MarkFlagRequired("asset") |
| 44 | + borrowCmd.AddCommand(marginMaxBorrowCmd, marginMaxWithdrawCmd) |
| 45 | + return []*cobra.Command{borrowCmd} |
| 46 | +} |
| 47 | + |
| 48 | +func marginMaxBorrow(cmd *cobra.Command, _ []string) { |
| 49 | + asset, _ := cmd.Flags().GetString("asset") |
| 50 | + client := margin.NewClient(config.Config.APIKey, config.Config.APISecret) |
| 51 | + borrow, err := client.MarginMaxBorrow(asset) |
| 52 | + if err != nil { |
| 53 | + log.Fatal(err) |
| 54 | + } |
| 55 | + printer.PrintTable(borrow) |
| 56 | +} |
| 57 | + |
| 58 | +func marginMaxWithdraw(cmd *cobra.Command, _ []string) { |
| 59 | + asset, _ := cmd.Flags().GetString("asset") |
| 60 | + client := margin.NewClient(config.Config.APIKey, config.Config.APISecret) |
| 61 | + withdraw, err := client.MarginMaxWithdraw(asset) |
| 62 | + if err != nil { |
| 63 | + log.Fatal(err) |
| 64 | + } |
| 65 | + fmt.Printf("margin max withdraw: %s %s\n", withdraw, asset) |
| 66 | +} |
0 commit comments