forked from nntaoli-project/goex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gdax.go
126 lines (107 loc) · 3.26 KB
/
gdax.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package gdax
import (
"fmt"
. "github.com/nntaoli-project/GoEx"
"net/http"
"sort"
)
//www.coinbase.com or www.gdax.com
type Gdax struct {
httpClient *http.Client
baseUrl,
accessKey,
secretKey string
}
func New(client *http.Client, accesskey, secretkey string) *Gdax {
return &Gdax{client, "https://api.gdax.com", accesskey, secretkey}
}
func (g *Gdax) LimitBuy(amount, price string, currency CurrencyPair) (*Order, error) {
panic("not implement")
}
func (g *Gdax) LimitSell(amount, price string, currency CurrencyPair) (*Order, error) {
panic("not implement")
}
func (g *Gdax) MarketBuy(amount, price string, currency CurrencyPair) (*Order, error) {
panic("not implement")
}
func (g *Gdax) MarketSell(amount, price string, currency CurrencyPair) (*Order, error) {
panic("not implement")
}
func (g *Gdax) CancelOrder(orderId string, currency CurrencyPair) (bool, error) {
panic("not implement")
}
func (g *Gdax) GetOneOrder(orderId string, currency CurrencyPair) (*Order, error) {
panic("not implement")
}
func (g *Gdax) GetUnfinishOrders(currency CurrencyPair) ([]Order, error) {
panic("not implement")
}
func (g *Gdax) GetOrderHistorys(currency CurrencyPair, currentPage, pageSize int) ([]Order, error) {
panic("not implement")
}
func (g *Gdax) GetAccount() (*Account, error) {
panic("not implement")
}
func (g *Gdax) GetTicker(currency CurrencyPair) (*Ticker, error) {
resp, err := HttpGet(g.httpClient, fmt.Sprintf("%s/products/%s/ticker", g.baseUrl, currency.ToSymbol("-")))
if err != nil {
errCode := HTTP_ERR_CODE
errCode.OriginErrMsg = err.Error()
return nil, errCode
}
return &Ticker{
Last: ToFloat64(resp["price"]),
Sell: ToFloat64(resp["ask"]),
Buy: ToFloat64(resp["bid"]),
Vol: ToFloat64(resp["volume"]),
}, nil
}
func (g *Gdax) Get24HStats(pair CurrencyPair) (*Ticker, error) {
resp, err := HttpGet(g.httpClient, fmt.Sprintf("%s/products/%s/stats", g.baseUrl, pair.ToSymbol("-")))
if err != nil {
errCode := HTTP_ERR_CODE
errCode.OriginErrMsg = err.Error()
return nil, errCode
}
return &Ticker{
High: ToFloat64(resp["high"]),
Low: ToFloat64(resp["low"]),
Vol: ToFloat64(resp["volmue"]),
Last: ToFloat64(resp["last"]),
}, nil
}
func (g *Gdax) GetDepth(size int, currency CurrencyPair) (*Depth, error) {
var level int = 2
if size == 1 {
level = 1
}
resp, err := HttpGet(g.httpClient, fmt.Sprintf("%s/products/%s/book?level=%d", g.baseUrl, currency.ToSymbol("-"), level))
if err != nil {
errCode := HTTP_ERR_CODE
errCode.OriginErrMsg = err.Error()
return nil, errCode
}
bids, _ := resp["bids"].([]interface{})
asks, _ := resp["asks"].([]interface{})
dep := new(Depth)
for _, v := range bids {
r := v.([]interface{})
dep.BidList = append(dep.BidList, DepthRecord{ToFloat64(r[0]), ToFloat64(r[1])})
}
for _, v := range asks {
r := v.([]interface{})
dep.AskList = append(dep.AskList, DepthRecord{ToFloat64(r[0]), ToFloat64(r[1])})
}
sort.Sort(sort.Reverse(dep.AskList))
return dep, nil
}
func (g *Gdax) GetKlineRecords(currency CurrencyPair, period, size, since int) ([]Kline, error) {
panic("not implement")
}
//非个人,整个交易所的交易记录
func (g *Gdax) GetTrades(currencyPair CurrencyPair, since int64) ([]Trade, error) {
panic("not implement")
}
func (g *Gdax) GetExchangeName() string {
return GDAX
}