-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathbinance.go
More file actions
70 lines (59 loc) · 1.89 KB
/
binance.go
File metadata and controls
70 lines (59 loc) · 1.89 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
59
60
61
62
63
64
65
66
67
68
69
70
//Package binance provides the binding for Binance Rest APIs
package binance
import (
"net/http"
"time"
"github.com/apisit/binance-go/account"
"github.com/apisit/binance-go/client"
"github.com/apisit/binance-go/general"
"github.com/apisit/binance-go/market"
"github.com/apisit/binance-go/stream"
)
//constant used for API client
const (
APIURL = "https://www.binance.com"
StreamAPIURL = "wss://stream.binance.com:9443/ws"
clientVersion = "0.1"
UserAgent = "github.com/apisit/binance-go version/" + clientVersion
defaultHTTPTimeout = 80 * time.Second
)
//Default HTTP client
var httpClient = &http.Client{Timeout: defaultHTTPTimeout}
//Binance API Key
var APIKey string
var SecretKey string
//Use Market endpoint without client
func Market() *market.Client {
api := client.New(APIURL, APIKey, SecretKey, httpClient, UserAgent)
return &market.Client{*api}
}
//Use General endpoint without client
func General() *general.Client {
api := client.New(APIURL, APIKey, SecretKey, httpClient, UserAgent)
return &general.Client{*api}
}
//Use Account endpoint without client
func Account() *account.Client {
api := client.New(APIURL, APIKey, SecretKey, httpClient, UserAgent)
return &account.Client{*api}
}
//Use Stream endpoint without client
func Stream() *stream.Client {
api := client.New(APIURL, APIKey, SecretKey, httpClient, UserAgent)
return &stream.Client{*api}
}
//Client is the Binance client. It contains all resources available.
type Client struct {
Market market.Client
General general.Client
Account account.Client
Stream stream.Client
}
//Init initializes the Binance client with given API key, secret key.
func (c *Client) Init(apiKey, secretKey string) {
api := client.New(APIURL, apiKey, secretKey, httpClient, UserAgent)
c.Market = market.Client{*api}
c.General = general.Client{*api}
c.Account = account.Client{*api}
c.Stream = stream.Client{*api}
}