-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbybit_test.go
More file actions
58 lines (52 loc) · 1.36 KB
/
bybit_test.go
File metadata and controls
58 lines (52 loc) · 1.36 KB
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
package main_test
import (
"context"
"encoding/json"
"fmt"
"testing"
"time"
"github.com/nikita55612/goTradingBot/internal/broker/bybit"
"github.com/nikita55612/goTradingBot/internal/pkg/cdl"
)
func TestGetInstrumentInfo(t *testing.T) {
cli := bybit.NewClientFromEnv(bybit.WithCategory("linear"))
instrumentInfo, err := cli.GetInstrumentInfo("BTCUSDT")
if err != nil {
t.Fatal(err)
}
data, _ := json.MarshalIndent(instrumentInfo, "", " ")
fmt.Println(string(data))
}
func TestGetCandles(t *testing.T) {
cli := bybit.NewClientFromEnv(bybit.WithCategory("linear"))
candles, err := cli.GetCandles("BTCUSDT", cdl.M15, 10)
if err != nil {
t.Fatal(err)
}
data, _ := json.MarshalIndent(candles, "", " ")
fmt.Println(string(data))
}
func TestGetAccountInfo(t *testing.T) {
cli := bybit.NewClientFromEnv(bybit.WithCategory("linear"))
accountInfo, err := cli.GetAccountInfo()
if err != nil {
t.Fatal(err)
}
data, _ := json.MarshalIndent(accountInfo, "", " ")
fmt.Println(string(data))
}
func TestCandleStream(t *testing.T) {
cli := bybit.NewClientFromEnv(bybit.WithCategory("linear"))
ctx, cancel := context.WithCancel(context.Background())
stream, err := cli.CandleStream(ctx, "BTCUSDT", cdl.M15)
if err != nil {
t.Fatal(err)
}
go func() {
<-time.After(time.Minute)
cancel()
}()
for data := range stream {
fmt.Printf("%+v\n", data)
}
}