mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +00:00
Periodic pairs update; LocalBitcoins, OKCoin and OKEX are now auto
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -97,7 +97,7 @@ const (
|
||||
statePaidPartlyConfirmed = "PAID_PARTLY_AND_CONFIRMED"
|
||||
|
||||
localbitcoinsAuthRate = 0
|
||||
localbitcoinsUnauthRate = 0
|
||||
localbitcoinsUnauthRate = 1
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -122,11 +122,11 @@ func (l *LocalBitcoins) SetDefaults() {
|
||||
l.RequestCurrencyPairFormat.Uppercase = true
|
||||
l.ConfigCurrencyPairFormat.Delimiter = ""
|
||||
l.ConfigCurrencyPairFormat.Uppercase = true
|
||||
l.SupportsAutoPairUpdating = false
|
||||
l.SupportsAutoPairUpdating = true
|
||||
l.SupportsRESTTickerBatching = true
|
||||
l.Requester = request.New(l.Name,
|
||||
request.NewRateLimit(time.Second*0, localbitcoinsAuthRate),
|
||||
request.NewRateLimit(time.Second*0, localbitcoinsUnauthRate),
|
||||
request.NewRateLimit(time.Millisecond*500, localbitcoinsAuthRate),
|
||||
request.NewRateLimit(time.Millisecond*500, localbitcoinsUnauthRate),
|
||||
common.NewHTTPClientWithTimeout(exchange.DefaultHTTPTimeout))
|
||||
l.APIUrlDefault = localbitcoinsAPIURL
|
||||
l.APIUrl = l.APIUrlDefault
|
||||
@@ -630,6 +630,21 @@ func (l *LocalBitcoins) GetTicker() (map[string]Ticker, error) {
|
||||
return result, l.SendHTTPRequest(l.APIUrl+localbitcoinsAPITicker, &result)
|
||||
}
|
||||
|
||||
// GetTradableCurrencies returns a list of tradable fiat currencies
|
||||
func (l *LocalBitcoins) GetTradableCurrencies() ([]string, error) {
|
||||
resp, err := l.GetTicker()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var currencies []string
|
||||
for x := range resp {
|
||||
currencies = append(currencies, x)
|
||||
}
|
||||
|
||||
return currencies, nil
|
||||
}
|
||||
|
||||
// GetTrades returns all closed trades in online buy and online sell categories,
|
||||
// updated every 15 minutes.
|
||||
func (l *LocalBitcoins) GetTrades(currency string, values url.Values) ([]Trade, error) {
|
||||
|
||||
@@ -36,6 +36,22 @@ func TestSetup(t *testing.T) {
|
||||
l.Setup(localbitcoinsConfig)
|
||||
}
|
||||
|
||||
func TestGetTicker(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := l.GetTicker()
|
||||
if err != nil {
|
||||
t.Errorf("Test failed - GetTicker() returned: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetTradableCurrencies(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := l.GetTradableCurrencies()
|
||||
if err != nil {
|
||||
t.Errorf("Test failed - GetTradableCurrencies() returned: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetAccountInfo(t *testing.T) {
|
||||
t.Parallel()
|
||||
if l.APIKey == "" || l.APISecret == "" {
|
||||
|
||||
@@ -29,6 +29,23 @@ func (l *LocalBitcoins) Run() {
|
||||
log.Printf("%s polling delay: %ds.\n", l.GetName(), l.RESTPollingDelay)
|
||||
log.Printf("%s %d currencies enabled: %s.\n", l.GetName(), len(l.EnabledPairs), l.EnabledPairs)
|
||||
}
|
||||
|
||||
currencies, err := l.GetTradableCurrencies()
|
||||
if err != nil {
|
||||
log.Printf("%s failed to obtain available tradable currencies. Err: %s", l.Name, err)
|
||||
return
|
||||
}
|
||||
|
||||
var pairs []string
|
||||
for x := range currencies {
|
||||
pairs = append(pairs, "BTC"+currencies[x])
|
||||
}
|
||||
|
||||
err = l.UpdateCurrencies(pairs, false, false)
|
||||
if err != nil {
|
||||
log.Printf("%s failed to update available currencies. Err %s", l.Name, err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// UpdateTicker updates and returns the ticker for a currency pair
|
||||
|
||||
@@ -22,9 +22,11 @@ import (
|
||||
const (
|
||||
okcoinAPIURL = "https://www.okcoin.com/api/v1/"
|
||||
okcoinAPIURLChina = "https://www.okcoin.com/api/v1/"
|
||||
okcoinAPIURLBase = "https://www.okcoin.com/api/"
|
||||
okcoinAPIVersion = "1"
|
||||
okcoinWebsocketURL = "wss://real.okcoin.com:10440/websocket/okcoinapi"
|
||||
okcoinWebsocketURLChina = "wss://real.okcoin.cn:10440/websocket/okcoinapi"
|
||||
okcoinInstruments = "instruments"
|
||||
okcoinTicker = "ticker.do"
|
||||
okcoinDepth = "depth.do"
|
||||
okcoinTrades = "trades.do"
|
||||
@@ -125,6 +127,7 @@ func (o *OKCoin) Setup(exch config.ExchangeConfig) {
|
||||
o.ConfigCurrencyPairFormat.Uppercase = true
|
||||
o.RequestCurrencyPairFormat.Uppercase = false
|
||||
o.RequestCurrencyPairFormat.Delimiter = "_"
|
||||
o.SupportsAutoPairUpdating = true
|
||||
} else {
|
||||
o.APIUrlDefault = okcoinAPIURLChina
|
||||
o.APIUrl = o.APIUrlDefault
|
||||
@@ -183,6 +186,20 @@ func (o *OKCoin) Setup(exch config.ExchangeConfig) {
|
||||
}
|
||||
}
|
||||
|
||||
// GetSpotInstruments returns a list of tradable spot instruments and their properties
|
||||
func (o *OKCoin) GetSpotInstruments() ([]SpotInstrument, error) {
|
||||
var resp []SpotInstrument
|
||||
|
||||
path := fmt.Sprintf("%sspot/v3/%s", okcoinAPIURLBase, okcoinInstruments)
|
||||
err := o.SendHTTPRequest(path, &resp)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// GetTicker returns the current ticker
|
||||
func (o *OKCoin) GetTicker(symbol string) (Ticker, error) {
|
||||
resp := TickerResponse{}
|
||||
|
||||
@@ -53,6 +53,14 @@ func setFeeBuilder() exchange.FeeBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetSpotInstruments(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := o.GetSpotInstruments()
|
||||
if err != nil {
|
||||
t.Errorf("Test failed - okcoin GetSpotInstruments() failed: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetFee(t *testing.T) {
|
||||
o.SetDefaults()
|
||||
var feeBuilder = setFeeBuilder()
|
||||
|
||||
@@ -2,6 +2,20 @@ package okcoin
|
||||
|
||||
import "github.com/thrasher-/gocryptotrader/currency/symbol"
|
||||
|
||||
// SpotInstrument stores the spot instrument info
|
||||
type SpotInstrument struct {
|
||||
BaseCurrency string `json:"base_currency"`
|
||||
BaseIncrement float64 `json:"base_increment,string"`
|
||||
BaseMinSize float64 `json:"base_min_size,string"`
|
||||
InstrumentID string `json:"instrument_id"`
|
||||
MinSize float64 `json:"min_size,string"`
|
||||
ProductID string `json:"product_id"`
|
||||
QuoteCurrency string `json:"quote_currency"`
|
||||
QuoteIncrement float64 `json:"quote_increment,string"`
|
||||
SizeIncrement float64 `json:"size_increment,string"`
|
||||
TickSize float64 `json:"tick_size,string"`
|
||||
}
|
||||
|
||||
// Ticker holds ticker data
|
||||
type Ticker struct {
|
||||
Buy float64 `json:",string"`
|
||||
|
||||
@@ -37,9 +37,19 @@ func (o *OKCoin) Run() {
|
||||
forceUpgrade = true
|
||||
}
|
||||
|
||||
var currencies []string
|
||||
for x := range o.AvailablePairs {
|
||||
currencies = append(currencies, o.AvailablePairs[x][0:3]+"_"+o.AvailablePairs[x][3:])
|
||||
prods, err := o.GetSpotInstruments()
|
||||
if err != nil {
|
||||
log.Printf("OKEX failed to obtain available spot instruments. Err: %d", err)
|
||||
} else {
|
||||
var pairs []string
|
||||
for x := range prods {
|
||||
pairs = append(pairs, prods[x].BaseCurrency+"_"+prods[x].QuoteCurrency)
|
||||
}
|
||||
|
||||
err = o.UpdateCurrencies(pairs, false, forceUpgrade)
|
||||
if err != nil {
|
||||
log.Printf("OKEX failed to update available currencies. Err: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
if forceUpgrade {
|
||||
@@ -50,11 +60,6 @@ func (o *OKCoin) Run() {
|
||||
if err != nil {
|
||||
log.Printf("%s failed to update currencies. Err: %s", o.Name, err)
|
||||
}
|
||||
|
||||
err = o.UpdateCurrencies(currencies, false, true)
|
||||
if err != nil {
|
||||
log.Printf("%s failed to update currencies. Err: %s", o.Name, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,10 +52,11 @@ const (
|
||||
|
||||
// Spot requests
|
||||
// Unauthenticated
|
||||
spotPrice = "ticker"
|
||||
spotDepth = "depth"
|
||||
spotTrades = "trades"
|
||||
spotKline = "kline"
|
||||
spotPrice = "ticker"
|
||||
spotDepth = "depth"
|
||||
spotTrades = "trades"
|
||||
spotKline = "kline"
|
||||
instruments = "instruments"
|
||||
|
||||
// Authenticated
|
||||
spotUserInfo = "userinfo"
|
||||
@@ -106,8 +107,8 @@ func (o *OKEX) SetDefaults() {
|
||||
o.RequestCurrencyPairFormat.Delimiter = "_"
|
||||
o.RequestCurrencyPairFormat.Uppercase = false
|
||||
o.ConfigCurrencyPairFormat.Delimiter = "_"
|
||||
o.ConfigCurrencyPairFormat.Uppercase = false
|
||||
o.SupportsAutoPairUpdating = false
|
||||
o.ConfigCurrencyPairFormat.Uppercase = true
|
||||
o.SupportsAutoPairUpdating = true
|
||||
o.SupportsRESTTickerBatching = false
|
||||
o.Requester = request.New(o.Name,
|
||||
request.NewRateLimit(time.Second, okexAuthRate),
|
||||
@@ -166,6 +167,20 @@ func (o *OKEX) Setup(exch config.ExchangeConfig) {
|
||||
}
|
||||
}
|
||||
|
||||
// GetSpotInstruments returns a list of tradable spot instruments and their properties
|
||||
func (o *OKEX) GetSpotInstruments() ([]SpotInstrument, error) {
|
||||
var resp []SpotInstrument
|
||||
|
||||
path := fmt.Sprintf("%sspot/v3/%s", o.APIUrl, instruments)
|
||||
err := o.SendHTTPRequest(path, &resp)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// GetContractPrice returns current contract prices
|
||||
//
|
||||
// symbol e.g. "btc_usd"
|
||||
|
||||
@@ -41,6 +41,14 @@ func TestSetup(t *testing.T) {
|
||||
o.Setup(okexConfig)
|
||||
}
|
||||
|
||||
func TestGetSpotInstruments(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := o.GetSpotInstruments()
|
||||
if err != nil {
|
||||
t.Errorf("Test failed - okex GetSpotInstruments() failed: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetContractPrice(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := o.GetContractPrice("btc_usd", "this_week")
|
||||
|
||||
@@ -3,6 +3,20 @@ package okex
|
||||
import "encoding/json"
|
||||
import "github.com/thrasher-/gocryptotrader/currency/symbol"
|
||||
|
||||
// SpotInstrument stores the spot instrument info
|
||||
type SpotInstrument struct {
|
||||
BaseCurrency string `json:"base_currency"`
|
||||
BaseIncrement float64 `json:"base_increment,string"`
|
||||
BaseMinSize float64 `json:"base_min_size,string"`
|
||||
InstrumentID string `json:"instrument_id"`
|
||||
MinSize float64 `json:"min_size,string"`
|
||||
ProductID string `json:"product_id"`
|
||||
QuoteCurrency string `json:"quote_currency"`
|
||||
QuoteIncrement float64 `json:"quote_increment,string"`
|
||||
SizeIncrement float64 `json:"size_increment,string"`
|
||||
TickSize float64 `json:"tick_size,string"`
|
||||
}
|
||||
|
||||
// ContractPrice holds date and ticker price price for contracts.
|
||||
type ContractPrice struct {
|
||||
Date string `json:"date"`
|
||||
|
||||
@@ -29,6 +29,22 @@ func (o *OKEX) Run() {
|
||||
log.Printf("%s polling delay: %ds.\n", o.GetName(), o.RESTPollingDelay)
|
||||
log.Printf("%s %d currencies enabled: %s.\n", o.GetName(), len(o.EnabledPairs), o.EnabledPairs)
|
||||
}
|
||||
|
||||
prods, err := o.GetSpotInstruments()
|
||||
if err != nil {
|
||||
log.Printf("OKEX failed to obtain available spot instruments. Err: %d", err)
|
||||
return
|
||||
}
|
||||
|
||||
var pairs []string
|
||||
for x := range prods {
|
||||
pairs = append(pairs, prods[x].BaseCurrency+"_"+prods[x].QuoteCurrency)
|
||||
}
|
||||
|
||||
err = o.UpdateCurrencies(pairs, false, false)
|
||||
if err != nil {
|
||||
log.Printf("OKEX failed to update available currencies. Err: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
// UpdateTicker updates and returns the ticker for a currency pair
|
||||
|
||||
77
testdata/configtest.json
vendored
77
testdata/configtest.json
vendored
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user