-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackpack_execute_order_test.go
62 lines (55 loc) · 1.51 KB
/
backpack_execute_order_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package backpackgo
import (
"fmt"
"os"
"testing"
"github.com/UnipayFI/backpack-go/options"
"github.com/UnipayFI/backpack-go/rest"
)
func TestBackpackExecuteOrder(t *testing.T) {
rest := NewRESTClient(rest.WithAPIToken(os.Getenv("API_KEY"), os.Getenv("API_SECRET")))
symbol := "SOL_USDC"
// test ExecuteMarketOrder
t.Run("test ExecuteMarketOrder", func(t *testing.T) {
var err error
order, err := rest.ExecuteMarketOrder(symbol+"_PERP", options.Buy, 0.1, options.WithAutoLendRedeem(true), options.WithTimeInForce(options.TimeInForceFOK))
if err != nil {
t.Errorf("ExecuteOrder failed: %v", err)
} else {
fmt.Printf("OK: ExecuteOrder, order id: %+v\n\n", order.ID)
}
})
// test ExecuteLimitOrder
t.Run("test basic ExecuteLimitOrder", func(t *testing.T) {
order, err := rest.ExecuteLimitOrder(
symbol,
options.Sell,
500,
0.11,
options.WithAutoLendRedeem(true),
)
if err != nil {
t.Errorf("ExecuteOrder failed: %v", err)
} else {
rest.CancelOrderByOrderID(symbol, order.ID)
fmt.Printf("OK: ExecuteOrder, order id: %+v\n\n", order.ID)
}
})
// test ExecuteConditionalLimitOrder
t.Run("test ExecuteConditionalLimitOrder", func(t *testing.T) {
order, err := rest.ExecuteConditionalLimitOrder(
symbol,
options.Sell,
500,
490,
0.1,
options.WithAutoLendRedeem(true),
)
if err != nil {
t.Errorf("ExecuteOrder failed: %v", err)
} else {
rest.CancelOrderByOrderID(symbol, order.ID)
fmt.Printf("OK: ExecuteOrder, order id: %+v\n\n", order.ID)
}
})
}