forked from nntaoli-project/goex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAex.go
136 lines (110 loc) · 3.65 KB
/
Aex.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
127
128
129
130
131
132
133
134
135
136
package aex
import (
"errors"
"fmt"
. "github.com/nntaoli-project/GoEx"
//"log"
"net/http"
"time"
)
//因服务器有防CC攻击策略,每60秒内调用次数不可超过120次,超过部分将被防火墙拦截。
const (
EXCHANGE_NAME = "aex.com"
API_BASE_URL = "https://api.aex.com/"
API_V1 = API_BASE_URL
TICKER_URI = "ticker.php?c=%s&mk_type=%s"
DEPTH_URI = "depth.php?c=%s&mk_type=%s"
ACCOUNT_URI = "getMyBalance.php"
TRADE_URI = "trades.php?c=%s&mk_type=%s"
CANCEL_URI = "cancelOrder.php"
ORDERS_INFO = "getMyTradeList.php"
UNFINISHED_ORDERS_INFO = "getOrderList.php"
)
type Aex struct {
accessKey,
secretKey,
accountId string
httpClient *http.Client
}
func New(client *http.Client, accessKey, secretKey, accountId string) *Aex {
return &Aex{accessKey, secretKey, accountId, client}
}
func (aex *Aex) GetExchangeName() string {
return EXCHANGE_NAME
}
func (aex *Aex) GetTicker(currency CurrencyPair) (*Ticker, error) {
cur := currency.CurrencyA.String()
money := currency.CurrencyB.String()
if cur == "UNKNOWN" {
//log.Println("Unsupport The CurrencyPair")
return nil, errors.New("Unsupport The CurrencyPair")
}
tickerUri := API_V1 + fmt.Sprintf(TICKER_URI, cur, money)
timestamp := time.Now().Unix()
bodyDataMap, err := HttpGet(aex.httpClient, tickerUri)
if err != nil {
//log.Println(err)
return nil, err
}
// log.Println("Aex bodyDataMap:", bodyDataMap)
var tickerMap map[string]interface{}
var ticker Ticker
switch bodyDataMap["ticker"].(type) {
case map[string]interface{}:
tickerMap = bodyDataMap["ticker"].(map[string]interface{})
default:
return nil, errors.New(fmt.Sprintf("Type Convert Error ? \n %s", bodyDataMap))
}
ticker.Date = uint64(timestamp)
ticker.Last = tickerMap["last"].(float64)
ticker.Buy = tickerMap["buy"].(float64)
ticker.Sell = tickerMap["sell"].(float64)
ticker.Low = tickerMap["low"].(float64)
ticker.High = tickerMap["high"].(float64)
ticker.Vol = tickerMap["vol"].(float64)
//log.Println("Aex", currency, "ticker:", ticker)
return &ticker, nil
}
func (aex *Aex) GetTickers(currency CurrencyPair) (*Ticker, error) {
return aex.GetTicker(currency)
}
func (aex *Aex) GetTickerInBuf(currency CurrencyPair) (*Ticker, error) {
return aex.GetTicker(currency)
}
func (aex *Aex) GetDepth(size int, currency CurrencyPair) (*Depth, error) {
panic("not implement")
}
func (aex *Aex) LimitBuy(amount, price string, currency CurrencyPair) (*Order, error) {
panic("not implements")
}
func (aex *Aex) LimitSell(amount, price string, currency CurrencyPair) (*Order, error) {
panic("not implements")
}
func (aex *Aex) MarketBuy(amount, price string, currency CurrencyPair) (*Order, error) {
panic("not implements")
}
func (aex *Aex) MarketSell(amount, price string, currency CurrencyPair) (*Order, error) {
panic("not implements")
}
func (aex *Aex) CancelOrder(orderId string, currency CurrencyPair) (bool, error) {
panic("not implements")
}
func (aex *Aex) GetOneOrder(orderId string, currency CurrencyPair) (*Order, error) {
panic("not implements")
}
func (aex *Aex) GetUnfinishOrders(currency CurrencyPair) ([]Order, error) {
panic("not implements")
}
func (aex *Aex) GetOrderHistorys(currency CurrencyPair, currentPage, pageSize int) ([]Order, error) {
panic("not implements")
}
func (aex *Aex) GetAccount() (*Account, error) {
panic("not implements")
}
func (aex *Aex) GetKlineRecords(currency CurrencyPair, period, size, since int) ([]Kline, error) {
panic("not implements")
}
//非个人,整个交易所的交易记录
func (aex *Aex) GetTrades(currencyPair CurrencyPair, since int64) ([]Trade, error) {
panic("not implements")
}