Skip to content

Commit 2fb3b7c

Browse files
committed
add futures.md
1 parent 16ec11a commit 2fb3b7c

3 files changed

Lines changed: 174 additions & 11 deletions

File tree

cmd/futures/positions.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var (
2020
positionListCmd = &cobra.Command{
2121
Use: "list",
2222
Aliases: []string{"ls"},
23-
Short: "list positions",
23+
Short: "List positions",
2424
Long: `Get current account's all positions.
2525
2626
Docs Link: https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Account-Information-V3`,
@@ -30,7 +30,7 @@ Docs Link: https://developers.binance.com/docs/derivatives/usds-margined-futures
3030
positionRiskCmd = &cobra.Command{
3131
Use: "risk",
3232
Aliases: []string{"r"},
33-
Short: "show position risk",
33+
Short: "Show position risk",
3434
Long: `Get current position information(only symbol that has position or open orders will be returned).
3535
3636
Docs Link: https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Position-Information-V3`,
@@ -39,7 +39,7 @@ Docs Link: https://developers.binance.com/docs/derivatives/usds-margined-futures
3939

4040
positionMarginCmd = &cobra.Command{
4141
Use: "set-margin",
42-
Short: "set position margin",
42+
Short: "Set position margin",
4343
PreRun: func(cmd *cobra.Command, args []string) {
4444
typ, _ := cmd.Flags().GetString("type")
4545
if typ != "ADD" && typ != "REDUCE" {
@@ -74,8 +74,6 @@ Docs Link: https://developers.binance.com/docs/derivatives/usds-margined-futures
7474
)
7575

7676
func InitPositionsCmds() []*cobra.Command {
77-
positionCmd.AddCommand(positionListCmd)
78-
7977
positionRiskCmd.Flags().StringP("symbol", "s", "", "symbol")
8078

8179
positionMarginCmd.Flags().StringP("symbol", "s", "", "symbol")

cmd/root.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
package cmd
22

33
import (
4-
"log"
4+
"errors"
55

66
"github.com/UnipayFI/binance-cli/config"
77
"github.com/spf13/cobra"
88
)
99

1010
var RootCmd = &cobra.Command{
11-
Use: "binance-cli",
12-
Short: "Binance API for CLI version",
11+
Use: "binance-cli",
12+
Short: "Binance API for CLI version",
13+
PreRunE: checkAPIKey,
1314
}
1415

1516
func init() {
1617
initCommandConfig()
17-
checkAPIKey()
1818
}
1919

2020
func Execute() {
@@ -25,8 +25,9 @@ func initCommandConfig() {
2525
RootCmd.CompletionOptions.DisableDefaultCmd = true
2626
}
2727

28-
func checkAPIKey() {
28+
func checkAPIKey(cmd *cobra.Command, args []string) error {
2929
if config.Config.APIKey == "" || config.Config.APISecret == "" {
30-
log.Fatal("API_KEY and API_SECRET must be set")
30+
return errors.New("API_KEY and API_SECRET must be set")
3131
}
32+
return nil
3233
}

docs/futures.md

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
# Futures Module
2+
3+
## Quick Navigation
4+
5+
## Account - Show account config
6+
Exec: ` ./binance-cli futures account config`
7+
```shell
8+
┌──────────┬───────────┬─────────────┬──────────────┬────────────────────┬─────────────────────┬────────────────┐
9+
│ FEE TIER │ CAN TRADE │ CAN DEPOSIT │ CAN WITHDRAW │ DUAL SIDE POSITION │ MULTI ASSETS MARGIN │ TRADE GROUP ID │
10+
├──────────┼───────────┼─────────────┼──────────────┼────────────────────┼─────────────────────┼────────────────┤
11+
│ 8 │ truetruetruetruefalse │ -1 │
12+
└──────────┴───────────┴─────────────┴──────────────┴────────────────────┴─────────────────────┴────────────────┘
13+
```
14+
15+
## Account - Show account balances
16+
Exec: `./binance-cli futures account balances`
17+
```shell
18+
┌───────┬────────────────┬──────────────────────┬────────────────┬───────────────────┬─────────────────────┐
19+
│ ASSET │ BALANCE │ CROSS WALLET BALANCE │ CROSS UN PNL │ AVAILABLE BALANCE │ MAX WITHDRAW AMOUNT │
20+
├───────┼────────────────┼──────────────────────┼────────────────┼───────────────────┼─────────────────────┤
21+
│ BNB │ 0.09949690 │ 0.09949690 │ 0.00000000 │ 0.09949690 │ 0.09949690 │
22+
│ USDC │ 0.70000000 │ 0.70000000 │ 0.00000000 │ 0.70000000 │ 0.70000000 │
23+
└───────┴────────────────┴──────────────────────┴────────────────┴───────────────────┴─────────────────────┘
24+
```
25+
26+
## Commission-rate - Show commission rate
27+
Exec: `./binance-cli futures commission-rate --symbol=BTCUSDT`
28+
```shell
29+
┌─────────┬───────────────────────┬───────────────────────┐
30+
│ SYMBOL │ MAKER COMMISSION RATE │ TAKER COMMISSION RATE │
31+
├─────────┼───────────────────────┼───────────────────────┤
32+
│ BTCUSDT │ -0.0030% │ 0.0200% │
33+
└─────────┴───────────────────────┴───────────────────────┘
34+
```
35+
36+
## Fee - Get BNB Burn Status
37+
Exec: `./binance-cli futures fee status`
38+
39+
## Fee - Change user's BNB Fee Discount on EVERY symbol
40+
Exec: `./binance-cli futures fee set --feeBurn=true`
41+
42+
## Income - Query income history
43+
Exec: `/binance-cli futures income`
44+
```shell
45+
┌───────┬─────────────────┬──────────────┬─────────────┬─────────┬─────────────────────┬───────────────────┬────────────┐
46+
│ ASSET │ INCOME │ INCOME TYPE │ INFO │ SYMBOL │ TIME │ TRAN ID │ TRADE ID │
47+
├───────┼─────────────────┼──────────────┼─────────────┼─────────┼─────────────────────┼───────────────────┼────────────┤
48+
│ USDT │ 0.02824612 │ COMMISSION │ 6560390403 │ BTCUSDT │ 2025-08-16 13:52:58 │ 900316560390403 │ 6560390403 │
49+
│ USDT │ -3.81817128 │ REALIZED_PNL │ 6560390646 │ BTCUSDT │ 2025-08-16 13:53:00 │ 900316560390646 │ 6560390646 │
50+
│ USDT │ 0.02824173 │ COMMISSION │ 6560390646 │ BTCUSDT │ 2025-08-16 13:53:00 │ 900316560390646 │ 6560390646 │
51+
└───────┴─────────────────┴──────────────┴─────────────┴─────────┴─────────────────────┴───────────────────┴────────────┘
52+
```
53+
54+
## Multi-assets-mode - Show multi-assets mode
55+
Exec: `./binance-cli futures multi-assets-mode show`
56+
57+
## Multi-assets-mode - Set multi-assets mode
58+
Exec: `./binance-cli futures multi-assets-mode set --multiAssetsMargin=true`
59+
60+
## Order
61+
> support all docs parameters
62+
> Docs Link: https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/New-Order-Trade
63+
64+
### Order - Create Market Order
65+
Exec: `./binance-cli futures order create --symbol=ETHUSDT --side=BUY --positionSide=SHORT --type=MARKET --quantity=0.1`
66+
67+
### Order - Create Limit Order
68+
Exec: `./binance-cli futures order create --symbol=ETHUSDT --side=BUY --positionSide=LONG --type=LIMIT --timeInForce=GTC --quantity=0.01 --price=4000`
69+
70+
### Order - Reduce short positions(Market)
71+
Exec: `./binance-cli futures order create --symbol=ETHUSDT --side=SELL --positionSide=SHORT --type=MARKET --quantity=1.0`
72+
73+
### Order - Reduce long positions(Limit)
74+
Exec: `./binance-cli futures order create --symbol=ETHUSDT --side=SELL --positionSide=LONG --type=LIMIT --timeInForce=GTC --price=4000.0 --quantity=0.01`
75+
76+
### Order - list open orders
77+
Exec: `./binance-cli futures order open`
78+
```shell
79+
┌─────────────────────┬─────────┬──────┬───────────────┬────────┬───────┬──────────┬───────────────────┬─────────────────────┬─────────────────────┐
80+
│ ORDER ID │ SYMBOL │ SIDE │ POSITION SIDE │ STATUS │ PRICE │ QUANTITY │ EXECUTED QUANTITY │ TIME │ UPDATE TIME │
81+
├─────────────────────┼─────────┼──────┼───────────────┼────────┼───────┼──────────┼───────────────────┼─────────────────────┼─────────────────────┤
82+
│ 8389765940941702977 │ ETHUSDT │ BUY │ LONG │ NEW │ 4000 │ 0.010 │ 0 │ 2025-08-19 15:32:41 │ 2025-08-19 15:32:41 │
83+
└─────────────────────┴─────────┴──────┴───────────────┴────────┴───────┴──────────┴───────────────────┴─────────────────────┴─────────────────────┘
84+
```
85+
86+
### Order - list orders
87+
Exec: `./binance-cli futures order ls`
88+
```shell
89+
┌─────────────────────┬─────────┬──────┬───────────────┬──────────┬───────┬──────────┬───────────────────┬─────────────────────┬─────────────────────┐
90+
│ ORDER ID │ SYMBOL │ SIDE │ POSITION SIDE │ STATUS │ PRICE │ QUANTITY │ EXECUTED QUANTITY │ TIME │ UPDATE TIME │
91+
├─────────────────────┼─────────┼──────┼───────────────┼──────────┼───────┼──────────┼───────────────────┼─────────────────────┼─────────────────────┤
92+
│ 8389765940941702977 │ ETHUSDT │ BUY │ LONG │ CANCELED │ 4000 │ 0.010 │ 0 │ 2025-08-19 15:32:41 │ 2025-08-19 15:33:17 │
93+
└─────────────────────┴─────────┴──────┴───────────────┴──────────┴───────┴──────────┴───────────────────┴─────────────────────┴─────────────────────┘
94+
```
95+
96+
### Order - Cancel order by ID
97+
Exec: `./binance-cli futures order cancel --symbol=ETHUSDT --orderId=xxx`
98+
OR
99+
`./binance-cli futures order cancel --symbol=ETHUSDT --origClientOrderId=xxx`
100+
101+
### Order - Cancel all order by symbol
102+
Exec: `./binance-cli futures order cancel --symbol=ETHUSDT`
103+
104+
## Position
105+
106+
### Position - List positions
107+
Exec: `./binance-cli futures position ls`
108+
```shell
109+
┌─────────┬───────────────┬─────────────────┬────────────────┬───────────────────┬──────────┬─────────────────────┐
110+
│ SYMBOL │ POSITION SIDE │ POSITION AMOUNT │ ENTRY PRICE │ UNREALIZED PROFIT │ LEVERAGE │ UPDATE TIME │
111+
├─────────┼───────────────┼─────────────────┼────────────────┼───────────────────┼──────────┼─────────────────────┤
112+
│ BTCUSDT │ SHORT │ -0.186 │ 117196.6285896 │ 443.67111766 │ 10 │ 2025-08-18 15:53:21 │
113+
└─────────┴───────────────┴─────────────────┴────────────────┴───────────────────┴──────────┴─────────────────────┘
114+
```
115+
116+
### Position - Show position risk
117+
Exec: `./binance-cli futures position risk`
118+
```shell
119+
┌─────────┬───────────────┬─────────────────┬─────────────────┬────────────────┬─────────────────┬───────────────────┬───────────────────┬─────────────────────┐
120+
│ SYMBOL │ POSITION SIDE │ POSITION AMOUNT │ NOTIONAL │ ENTRY PRICE │ MARK PRICE │ UNREALIZED PROFIT │ LIQUIDATION PRICE │ UPDATE TIME │
121+
├─────────┼───────────────┼─────────────────┼─────────────────┼────────────────┼─────────────────┼───────────────────┼───────────────────┼─────────────────────┤
122+
│ BTCUSDT │ SHORT │ -0.186 BTC │ -21345.25499086 │ 117196.6285896 │ 114759.43543478 │ 453.31792679 │ 536665.62249500 │ 2025-08-18 15:53:21 │
123+
└─────────┴───────────────┴─────────────────┴─────────────────┴────────────────┴─────────────────┴───────────────────┴───────────────────┴─────────────────────┘
124+
```
125+
126+
### Position - Set position margin
127+
Exec: `./binance-cli futures position set-margin --amount=1.0 --positionSide=SHORT --symbol=BTCUSDT --type=ADD`
128+
129+
### Position - Change Position Mode
130+
Exec: `./binance-cli futures position set-side --dualSidePosition=true`
131+
132+
### Position - Get user's position mode on EVERY symbol
133+
Exec: `./binance-cli futures position side`
134+
135+
## Symbol
136+
137+
### Symbol - Change Initial Leverage
138+
Exec: `./binance-cli futures symbol set-leverage --symbol=BTCUSDT --leverage=10`
139+
140+
### Symbol - Set margin type
141+
Exec: `./binance-cli futures symbol set-margin-type --symbol=BTCUSDT --marginType=CROSSED`
142+
143+
### Symbol - Show symbol config
144+
Exec: ` ./binance-cli futures symbol show --symbol=BTCUSDT`
145+
```shell
146+
┌─────────┬─────────────┬────────────────────┬──────────┬────────────────────┐
147+
│ SYMBOL │ MARGIN TYPE │ IS AUTO ADD MARGIN │ LEVERAGE │ MAX NOTIONAL VALUE │
148+
├─────────┼─────────────┼────────────────────┼──────────┼────────────────────┤
149+
│ BTCUSDT │ CROSSED │ false │ 10 │ 230000000 │
150+
└─────────┴─────────────┴────────────────────┴──────────┴────────────────────┘
151+
```
152+
153+
## Trade - Get trades for a specific account and symbol.
154+
Exec: `./binance-cli futures trade ls --symbol=BTCUSDT`
155+
```shell
156+
┌──────────────┬─────────┬──────┬───────────────┬───────────┬──────────┬────────────────┬──────────────┬─────────────────────┐
157+
│ ORDER ID │ SYMBOL │ SIDE │ POSITION SIDE │ PRICE │ QUANTITY │ QUOTE QUANTITY │ REALIZED PNL │ TIME │
158+
├──────────────┼─────────┼──────┼───────────────┼───────────┼──────────┼────────────────┼──────────────┼─────────────────────┤
159+
│ 749374403589 │ BTCUSDT │ BUY │ SHORT │ 119711.70 │ 0.008 │ 957.69360 │ -29.22242085 │ 2025-08-11 12:51:09 │
160+
│ 749374653742 │ BTCUSDT │ BUY │ SHORT │ 119722.70 │ 0.008 │ 957.78160 │ -29.31042085 │ 2025-08-11 12:51:23 │
161+
│ 749400923511 │ BTCUSDT │ BUY │ SHORT │ 119907.80 │ 0.008 │ 959.26240 │ -30.79122085 │ 2025-08-11 13:36:25 │
162+
│ 749400940699 │ BTCUSDT │ BUY │ SHORT │ 119887.20 │ 0.008 │ 959.09760 │ -30.62642085 │ 2025-08-11 13:36:27 │
163+
└──────────────┴─────────┴──────┴───────────────┴───────────┴──────────┴────────────────┴──────────────┴─────────────────────┘
164+
```

0 commit comments

Comments
 (0)