forked from nntaoli-project/goex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Adapter.go
57 lines (46 loc) · 1.15 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
package bitmex
import (
"fmt"
. "github.com/nntaoli-project/goex"
"strings"
)
func AdaptCurrencyPairToSymbol(pair CurrencyPair, contract string) string {
if contract == "" || contract == SWAP_CONTRACT {
if pair.CurrencyA.Eq(BTC) {
pair = NewCurrencyPair(XBT, USD)
}
if pair.CurrencyB.Eq(BTC) {
pair = NewCurrencyPair(pair.CurrencyA, XBT)
}
return pair.AdaptUsdtToUsd().ToSymbol("")
}
coin := pair.CurrencyA.Symbol
if pair.CurrencyA.Eq(BTC) {
coin = XBT.Symbol
}
return fmt.Sprintf("%s%s", coin, strings.ToUpper(contract))
}
func AdaptWsSymbol(symbol string) (pair CurrencyPair, contract string) {
symbol = strings.ToUpper(symbol)
if symbol == "XBTCUSD" {
return BTC_USD, SWAP_CONTRACT
}
if symbol == "BCHUSD" {
return BCH_USD, SWAP_CONTRACT
}
if symbol == "ETHUSD" {
return ETH_USD, SWAP_CONTRACT
}
if symbol == "LTCUSD" {
return LTC_USD, SWAP_CONTRACT
}
if symbol == "LINKUSDT" {
return NewCurrencyPair2("LINK_USDT"), SWAP_CONTRACT
}
pair = NewCurrencyPair(NewCurrency(symbol[0:3], ""), USDT)
contract = symbol[3:]
if pair.CurrencyA.Eq(XBT) {
return NewCurrencyPair(BTC, USDT), contract
}
return pair, contract
}