forked from nntaoli-project/goex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdapter.go
66 lines (53 loc) · 1.7 KB
/
Adapter.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
package binance
import (
"fmt"
"github.com/nntaoli-project/goex"
"strings"
)
func adaptStreamToCurrencyPair(stream string) goex.CurrencyPair {
symbol := strings.Split(stream, "@")[0]
if strings.HasSuffix(symbol, "usdt") {
return goex.NewCurrencyPair2(fmt.Sprintf("%s_usdt", strings.TrimSuffix(symbol, "usdt")))
}
if strings.HasSuffix(symbol, "usd") {
return goex.NewCurrencyPair2(fmt.Sprintf("%s_usd", strings.TrimSuffix(symbol, "usd")))
}
if strings.HasSuffix(symbol, "btc") {
return goex.NewCurrencyPair2(fmt.Sprintf("%s_btc", strings.TrimSuffix(symbol, "btc")))
}
return goex.UNKNOWN_PAIR
}
func adaptSymbolToCurrencyPair(symbol string) goex.CurrencyPair {
symbol = strings.ToUpper(symbol)
if strings.HasSuffix(symbol, "USD") {
return goex.NewCurrencyPair2(fmt.Sprintf("%s_USD", strings.TrimSuffix(symbol, "USD")))
}
if strings.HasSuffix(symbol, "USDT") {
return goex.NewCurrencyPair2(fmt.Sprintf("%s_USDT", strings.TrimSuffix(symbol, "USDT")))
}
if strings.HasSuffix(symbol, "PAX") {
return goex.NewCurrencyPair2(fmt.Sprintf("%s_PAX", strings.TrimSuffix(symbol, "PAX")))
}
if strings.HasSuffix(symbol, "BTC") {
return goex.NewCurrencyPair2(fmt.Sprintf("%s_BTC", strings.TrimSuffix(symbol, "BTC")))
}
return goex.UNKNOWN_PAIR
}
func adaptOrderStatus(status string) goex.TradeStatus {
var tradeStatus goex.TradeStatus
switch status {
case "NEW":
tradeStatus = goex.ORDER_UNFINISH
case "FILLED":
tradeStatus = goex.ORDER_FINISH
case "PARTIALLY_FILLED":
tradeStatus = goex.ORDER_PART_FINISH
case "CANCELED":
tradeStatus = goex.ORDER_CANCEL
case "PENDING_CANCEL":
tradeStatus = goex.ORDER_CANCEL_ING
case "REJECTED":
tradeStatus = goex.ORDER_REJECT
}
return tradeStatus
}