mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-23 07:26:47 +00:00
Various improvements, update config
This commit is contained in:
@@ -56,7 +56,7 @@ func (p *HitBTC) SetDefaults() {
|
||||
p.RESTPollingDelay = 10
|
||||
p.RequestCurrencyPairFormat.Delimiter = ""
|
||||
p.RequestCurrencyPairFormat.Uppercase = true
|
||||
p.ConfigCurrencyPairFormat.Delimiter = ""
|
||||
p.ConfigCurrencyPairFormat.Delimiter = "-"
|
||||
p.ConfigCurrencyPairFormat.Uppercase = true
|
||||
p.AssetTypes = []string{ticker.Spot}
|
||||
}
|
||||
@@ -73,16 +73,9 @@ func (p *HitBTC) Setup(exch config.ExchangeConfig) {
|
||||
p.Verbose = exch.Verbose
|
||||
p.Websocket = exch.Websocket
|
||||
p.BaseCurrencies = common.SplitStrings(exch.BaseCurrencies, ",")
|
||||
availiableSymbols, err := p.GetSymbols("")
|
||||
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
p.AvailablePairs = common.SplitStrings(exch.AvailablePairs, ",")
|
||||
} else {
|
||||
p.AvailablePairs = availiableSymbols
|
||||
}
|
||||
p.AvailablePairs = common.SplitStrings(exch.AvailablePairs, ",")
|
||||
p.EnabledPairs = common.SplitStrings(exch.EnabledPairs, ",")
|
||||
err = p.SetCurrencyPairFormat()
|
||||
err := p.SetCurrencyPairFormat()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
@@ -136,17 +129,30 @@ func (p *HitBTC) GetSymbols(symbol string) ([]string, error) {
|
||||
return ret, err
|
||||
}
|
||||
|
||||
// GetSymbolsDetailed is the same as above but returns an array of symbols with
|
||||
// all ther details.
|
||||
func (p *HitBTC) GetSymbolsDetailed() ([]Symbol, error) {
|
||||
resp := []Symbol{}
|
||||
path := fmt.Sprintf("%s/%s", APIURL, APIv2Symbol)
|
||||
return resp, common.SendHTTPGetRequest(path, true, p.Verbose, &resp)
|
||||
}
|
||||
|
||||
// GetTicker
|
||||
// Return ticker information
|
||||
func (p *HitBTC) GetTicker(symbol string) map[string]Ticker {
|
||||
func (p *HitBTC) GetTicker(symbol string) (map[string]Ticker, error) {
|
||||
|
||||
resp1 := []Ticker{}
|
||||
resp2 := Ticker{}
|
||||
ret := make(map[string]Ticker)
|
||||
resp1 := []TickerResponse{}
|
||||
resp2 := TickerResponse{}
|
||||
ret := make(map[string]TickerResponse)
|
||||
result := make(map[string]Ticker)
|
||||
path := fmt.Sprintf("%s/%s/%s", APIURL, APIv2Ticker, symbol)
|
||||
var err error
|
||||
|
||||
if symbol == "" {
|
||||
common.SendHTTPGetRequest(path, true, p.Verbose, &resp1)
|
||||
err = common.SendHTTPGetRequest(path, true, false, &resp1)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, item := range resp1 {
|
||||
if item.Symbol != "" {
|
||||
@@ -154,11 +160,45 @@ func (p *HitBTC) GetTicker(symbol string) map[string]Ticker {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
common.SendHTTPGetRequest(path, true, p.Verbose, &resp2)
|
||||
err = common.SendHTTPGetRequest(path, true, false, &resp2)
|
||||
ret[resp2.Symbol] = resp2
|
||||
}
|
||||
|
||||
return ret
|
||||
if err == nil {
|
||||
for x, y := range ret {
|
||||
tick := Ticker{}
|
||||
|
||||
ask, _ := strconv.ParseFloat(y.Ask, 64)
|
||||
tick.Ask = ask
|
||||
|
||||
bid, _ := strconv.ParseFloat(y.Bid, 64)
|
||||
tick.Bid = bid
|
||||
|
||||
high, _ := strconv.ParseFloat(y.High, 64)
|
||||
tick.High = high
|
||||
|
||||
last, _ := strconv.ParseFloat(y.Last, 64)
|
||||
tick.Last = last
|
||||
|
||||
low, _ := strconv.ParseFloat(y.Low, 64)
|
||||
tick.Low = low
|
||||
|
||||
open, _ := strconv.ParseFloat(y.Open, 64)
|
||||
tick.Open = open
|
||||
|
||||
vol, _ := strconv.ParseFloat(y.Volume, 64)
|
||||
tick.Volume = vol
|
||||
|
||||
volQuote, _ := strconv.ParseFloat(y.VolumeQuote, 64)
|
||||
tick.VolumeQuote = volQuote
|
||||
|
||||
tick.Symbol = y.Symbol
|
||||
tick.Timestamp = y.Timestamp
|
||||
result[x] = tick
|
||||
}
|
||||
}
|
||||
|
||||
return result, err
|
||||
}
|
||||
|
||||
// GetTrades returns trades from hitbtc
|
||||
|
||||
@@ -3,16 +3,29 @@ package hitbtc
|
||||
import "time"
|
||||
|
||||
type Ticker struct {
|
||||
Last float64 `json:"last,string"` // Last trade price
|
||||
Ask float64 `json:"ask,string"` // Best ask price
|
||||
Bid float64 `json:"bid,string"` // Best bid price
|
||||
Timestamp time.Time `json:"timestamp,string"` // Last update or refresh ticker timestamp
|
||||
Volume float64 `json:"volume,string"` // Total trading amount within 24 hours in base currency
|
||||
VolumeQuote float64 `json:"volumeQuote,string"` // Total trading amount within 24 hours in quote currency
|
||||
Last float64
|
||||
Ask float64
|
||||
Bid float64
|
||||
Timestamp time.Time
|
||||
Volume float64
|
||||
VolumeQuote float64
|
||||
Symbol string
|
||||
High float64
|
||||
Low float64
|
||||
Open float64
|
||||
}
|
||||
|
||||
type TickerResponse struct {
|
||||
Last string `json:"last"` // Last trade price
|
||||
Ask string `json:"ask"` // Best ask price
|
||||
Bid string `json:"bid"` // Best bid price
|
||||
Timestamp time.Time `json:"timestamp,string"` // Last update or refresh ticker timestamp
|
||||
Volume string `json:"volume"` // Total trading amount within 24 hours in base currency
|
||||
VolumeQuote string `json:"volumeQuote"` // Total trading amount within 24 hours in quote currency
|
||||
Symbol string `json:"symbol"`
|
||||
High float64 `json:"high,string"` // Highest trade price within 24 hours
|
||||
Low float64 `json:"low,string"` // Lowest trade price within 24 hours
|
||||
Open float64 `json:"open,string"` // Last trade price 24 hours ago
|
||||
High string `json:"high"` // Highest trade price within 24 hours
|
||||
Low string `json:"low"` // Lowest trade price within 24 hours
|
||||
Open string `json:"open"` // Last trade price 24 hours ago
|
||||
}
|
||||
|
||||
type Symbol struct {
|
||||
|
||||
@@ -26,11 +26,42 @@ func (p *HitBTC) Run() {
|
||||
if p.Websocket {
|
||||
go p.WebsocketClient()
|
||||
}
|
||||
|
||||
exchangeProducts, err := p.GetSymbolsDetailed()
|
||||
if err != nil {
|
||||
log.Printf("%s Failed to get available symbols.\n", p.GetName())
|
||||
} else {
|
||||
forceUpgrade := false
|
||||
if !common.DataContains(p.EnabledPairs, "-") || !common.DataContains(p.AvailablePairs, "-") {
|
||||
forceUpgrade = true
|
||||
}
|
||||
var currencies []string
|
||||
for x := range exchangeProducts {
|
||||
currencies = append(currencies, exchangeProducts[x].BaseCurrency+"-"+exchangeProducts[x].QuoteCurrency)
|
||||
}
|
||||
|
||||
if forceUpgrade {
|
||||
enabledPairs := []string{"BTC-USD"}
|
||||
log.Println("WARNING: Available pairs for HitBTC reset due to config upgrade, please enable the ones you would like again.")
|
||||
|
||||
err = p.UpdateEnabledCurrencies(enabledPairs, true)
|
||||
if err != nil {
|
||||
log.Printf("%s Failed to update enabled currencies.\n", p.GetName())
|
||||
}
|
||||
}
|
||||
err = p.UpdateAvailableCurrencies(currencies, forceUpgrade)
|
||||
if err != nil {
|
||||
log.Printf("%s Failed to update available currencies.\n", p.GetName())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// UpdateTicker updates and returns the ticker for a currency pair
|
||||
func (p *HitBTC) UpdateTicker(currencyPair pair.CurrencyPair, assetType string) (ticker.Price, error) {
|
||||
tick := p.GetTicker("")
|
||||
tick, err := p.GetTicker("")
|
||||
if err != nil {
|
||||
return ticker.Price{}, err
|
||||
}
|
||||
|
||||
for _, x := range p.GetEnabledCurrencies() {
|
||||
var tp ticker.Price
|
||||
@@ -59,7 +90,7 @@ func (p *HitBTC) GetTickerPrice(currencyPair pair.CurrencyPair, assetType string
|
||||
// GetOrderbookEx returns orderbook base on the currency pair
|
||||
func (p *HitBTC) GetOrderbookEx(currencyPair pair.CurrencyPair, assetType string) (orderbook.Base, error) {
|
||||
ob, err := orderbook.GetOrderbook(p.GetName(), currencyPair, assetType)
|
||||
if err == nil {
|
||||
if err != nil {
|
||||
return p.UpdateOrderbook(currencyPair, assetType)
|
||||
}
|
||||
return ob, nil
|
||||
|
||||
@@ -31,6 +31,10 @@ func (o *OKEX) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Price
|
||||
var tickerPrice ticker.Price
|
||||
|
||||
if assetType != ticker.Spot {
|
||||
if p.SecondCurrency.String() == common.StringToLower("USDT") {
|
||||
p.SecondCurrency = "usd"
|
||||
currency = exchange.FormatExchangeCurrency(o.Name, p).String()
|
||||
}
|
||||
tick, err := o.GetContractPrice(currency, assetType)
|
||||
if err != nil {
|
||||
return tickerPrice, err
|
||||
@@ -45,6 +49,11 @@ func (o *OKEX) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Price
|
||||
tickerPrice.High = tick.Ticker.High
|
||||
ticker.ProcessTicker(o.GetName(), p, tickerPrice, assetType)
|
||||
} else {
|
||||
if p.SecondCurrency.String() == common.StringToLower("USD") {
|
||||
p.SecondCurrency = "usdt"
|
||||
currency = exchange.FormatExchangeCurrency(o.Name, p).String()
|
||||
}
|
||||
|
||||
tick, err := o.GetSpotTicker(currency)
|
||||
if err != nil {
|
||||
return tickerPrice, err
|
||||
@@ -86,6 +95,10 @@ func (o *OKEX) UpdateOrderbook(p pair.CurrencyPair, assetType string) (orderbook
|
||||
currency := exchange.FormatExchangeCurrency(o.Name, p).String()
|
||||
|
||||
if assetType != ticker.Spot {
|
||||
if p.SecondCurrency.String() == common.StringToLower("USDT") {
|
||||
p.SecondCurrency = "usd"
|
||||
currency = exchange.FormatExchangeCurrency(o.Name, p).String()
|
||||
}
|
||||
orderbookNew, err := o.GetContractMarketDepth(currency, assetType)
|
||||
if err != nil {
|
||||
return orderBook, err
|
||||
@@ -102,6 +115,11 @@ func (o *OKEX) UpdateOrderbook(p pair.CurrencyPair, assetType string) (orderbook
|
||||
}
|
||||
|
||||
} else {
|
||||
if p.SecondCurrency.String() == common.StringToLower("USD") {
|
||||
p.SecondCurrency = "usdt"
|
||||
currency = exchange.FormatExchangeCurrency(o.Name, p).String()
|
||||
}
|
||||
|
||||
orderbookNew, err := o.GetSpotMarketDepth(currency, "200")
|
||||
if err != nil {
|
||||
return orderBook, err
|
||||
|
||||
@@ -64,7 +64,7 @@ func (y *Yobit) GetTickerPrice(p pair.CurrencyPair, assetType string) (ticker.Pr
|
||||
// GetOrderbookEx returns the orderbook for a currency pair
|
||||
func (y *Yobit) GetOrderbookEx(p pair.CurrencyPair, assetType string) (orderbook.Base, error) {
|
||||
ob, err := orderbook.GetOrderbook(y.GetName(), p, assetType)
|
||||
if err == nil {
|
||||
if err != nil {
|
||||
return y.UpdateOrderbook(p, assetType)
|
||||
}
|
||||
return ob, nil
|
||||
|
||||
Reference in New Issue
Block a user