-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbybit.go
63 lines (54 loc) · 1.16 KB
/
bybit.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
63
package bybit
//# version 0.0.3
import (
"encoding/json"
"fmt"
"log"
)
type Response struct {
RetCode int `json:"retCode"`
RetMsg string `json:"retMsg"`
Result interface{} `json:"result"`
RetExtInfo interface{} `json:"retExtInfo"`
Time int `json:"time"`
}
type CallParams struct {
Method string
EndPoint string
Params interface{}
Fields []string
}
func getResponse(body []byte, a any) Response {
var r Response
err := json.Unmarshal(body, &r)
if err != nil {
fmt.Println("err:", err)
}
Recast(r.Result, &a)
r.Result = a
return r
}
func Call(c *CallParams, a any) {
MODE := GetEnv("BYBIT_MODE")
API_KEY := GetEnv("BYBIT_API_KEY")
API_SECRET := GetEnv("BYBIT_API_SECRET")
Client := NewConnector().
SetKeys(API_KEY, API_SECRET).
SetUrl(MODE).
SetParams(c.Params, c.Fields).
SetEndPoint(c.EndPoint)
var body []byte
switch c.Method {
case "GET":
body, _ = Client.GetRequest()
case "POST":
body, _ = Client.PostRequest()
default:
panic("method missing...")
}
x := getResponse(body, a)
if x.RetCode != 0 {
log.Default().Println("code=", x.RetCode)
log.Default().Println("msg=", x.RetMsg)
}
}