forked from amir-the-h/okex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.go
37 lines (32 loc) · 1014 Bytes
/
api.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
package api
import (
"context"
"github.com/amir-the-h/okex"
"github.com/amir-the-h/okex/api/rest"
"github.com/amir-the-h/okex/api/ws"
)
// Client is the main api wrapper of okex
type Client struct {
Rest *rest.ClientRest
Ws *ws.ClientWs
ctx context.Context
}
// NewClient returns a pointer to a fresh Client
func NewClient(ctx context.Context, apiKey, secretKey, passphrase string, destination okex.Destination) (*Client, error) {
restURL := okex.RestURL
wsPubURL := okex.PublicWsURL
wsPriURL := okex.PrivateWsURL
switch destination {
case okex.AwsServer:
restURL = okex.AwsRestURL
wsPubURL = okex.AwsPublicWsURL
wsPriURL = okex.AwsPrivateWsURL
case okex.DemoServer:
restURL = okex.DemoRestURL
wsPubURL = okex.DemoPublicWsURL
wsPriURL = okex.DemoPrivateWsURL
}
r := rest.NewClient(apiKey, secretKey, passphrase, restURL, destination)
c := ws.NewClient(ctx, apiKey, secretKey, passphrase, map[bool]okex.BaseURL{true: wsPriURL, false: wsPubURL})
return &Client{r, c, ctx}, nil
}