Skip to content

Commit ba728fc

Browse files
committed
support spot BNB burn
1 parent 03c9dd5 commit ba728fc

4 files changed

Lines changed: 111 additions & 0 deletions

File tree

cmd/spot.go

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

cmd/spot/fee.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package spot
2+
3+
import (
4+
"fmt"
5+
"log"
6+
7+
"github.com/UnipayFI/binance-cli/config"
8+
"github.com/UnipayFI/binance-cli/exchange"
9+
"github.com/UnipayFI/binance-cli/exchange/spot"
10+
"github.com/spf13/cobra"
11+
)
12+
13+
var (
14+
feeCmd = &cobra.Command{
15+
Use: "fee",
16+
Short: "BNB payment fee",
17+
Long: `BNB payment fee.`,
18+
}
19+
20+
feeBurnStatusCmd = &cobra.Command{
21+
Use: "status",
22+
Aliases: []string{"s"},
23+
Short: "Get BNB Burn Status",
24+
Long: `Get BNB Burn Status.
25+
26+
Docs Link: https://developers.binance.com/docs/margin_trading/account/Get-BNB-Burn-Status`,
27+
Run: feeBurnStatus,
28+
}
29+
30+
feeBurnStatusSetCmd = &cobra.Command{
31+
Use: "set",
32+
Aliases: []string{"c"},
33+
Short: "Toggle BNB Burn On Spot Trade And Margin Interest",
34+
Long: `Toggle BNB Burn On Spot Trade And Margin Interest.
35+
36+
Docs Link: https://developers.binance.com/docs/wallet/asset/Toggle-BNB-Burn-On-Spot-Trade-And-Margin-Interest`,
37+
Run: setFeeBurnStatus,
38+
}
39+
)
40+
41+
func InitFeeCmds() []*cobra.Command {
42+
feeBurnStatusSetCmd.Flags().BoolP("spotBNBBurn", "s", false, "Determines whether to use BNB to pay for trading fees on SPOT")
43+
feeBurnStatusSetCmd.Flags().BoolP("interestBNBBurn", "i", false, "Determines whether to use BNB to pay for margin loan's interest")
44+
feeBurnStatusSetCmd.MarkFlagRequired("status")
45+
46+
feeCmd.AddCommand(feeBurnStatusCmd, feeBurnStatusSetCmd)
47+
return []*cobra.Command{feeCmd}
48+
}
49+
50+
func feeBurnStatus(cmd *cobra.Command, _ []string) {
51+
client := spot.Client{Client: exchange.NewClient(config.Config.APIKey, config.Config.APISecret)}
52+
burnStatus, err := client.GetFeeBurnStatus()
53+
if err != nil {
54+
log.Fatalf("futures fee burn status error: %v", err)
55+
}
56+
fmt.Printf("fee burn spotBNBBurn: %v, interestBNBBurn: %v\n", burnStatus.SpotBNBBurn, burnStatus.InterestBNBBurn)
57+
}
58+
59+
func setFeeBurnStatus(cmd *cobra.Command, _ []string) {
60+
spotBNBBurn, _ := cmd.Flags().GetBool("spotBNBBurn")
61+
interestBNBBurn, _ := cmd.Flags().GetBool("interestBNBBurn")
62+
client := spot.Client{Client: exchange.NewClient(config.Config.APIKey, config.Config.APISecret)}
63+
burnStatus, err := client.SetFeeBurnStatus(spotBNBBurn, interestBNBBurn)
64+
if err != nil {
65+
log.Fatalf("futures fee burn status change error: %v", err)
66+
}
67+
fmt.Printf("fee burn changed to spotBNBBurn: %v, interestBNBBurn: %v\n", burnStatus.SpotBNBBurn, burnStatus.InterestBNBBurn)
68+
}

docs/spot.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
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)
710
- [Order](#order)
811
- [Create Market Order](#order---create-market-order)
912
- [Create Limit Order](#order---create-limit-order)
@@ -50,6 +53,20 @@ Exec: `./binance-cli spot dividend ls`
5053
└─────────────────────┴───────┴──────────┴─────────────────────┴────────────────────┴────────────────┘
5154
```
5255

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+
5370
## Order
5471
> support all docs parameters
5572
> Docs Link: https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#new-order-trade

exchange/spot/fee.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package spot
2+
3+
import (
4+
"context"
5+
6+
"github.com/adshao/go-binance/v2"
7+
)
8+
9+
func (c *Client) GetFeeBurnStatus() (binance.BNBBurn, error) {
10+
service := binance.NewClient(c.ApiKey, c.ApiSecret).NewGetBNBBurnService()
11+
response, err := service.Do(context.Background())
12+
if err != nil {
13+
return binance.BNBBurn{}, err
14+
}
15+
return *response, nil
16+
}
17+
18+
func (c *Client) SetFeeBurnStatus(spotBNBBurn, interestBNBBurn bool) (binance.BNBBurn, error) {
19+
service := binance.NewClient(c.ApiKey, c.ApiSecret).NewToggleBNBBurnService()
20+
response, err := service.SpotBNBBurn(spotBNBBurn).InterestBNBBurn(interestBNBBurn).Do(context.Background())
21+
if err != nil {
22+
return binance.BNBBurn{}, err
23+
}
24+
return *response, nil
25+
}

0 commit comments

Comments
 (0)