forked from nntaoli-project/goex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bittrex.go
119 lines (100 loc) · 3.3 KB
/
bittrex.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
package bittrex
import (
"fmt"
. "github.com/nntaoli-project/GoEx"
"net/http"
"sort"
"errors"
)
type Bittrex struct {
client *http.Client
baseUrl,
accesskey,
secretkey string
}
func New(client *http.Client, accesskey, secretkey string) *Bittrex {
return &Bittrex{client: client, accesskey: accesskey, secretkey: secretkey, baseUrl: "https://bittrex.com/api/v1.1"}
}
func (bx *Bittrex) LimitBuy(amount, price string, currency CurrencyPair) (*Order, error) {
panic("not implement")
}
func (bx *Bittrex) LimitSell(amount, price string, currency CurrencyPair) (*Order, error) {
panic("not implement")
}
func (bx *Bittrex) MarketBuy(amount, price string, currency CurrencyPair) (*Order, error) {
panic("not implement")
}
func (bx *Bittrex) MarketSell(amount, price string, currency CurrencyPair) (*Order, error) {
panic("not implement")
}
func (bx *Bittrex) CancelOrder(orderId string, currency CurrencyPair) (bool, error) {
panic("not implement")
}
func (bx *Bittrex) GetOneOrder(orderId string, currency CurrencyPair) (*Order, error) {
panic("not implement")
}
func (bx *Bittrex) GetUnfinishOrders(currency CurrencyPair) ([]Order, error) {
panic("not implement")
}
func (bx *Bittrex) GetOrderHistorys(currency CurrencyPair, currentPage, pageSize int) ([]Order, error) {
panic("not implement")
}
func (bx *Bittrex) GetAccount() (*Account, error) {
panic("not implement")
}
func (bx *Bittrex) GetTicker(currency CurrencyPair) (*Ticker, error) {
resp, err := HttpGet(bx.client, fmt.Sprintf("%s/public/getmarketsummary?market=%s", bx.baseUrl, currency.ToSymbol2("-")))
if err != nil {
errCode := HTTP_ERR_CODE
errCode.OriginErrMsg = err.Error()
return nil, errCode
}
result, _ := resp["result"].([]interface{})
if len(result) <= 0 {
return nil, API_ERR
}
tickermap := result[0].(map[string]interface{})
return &Ticker{
Last: ToFloat64(tickermap["Last"]),
Sell: ToFloat64(tickermap["Ask"]),
Buy: ToFloat64(tickermap["Bid"]),
Low: ToFloat64(tickermap["Low"]),
High: ToFloat64(tickermap["High"]),
Vol: ToFloat64(tickermap["Volume"]),
}, nil
}
func (bx *Bittrex) GetDepth(size int, currency CurrencyPair) (*Depth, error) {
resp, err := HttpGet(bx.client, fmt.Sprintf("%s/public/getorderbook?market=%s&type=both", bx.baseUrl, currency.ToSymbol2("-")))
if err != nil {
errCode := HTTP_ERR_CODE
errCode.OriginErrMsg = err.Error()
return nil, errCode
}
result, err2 := resp["result"].(map[string]interface{})
if err2 != true {
return nil, errors.New(resp["message"].(string))
}
bids, _ := result["buy"].([]interface{})
asks, _ := result["sell"].([]interface{})
dep := new(Depth)
for _, v := range bids {
r := v.(map[string]interface{})
dep.BidList = append(dep.BidList, DepthRecord{ToFloat64(r["Rate"]), ToFloat64(r["Quantity"])})
}
for _, v := range asks {
r := v.(map[string]interface{})
dep.AskList = append(dep.AskList, DepthRecord{ToFloat64(r["Rate"]), ToFloat64(r["Quantity"])})
}
sort.Sort(sort.Reverse(dep.AskList))
return dep, nil
}
func (bx *Bittrex) GetKlineRecords(currency CurrencyPair, period, size, since int) ([]Kline, error) {
panic("not implement")
}
//非个人,整个交易所的交易记录
func (bx *Bittrex) GetTrades(currencyPair CurrencyPair, since int64) ([]Trade, error) {
panic("not implement")
}
func (bx *Bittrex) GetExchangeName() string {
return BITTREX
}