mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-04 07:26:47 +00:00
Bump last checked available currencies timestamp and expand automatic updating of available currencies for various exchanges
This commit is contained in:
@@ -68,8 +68,8 @@ func (b *Bithumb) SetDefaults() {
|
||||
b.ConfigCurrencyPairFormat.Uppercase = true
|
||||
b.ConfigCurrencyPairFormat.Index = "KRW"
|
||||
b.AssetTypes = []string{ticker.Spot}
|
||||
b.SupportsAutoPairUpdating = false
|
||||
b.SupportsRESTTickerBatching = false
|
||||
b.SupportsAutoPairUpdating = true
|
||||
b.SupportsRESTTickerBatching = true
|
||||
b.Requester = request.New(b.Name, request.NewRateLimit(time.Second, bithumbAuthRate), request.NewRateLimit(time.Second, bithumbUnauthRate), common.NewHTTPClientWithTimeout(exchange.DefaultHTTPTimeout))
|
||||
}
|
||||
|
||||
@@ -103,6 +103,20 @@ func (b *Bithumb) Setup(exch config.ExchangeConfig) {
|
||||
}
|
||||
}
|
||||
|
||||
// GetTradablePairs returns a list of tradable currencies
|
||||
func (b *Bithumb) GetTradablePairs() ([]string, error) {
|
||||
result, err := b.GetAllTickers()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var currencies []string
|
||||
for x := range result {
|
||||
currencies = append(currencies, x)
|
||||
}
|
||||
return currencies, nil
|
||||
}
|
||||
|
||||
// GetTicker returns ticker information
|
||||
//
|
||||
// symbol e.g. "btc"
|
||||
@@ -113,6 +127,44 @@ func (b *Bithumb) GetTicker(symbol string) (Ticker, error) {
|
||||
return response, b.SendHTTPRequest(path, &response)
|
||||
}
|
||||
|
||||
// GetAllTickers returns all ticker information
|
||||
func (b *Bithumb) GetAllTickers() (map[string]Ticker, error) {
|
||||
type Response struct {
|
||||
Data map[string]interface{}
|
||||
}
|
||||
|
||||
response := Response{}
|
||||
path := fmt.Sprintf("%s%s%s", apiURL, publicTicker, "all")
|
||||
|
||||
err := b.SendHTTPRequest(path, &response)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result := make(map[string]Ticker)
|
||||
for k, v := range response.Data {
|
||||
if k == "date" {
|
||||
continue
|
||||
}
|
||||
|
||||
data := v.(map[string]interface{})
|
||||
var t Ticker
|
||||
t.AveragePrice, _ = strconv.ParseFloat(data["average_price"].(string), 64)
|
||||
t.BuyPrice, _ = strconv.ParseFloat(data["buy_price"].(string), 64)
|
||||
t.ClosingPrice, _ = strconv.ParseFloat(data["closing_price"].(string), 64)
|
||||
t.MaxPrice, _ = strconv.ParseFloat(data["max_price"].(string), 64)
|
||||
t.MinPrice, _ = strconv.ParseFloat(data["min_price"].(string), 64)
|
||||
t.OpeningPrice, _ = strconv.ParseFloat(data["opening_price"].(string), 64)
|
||||
t.SellPrice, _ = strconv.ParseFloat(data["sell_price"].(string), 64)
|
||||
t.UnitsTraded, _ = strconv.ParseFloat(data["units_traded"].(string), 64)
|
||||
t.Volume1Day, _ = strconv.ParseFloat(data["volume_1day"].(string), 64)
|
||||
t.Volume7Day, _ = strconv.ParseFloat(data["volume_7day"].(string), 64)
|
||||
result[k] = t
|
||||
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// GetOrderBook returns current orderbook
|
||||
//
|
||||
// symbol e.g. "btc"
|
||||
|
||||
@@ -33,6 +33,14 @@ func TestSetup(t *testing.T) {
|
||||
b.Setup(bitConfig)
|
||||
}
|
||||
|
||||
func TestGetTradablePairs(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.GetTradablePairs()
|
||||
if err != nil {
|
||||
t.Error("test failed - Bithumb GetTradablePairs() error", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetTicker(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.GetTicker("btc")
|
||||
@@ -41,6 +49,14 @@ func TestGetTicker(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetAllTickers(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.GetAllTickers()
|
||||
if err != nil {
|
||||
t.Error("test failed - Bithumb GetAllTickers() error", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetOrderBook(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.GetOrderBook("btc")
|
||||
|
||||
@@ -1,24 +1,34 @@
|
||||
package bithumb
|
||||
|
||||
// Ticker holds the standard ticker information
|
||||
// Ticker holds ticker data
|
||||
type Ticker struct {
|
||||
Status string `json:"status"`
|
||||
Data struct {
|
||||
OpeningPrice float64 `json:"opening_price,string"`
|
||||
ClosingPrice float64 `json:"closing_price,string"`
|
||||
MinPrice float64 `json:"min_price,string"`
|
||||
MaxPrice float64 `json:"max_price,string"`
|
||||
AveragePrice float64 `json:"average_price,string"`
|
||||
UnitsTraded float64 `json:"units_traded,string"`
|
||||
Volume1Day float64 `json:"volume_1day,string"`
|
||||
Volume7Day float64 `json:"volume_7day,string"`
|
||||
BuyPrice float64 `json:"buy_price,string"`
|
||||
SellPrice float64 `json:"sell_price,string"`
|
||||
Date int64 `json:"date,string"`
|
||||
} `json:"data"`
|
||||
OpeningPrice float64 `json:"opening_price,string"`
|
||||
ClosingPrice float64 `json:"closing_price,string"`
|
||||
MinPrice float64 `json:"min_price,string"`
|
||||
MaxPrice float64 `json:"max_price,string"`
|
||||
AveragePrice float64 `json:"average_price,string"`
|
||||
UnitsTraded float64 `json:"units_traded,string"`
|
||||
Volume1Day float64 `json:"volume_1day,string"`
|
||||
Volume7Day float64 `json:"volume_7day,string"`
|
||||
BuyPrice float64 `json:"buy_price,string"`
|
||||
SellPrice float64 `json:"sell_price,string"`
|
||||
// Date int64 `json:"date,string"`
|
||||
}
|
||||
|
||||
// TickerResponse holds the standard ticker response
|
||||
type TickerResponse struct {
|
||||
Status string `json:"status"`
|
||||
Data Ticker `json:"data"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
// TickersResponse holds the standard ticker response
|
||||
type TickersResponse struct {
|
||||
Status string `json:"status"`
|
||||
Data map[string]Ticker `json:"data"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
// Orderbook holds full range of order book information
|
||||
type Orderbook struct {
|
||||
Status string `json:"status"`
|
||||
|
||||
@@ -28,26 +28,53 @@ func (b *Bithumb) Run() {
|
||||
log.Printf("%s polling delay: %ds.\n", b.GetName(), b.RESTPollingDelay)
|
||||
log.Printf("%s %d currencies enabled: %s.\n", b.GetName(), len(b.EnabledPairs), b.EnabledPairs)
|
||||
}
|
||||
|
||||
exchangeProducts, err := b.GetTradingPairs()
|
||||
if err != nil {
|
||||
log.Printf("%s Failed to get available symbols.\n", b.GetName())
|
||||
} else {
|
||||
err = b.UpdateCurrencies(exchangeProducts, false, false)
|
||||
if err != nil {
|
||||
log.Printf("%s Failed to update available symbols.\n", b.GetName())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// GetTradingPairs gets the available trading currencies
|
||||
func (b *Bithumb) GetTradingPairs() ([]string, error) {
|
||||
currencies, err := b.GetTradablePairs()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for x := range currencies {
|
||||
currencies[x] = currencies[x] + "KRW"
|
||||
}
|
||||
|
||||
return currencies, nil
|
||||
}
|
||||
|
||||
// UpdateTicker updates and returns the ticker for a currency pair
|
||||
func (b *Bithumb) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Price, error) {
|
||||
var tickerPrice ticker.Price
|
||||
item := p.GetFirstCurrency().String()
|
||||
tick, err := b.GetTicker(item)
|
||||
|
||||
tickers, err := b.GetAllTickers()
|
||||
if err != nil {
|
||||
return tickerPrice, err
|
||||
}
|
||||
|
||||
tickerPrice.Pair = p
|
||||
tickerPrice.Ask = tick.Data.SellPrice
|
||||
tickerPrice.Bid = tick.Data.BuyPrice
|
||||
tickerPrice.Low = tick.Data.MinPrice
|
||||
tickerPrice.Last = tick.Data.ClosingPrice
|
||||
tickerPrice.Volume = tick.Data.Volume1Day
|
||||
tickerPrice.High = tick.Data.MaxPrice
|
||||
ticker.ProcessTicker(b.GetName(), p, tickerPrice, assetType)
|
||||
|
||||
for _, x := range b.GetEnabledCurrencies() {
|
||||
currency := x.GetFirstCurrency().String()
|
||||
var tp ticker.Price
|
||||
tp.Pair = x
|
||||
tp.Ask = tickers[currency].SellPrice
|
||||
tp.Bid = tickers[currency].BuyPrice
|
||||
tp.Low = tickers[currency].MinPrice
|
||||
tp.Last = tickers[currency].ClosingPrice
|
||||
tp.Volume = tickers[currency].Volume1Day
|
||||
tp.High = tickers[currency].MaxPrice
|
||||
ticker.ProcessTicker(b.Name, x, tp, assetType)
|
||||
}
|
||||
return ticker.GetTicker(b.Name, p, assetType)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user