mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 15:09:42 +00:00
exchanges: Change wrapper function FetchTradablePairs to return currency.Pairs (#1093)
* exchanges: FetchTradablePairs currency pair slice return (1) * exchanges: finish conversion * thrasher: nits + linter * exchanges: shift var dec into for loop * exchanges: Apply changes thanks @thrasher- * Update exchanges/alphapoint/alphapoint_wrapper.go Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io> * thrasher: nitters * Update exchanges/bitflyer/bitflyer_wrapper.go Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io> * thrasher: fix more nitters Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io> Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io>
This commit is contained in:
@@ -217,7 +217,7 @@ func ({{.Variable}} *{{.CapitalName}}) Run() {
|
||||
}
|
||||
|
||||
// FetchTradablePairs returns a list of the exchanges tradable pairs
|
||||
func ({{.Variable}} *{{.CapitalName}}) FetchTradablePairs(ctx context.Context, asset asset.Item) ([]string, error) {
|
||||
func ({{.Variable}} *{{.CapitalName}}) FetchTradablePairs(ctx context.Context, a asset.Item) (currency.Pairs, error) {
|
||||
// Implement fetching the exchange available pairs if supported
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
@@ -398,7 +398,7 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
|
||||
Response: jsonifyInterface([]interface{}{updateOrderbookResponse}),
|
||||
})
|
||||
|
||||
var fetchTradablePairsResponse []string
|
||||
var fetchTradablePairsResponse []currency.Pair
|
||||
fetchTradablePairsResponse, err = e.FetchTradablePairs(context.TODO(), assetTypes[i])
|
||||
msg = ""
|
||||
if err != nil {
|
||||
|
||||
@@ -641,7 +641,7 @@ Supported Examples:
|
||||
|
||||
```go
|
||||
// FetchTradablePairs returns a list of the exchanges tradable pairs
|
||||
func (f *FTX) FetchTradablePairs(ctx context.Context, a asset.Item) ([]string, error) {
|
||||
func (f *FTX) FetchTradablePairs(ctx context.Context, a asset.Item) (currency.Pairs, error) {
|
||||
if !f.SupportsAsset(a) {
|
||||
return nil, fmt.Errorf("asset type of %s is not supported by %s", a, f.Name)
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ func (a *Alphapoint) SetDefaults() {
|
||||
}
|
||||
|
||||
// FetchTradablePairs returns a list of the exchanges tradable pairs
|
||||
func (a *Alphapoint) FetchTradablePairs(ctx context.Context, asset asset.Item) ([]string, error) {
|
||||
func (a *Alphapoint) FetchTradablePairs(_ context.Context, _ asset.Item) (currency.Pairs, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
|
||||
@@ -151,11 +151,7 @@ func TestUpdateTicker(t *testing.T) {
|
||||
if len(tradablePairs) == 0 {
|
||||
t.Fatal("no tradable pairs")
|
||||
}
|
||||
cp, err := currency.NewPairFromString(tradablePairs[0])
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
_, err = b.UpdateTicker(context.Background(), cp, asset.CoinMarginedFutures)
|
||||
_, err = b.UpdateTicker(context.Background(), tradablePairs[0], asset.CoinMarginedFutures)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -167,11 +163,7 @@ func TestUpdateTicker(t *testing.T) {
|
||||
if len(usdtMarginedPairs) == 0 {
|
||||
t.Errorf("no pairs are enabled")
|
||||
}
|
||||
ucp, err := currency.NewPairFromString(usdtMarginedPairs[0])
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
_, err = b.UpdateTicker(context.Background(), ucp, asset.USDTMarginedFutures)
|
||||
_, err = b.UpdateTicker(context.Background(), usdtMarginedPairs[0], asset.USDTMarginedFutures)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -2010,12 +2002,8 @@ func TestGetOrderInfo(t *testing.T) {
|
||||
if len(tradablePairs) == 0 {
|
||||
t.Fatal("no tradable pairs")
|
||||
}
|
||||
cp, err := currency.NewPairFromString(tradablePairs[0])
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
_, err = b.GetOrderInfo(context.Background(),
|
||||
"123", cp, asset.CoinMarginedFutures)
|
||||
"123", tradablePairs[0], asset.CoinMarginedFutures)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
@@ -351,30 +351,28 @@ func (b *Binance) Run() {
|
||||
}
|
||||
|
||||
// FetchTradablePairs returns a list of the exchanges tradable pairs
|
||||
func (b *Binance) FetchTradablePairs(ctx context.Context, a asset.Item) ([]string, error) {
|
||||
func (b *Binance) FetchTradablePairs(ctx context.Context, a asset.Item) (currency.Pairs, error) {
|
||||
if !b.SupportsAsset(a) {
|
||||
return nil, fmt.Errorf("asset type of %s is not supported by %s", a, b.Name)
|
||||
}
|
||||
format, err := b.GetPairFormat(a, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
tradingStatus := "TRADING"
|
||||
var pairs []string
|
||||
var pairs []currency.Pair
|
||||
switch a {
|
||||
case asset.Spot, asset.Margin:
|
||||
var info ExchangeInfo
|
||||
info, err = b.GetExchangeInfo(ctx)
|
||||
info, err := b.GetExchangeInfo(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pairs = make([]currency.Pair, 0, len(info.Symbols))
|
||||
for x := range info.Symbols {
|
||||
if info.Symbols[x].Status != tradingStatus {
|
||||
continue
|
||||
}
|
||||
pair := info.Symbols[x].BaseAsset +
|
||||
format.Delimiter +
|
||||
info.Symbols[x].QuoteAsset
|
||||
pair, err := currency.NewPairFromStrings(info.Symbols[x].BaseAsset,
|
||||
info.Symbols[x].QuoteAsset)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if a == asset.Spot && info.Symbols[x].IsSpotTradingAllowed {
|
||||
pairs = append(pairs, pair)
|
||||
}
|
||||
@@ -383,46 +381,42 @@ func (b *Binance) FetchTradablePairs(ctx context.Context, a asset.Item) ([]strin
|
||||
}
|
||||
}
|
||||
case asset.CoinMarginedFutures:
|
||||
var cInfo CExchangeInfo
|
||||
cInfo, err = b.FuturesExchangeInfo(ctx)
|
||||
cInfo, err := b.FuturesExchangeInfo(ctx)
|
||||
if err != nil {
|
||||
return pairs, err
|
||||
return nil, err
|
||||
}
|
||||
pairs = make([]currency.Pair, 0, len(cInfo.Symbols))
|
||||
for z := range cInfo.Symbols {
|
||||
if cInfo.Symbols[z].ContractStatus != tradingStatus {
|
||||
continue
|
||||
}
|
||||
var curr currency.Pair
|
||||
curr, err = currency.NewPairFromString(cInfo.Symbols[z].Symbol)
|
||||
pair, err := currency.NewPairFromString(cInfo.Symbols[z].Symbol)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pairs = append(pairs, format.Format(curr))
|
||||
pairs = append(pairs, pair)
|
||||
}
|
||||
case asset.USDTMarginedFutures:
|
||||
var uInfo UFuturesExchangeInfo
|
||||
uInfo, err = b.UExchangeInfo(ctx)
|
||||
uInfo, err := b.UExchangeInfo(ctx)
|
||||
if err != nil {
|
||||
return pairs, err
|
||||
return nil, err
|
||||
}
|
||||
pairs = make([]currency.Pair, 0, len(uInfo.Symbols))
|
||||
for u := range uInfo.Symbols {
|
||||
if uInfo.Symbols[u].Status != tradingStatus {
|
||||
continue
|
||||
}
|
||||
var curr currency.Pair
|
||||
var pair currency.Pair
|
||||
if uInfo.Symbols[u].ContractType == "PERPETUAL" {
|
||||
curr, err = currency.NewPairFromStrings(uInfo.Symbols[u].BaseAsset, uInfo.Symbols[u].QuoteAsset)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pair, err = currency.NewPairFromStrings(uInfo.Symbols[u].BaseAsset,
|
||||
uInfo.Symbols[u].QuoteAsset)
|
||||
} else {
|
||||
curr, err = currency.NewPairFromString(uInfo.Symbols[u].Symbol)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pair, err = currency.NewPairFromString(uInfo.Symbols[u].Symbol)
|
||||
}
|
||||
|
||||
pairs = append(pairs, format.Format(curr))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pairs = append(pairs, pair)
|
||||
}
|
||||
}
|
||||
return pairs, nil
|
||||
@@ -433,12 +427,7 @@ func (b *Binance) FetchTradablePairs(ctx context.Context, a asset.Item) ([]strin
|
||||
func (b *Binance) UpdateTradablePairs(ctx context.Context, forceUpdate bool) error {
|
||||
assetTypes := b.GetAssetTypes(false)
|
||||
for i := range assetTypes {
|
||||
p, err := b.FetchTradablePairs(ctx, assetTypes[i])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
pairs, err := currency.NewPairsFromStrings(p)
|
||||
pairs, err := b.FetchTradablePairs(ctx, assetTypes[i])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -300,12 +300,10 @@ func TestGetOrderInfo(t *testing.T) {
|
||||
if len(tradablePairs) == 0 {
|
||||
t.Fatal("Binanceus GetOrderInfo() no tradable pairs")
|
||||
}
|
||||
cp, err := currency.NewPairFromString(tradablePairs[0])
|
||||
if err != nil {
|
||||
t.Error("Binanceus GetOrderInfo() error", err)
|
||||
}
|
||||
_, err = bi.GetOrderInfo(context.Background(),
|
||||
"123", cp, asset.Spot)
|
||||
"123",
|
||||
tradablePairs[0],
|
||||
asset.Spot)
|
||||
if !strings.Contains(err.Error(), "Order does not exist.") {
|
||||
t.Error("Binanceus GetOrderInfo() error", err)
|
||||
}
|
||||
|
||||
@@ -251,28 +251,26 @@ func (bi *Binanceus) Run() {
|
||||
}
|
||||
|
||||
// FetchTradablePairs returns a list of the exchanges tradable pairs
|
||||
func (bi *Binanceus) FetchTradablePairs(ctx context.Context, a asset.Item) ([]string, error) {
|
||||
func (bi *Binanceus) FetchTradablePairs(ctx context.Context, a asset.Item) (currency.Pairs, error) {
|
||||
if !bi.SupportsAsset(a) {
|
||||
return nil, fmt.Errorf("asset type of %s is not supported by %s", a, bi.Name)
|
||||
}
|
||||
format, err := bi.GetPairFormat(a, false)
|
||||
info, err := bi.GetExchangeInfo(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
tradingStatus := "TRADING"
|
||||
var info ExchangeInfo
|
||||
info, err = bi.GetExchangeInfo(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pairs := make([]string, 0, len(info.Symbols))
|
||||
pairs := make([]currency.Pair, 0, len(info.Symbols))
|
||||
for x := range info.Symbols {
|
||||
if info.Symbols[x].Status != tradingStatus || !info.Symbols[x].IsSpotTradingAllowed {
|
||||
if info.Symbols[x].Status != "TRADING" ||
|
||||
!info.Symbols[x].IsSpotTradingAllowed {
|
||||
continue
|
||||
}
|
||||
pair := info.Symbols[x].BaseAsset +
|
||||
format.Delimiter +
|
||||
info.Symbols[x].QuoteAsset
|
||||
var pair currency.Pair
|
||||
pair, err = currency.NewPairFromStrings(info.Symbols[x].BaseAsset,
|
||||
info.Symbols[x].QuoteAsset)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pairs = append(pairs, pair)
|
||||
}
|
||||
return pairs, nil
|
||||
@@ -285,11 +283,7 @@ func (bi *Binanceus) UpdateTradablePairs(ctx context.Context, forceUpdate bool)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
p, err := currency.NewPairsFromStrings(pairs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return bi.UpdatePairs(p, asset.Spot, false, forceUpdate)
|
||||
return bi.UpdatePairs(pairs, asset.Spot, false, forceUpdate)
|
||||
}
|
||||
|
||||
// UpdateTicker updates and returns the ticker for a currency pair
|
||||
|
||||
@@ -277,40 +277,52 @@ func (b *Bitfinex) Run() {
|
||||
}
|
||||
|
||||
// FetchTradablePairs returns a list of the exchanges tradable pairs
|
||||
func (b *Bitfinex) FetchTradablePairs(ctx context.Context, a asset.Item) ([]string, error) {
|
||||
func (b *Bitfinex) FetchTradablePairs(ctx context.Context, a asset.Item) (currency.Pairs, error) {
|
||||
items, err := b.GetTickerBatch(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var symbols []string
|
||||
pairs := make([]currency.Pair, 0, len(items))
|
||||
var pair currency.Pair
|
||||
switch a {
|
||||
case asset.Spot:
|
||||
for k := range items {
|
||||
if !strings.HasPrefix(k, "t") {
|
||||
continue
|
||||
}
|
||||
symbols = append(symbols, k[1:])
|
||||
pair, err = currency.NewPairFromString(k[1:])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pairs = append(pairs, pair)
|
||||
}
|
||||
case asset.Margin:
|
||||
for k := range items {
|
||||
if !strings.Contains(k, ":") {
|
||||
continue
|
||||
}
|
||||
symbols = append(symbols, k[1:])
|
||||
pair, err = currency.NewPairFromStrings(k[1:], "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pairs = append(pairs, pair)
|
||||
}
|
||||
case asset.MarginFunding:
|
||||
for k := range items {
|
||||
if !strings.HasPrefix(k, "f") {
|
||||
continue
|
||||
}
|
||||
symbols = append(symbols, k[1:])
|
||||
pair, err = currency.NewPairFromString(k[1:])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pairs = append(pairs, pair)
|
||||
}
|
||||
default:
|
||||
return nil, errors.New("asset type not supported by this endpoint")
|
||||
}
|
||||
|
||||
return symbols, nil
|
||||
return pairs, nil
|
||||
}
|
||||
|
||||
// UpdateTradablePairs updates the exchanges available pairs and stores
|
||||
@@ -323,23 +335,7 @@ func (b *Bitfinex) UpdateTradablePairs(ctx context.Context, forceUpdate bool) er
|
||||
return err
|
||||
}
|
||||
|
||||
var p currency.Pairs
|
||||
if assets[i] == asset.MarginFunding {
|
||||
p = make(currency.Pairs, len(pairs))
|
||||
for x := range pairs {
|
||||
p[x], err = currency.NewPairFromStrings(pairs[x], "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
p, err = currency.NewPairsFromStrings(pairs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
err = b.UpdatePairs(p, assets[i], false, forceUpdate)
|
||||
err = b.UpdatePairs(pairs, assets[i], false, forceUpdate)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -152,29 +152,35 @@ func (b *Bitflyer) Run() {
|
||||
}
|
||||
|
||||
// FetchTradablePairs returns a list of the exchanges tradable pairs
|
||||
func (b *Bitflyer) FetchTradablePairs(ctx context.Context, a asset.Item) ([]string, error) {
|
||||
pairs, err := b.GetMarkets(ctx)
|
||||
func (b *Bitflyer) FetchTradablePairs(ctx context.Context, a asset.Item) (currency.Pairs, error) {
|
||||
symbols, err := b.GetMarkets(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
format, err := b.GetPairFormat(a, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var products []string
|
||||
for i := range pairs {
|
||||
if pairs[i].Alias != "" && a == asset.Futures {
|
||||
products = append(products, pairs[i].Alias)
|
||||
} else if pairs[i].Alias == "" &&
|
||||
pairs := make([]currency.Pair, 0, len(symbols))
|
||||
for i := range symbols {
|
||||
var pair currency.Pair
|
||||
if symbols[i].Alias != "" && a == asset.Futures {
|
||||
pair, err = currency.NewPairFromString(symbols[i].Alias)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pairs = append(pairs, pair)
|
||||
} else if symbols[i].Alias == "" &&
|
||||
a == asset.Spot &&
|
||||
strings.Contains(pairs[i].ProductCode,
|
||||
format.Delimiter) {
|
||||
products = append(products, pairs[i].ProductCode)
|
||||
strings.Contains(symbols[i].ProductCode, format.Delimiter) {
|
||||
pair, err = currency.NewPairFromString(symbols[i].ProductCode)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pairs = append(pairs, pair)
|
||||
}
|
||||
}
|
||||
return products, nil
|
||||
return pairs, nil
|
||||
}
|
||||
|
||||
// UpdateTradablePairs updates the exchanges available pairs and stores
|
||||
@@ -187,12 +193,7 @@ func (b *Bitflyer) UpdateTradablePairs(ctx context.Context, forceUpdate bool) er
|
||||
return err
|
||||
}
|
||||
|
||||
p, err := currency.NewPairsFromStrings(pairs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = b.UpdatePairs(p, assets[x], false, forceUpdate)
|
||||
err = b.UpdatePairs(pairs, assets[x], false, forceUpdate)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -230,17 +230,22 @@ func (b *Bithumb) Run() {
|
||||
}
|
||||
|
||||
// FetchTradablePairs returns a list of the exchanges tradable pairs
|
||||
func (b *Bithumb) FetchTradablePairs(ctx context.Context, asset asset.Item) ([]string, error) {
|
||||
func (b *Bithumb) FetchTradablePairs(ctx context.Context, a asset.Item) (currency.Pairs, error) {
|
||||
currencies, err := b.GetTradablePairs(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pairs := make([]currency.Pair, len(currencies))
|
||||
for x := range currencies {
|
||||
currencies[x] += currency.DashDelimiter + "KRW"
|
||||
var pair currency.Pair
|
||||
pair, err = currency.NewPairFromStrings(currencies[x], "KRW")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pairs[x] = pair
|
||||
}
|
||||
|
||||
return currencies, nil
|
||||
return pairs, nil
|
||||
}
|
||||
|
||||
// UpdateTradablePairs updates the exchanges available pairs and stores
|
||||
@@ -250,13 +255,7 @@ func (b *Bithumb) UpdateTradablePairs(ctx context.Context, forceUpdate bool) err
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
p, err := currency.NewPairsFromStrings(pairs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return b.UpdatePairs(p, asset.Spot, false, forceUpdate)
|
||||
return b.UpdatePairs(pairs, asset.Spot, false, forceUpdate)
|
||||
}
|
||||
|
||||
// UpdateTickers updates the ticker for all currency pairs of a given asset type
|
||||
|
||||
@@ -244,22 +244,27 @@ func (b *Bitmex) Run() {
|
||||
}
|
||||
|
||||
// FetchTradablePairs returns a list of the exchanges tradable pairs
|
||||
func (b *Bitmex) FetchTradablePairs(ctx context.Context, a asset.Item) ([]string, error) {
|
||||
func (b *Bitmex) FetchTradablePairs(ctx context.Context, a asset.Item) (currency.Pairs, error) {
|
||||
marketInfo, err := b.GetActiveAndIndexInstruments(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
products := make([]string, 0, len(marketInfo))
|
||||
pairs := make([]currency.Pair, 0, len(marketInfo))
|
||||
for x := range marketInfo {
|
||||
if marketInfo[x].State != "Open" && a != asset.Index {
|
||||
continue
|
||||
}
|
||||
|
||||
var pair currency.Pair
|
||||
switch a {
|
||||
case asset.Spot:
|
||||
if marketInfo[x].Typ == spotID {
|
||||
products = append(products, marketInfo[x].Symbol)
|
||||
pair, err = currency.NewPairFromString(marketInfo[x].Symbol)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pairs = append(pairs, pair)
|
||||
}
|
||||
case asset.PerpetualContract:
|
||||
if marketInfo[x].Typ == perpetualContractID {
|
||||
@@ -276,9 +281,12 @@ func (b *Bitmex) FetchTradablePairs(ctx context.Context, a asset.Item) ([]string
|
||||
}
|
||||
settleTrail = currency.UnderscoreDelimiter + settlement[1]
|
||||
}
|
||||
products = append(products, marketInfo[x].Underlying+
|
||||
currency.DashDelimiter+
|
||||
pair, err = currency.NewPairFromStrings(marketInfo[x].Underlying,
|
||||
marketInfo[x].QuoteCurrency+settleTrail)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pairs = append(pairs, pair)
|
||||
}
|
||||
case asset.Futures:
|
||||
if marketInfo[x].Typ == futuresID {
|
||||
@@ -299,7 +307,11 @@ func (b *Bitmex) FetchTradablePairs(ctx context.Context, a asset.Item) ([]string
|
||||
root := isolate[0][:len(isolate[0])-3]
|
||||
contract := isolate[0][len(isolate[0])-3:]
|
||||
|
||||
products = append(products, root+currency.DashDelimiter+contract+settleTrail)
|
||||
pair, err = currency.NewPairFromStrings(root, contract+settleTrail)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pairs = append(pairs, pair)
|
||||
}
|
||||
case asset.Index:
|
||||
// TODO: This can be expanded into individual assets later.
|
||||
@@ -307,13 +319,17 @@ func (b *Bitmex) FetchTradablePairs(ctx context.Context, a asset.Item) ([]string
|
||||
marketInfo[x].Typ == bitMEXPriceIndexID ||
|
||||
marketInfo[x].Typ == bitMEXLendingPremiumIndexID ||
|
||||
marketInfo[x].Typ == bitMEXVolatilityIndexID {
|
||||
products = append(products, marketInfo[x].Symbol)
|
||||
pair, err = currency.NewPairFromString(marketInfo[x].Symbol)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pairs = append(pairs, pair)
|
||||
}
|
||||
default:
|
||||
return nil, errors.New("unhandled asset type")
|
||||
}
|
||||
}
|
||||
return products, nil
|
||||
return pairs, nil
|
||||
}
|
||||
|
||||
// UpdateTradablePairs updates the exchanges available pairs and stores
|
||||
@@ -322,12 +338,7 @@ func (b *Bitmex) UpdateTradablePairs(ctx context.Context, forceUpdate bool) erro
|
||||
assets := b.GetAssetTypes(false)
|
||||
|
||||
for x := range assets {
|
||||
pairsStr, err := b.FetchTradablePairs(ctx, assets[x])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
pairs, err := currency.NewPairsFromStrings(pairsStr)
|
||||
pairs, err := b.FetchTradablePairs(ctx, assets[x])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -198,11 +198,7 @@ func TestGetTradingPairs(t *testing.T) {
|
||||
|
||||
func TestFetchTradablePairs(t *testing.T) {
|
||||
t.Parallel()
|
||||
r, err := b.FetchTradablePairs(context.Background(), asset.Spot)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
pairs, err := currency.NewPairsFromStrings(r)
|
||||
pairs, err := b.FetchTradablePairs(context.Background(), asset.Spot)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -279,21 +279,25 @@ func (b *Bitstamp) Run() {
|
||||
}
|
||||
|
||||
// FetchTradablePairs returns a list of the exchanges tradable pairs
|
||||
func (b *Bitstamp) FetchTradablePairs(ctx context.Context, asset asset.Item) ([]string, error) {
|
||||
pairs, err := b.GetTradingPairs(ctx)
|
||||
func (b *Bitstamp) FetchTradablePairs(ctx context.Context, a asset.Item) (currency.Pairs, error) {
|
||||
symbols, err := b.GetTradingPairs(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
products := make([]string, 0, len(pairs))
|
||||
for x := range pairs {
|
||||
if pairs[x].Trading != "Enabled" {
|
||||
pairs := make([]currency.Pair, 0, len(symbols))
|
||||
for x := range symbols {
|
||||
if symbols[x].Trading != "Enabled" {
|
||||
continue
|
||||
}
|
||||
products = append(products, pairs[x].Name)
|
||||
var pair currency.Pair
|
||||
pair, err = currency.NewPairFromString(symbols[x].Name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pairs = append(pairs, pair)
|
||||
}
|
||||
|
||||
return products, nil
|
||||
return pairs, nil
|
||||
}
|
||||
|
||||
// UpdateTradablePairs updates the exchanges available pairs and stores
|
||||
@@ -303,13 +307,7 @@ func (b *Bitstamp) UpdateTradablePairs(ctx context.Context, forceUpdate bool) er
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
p, err := currency.NewPairsFromStrings(pairs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return b.UpdatePairs(p, asset.Spot, false, forceUpdate)
|
||||
return b.UpdatePairs(pairs, asset.Spot, false, forceUpdate)
|
||||
}
|
||||
|
||||
// UpdateTickers updates the ticker for all currency pairs of a given asset type
|
||||
|
||||
@@ -246,25 +246,29 @@ func (b *Bittrex) Run() {
|
||||
}
|
||||
|
||||
// FetchTradablePairs returns a list of the exchanges tradable pairs
|
||||
func (b *Bittrex) FetchTradablePairs(ctx context.Context, asset asset.Item) ([]string, error) {
|
||||
func (b *Bittrex) FetchTradablePairs(ctx context.Context, a asset.Item) (currency.Pairs, error) {
|
||||
// Bittrex only supports spot trading
|
||||
if !b.SupportsAsset(asset) {
|
||||
return nil, fmt.Errorf("asset type of %s is not supported by %s", asset, b.Name)
|
||||
if !b.SupportsAsset(a) {
|
||||
return nil, fmt.Errorf("asset type of %s is not supported by %s", a, b.Name)
|
||||
}
|
||||
markets, err := b.GetMarkets(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp := make([]string, 0, len(markets))
|
||||
pairs := make([]currency.Pair, 0, len(markets))
|
||||
for x := range markets {
|
||||
if markets[x].Status != "ONLINE" {
|
||||
continue
|
||||
}
|
||||
resp = append(resp, markets[x].Symbol)
|
||||
var pair currency.Pair
|
||||
pair, err = currency.NewPairFromString(markets[x].Symbol)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pairs = append(pairs, pair)
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
return pairs, nil
|
||||
}
|
||||
|
||||
// UpdateTradablePairs updates the exchanges available pairs and stores
|
||||
@@ -274,13 +278,7 @@ func (b *Bittrex) UpdateTradablePairs(ctx context.Context, forceUpdate bool) err
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
p, err := currency.NewPairsFromStrings(pairs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return b.UpdatePairs(p, asset.Spot, false, forceUpdate)
|
||||
return b.UpdatePairs(pairs, asset.Spot, false, forceUpdate)
|
||||
}
|
||||
|
||||
// UpdateTickers updates the ticker for all currency pairs of a given asset type
|
||||
|
||||
@@ -284,7 +284,7 @@ func (b *BTCMarkets) Run() {
|
||||
}
|
||||
|
||||
// FetchTradablePairs returns a list of the exchanges tradable pairs
|
||||
func (b *BTCMarkets) FetchTradablePairs(ctx context.Context, a asset.Item) ([]string, error) {
|
||||
func (b *BTCMarkets) FetchTradablePairs(ctx context.Context, a asset.Item) (currency.Pairs, error) {
|
||||
if a != asset.Spot {
|
||||
return nil, fmt.Errorf("asset type of %s is not supported by %s", a, b.Name)
|
||||
}
|
||||
@@ -292,10 +292,14 @@ func (b *BTCMarkets) FetchTradablePairs(ctx context.Context, a asset.Item) ([]st
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pairs := make([]string, len(markets))
|
||||
pairs := make([]currency.Pair, len(markets))
|
||||
for x := range markets {
|
||||
pairs[x] = markets[x].MarketID
|
||||
var pair currency.Pair
|
||||
pair, err = currency.NewPairFromString(markets[x].MarketID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pairs[x] = pair
|
||||
}
|
||||
return pairs, nil
|
||||
}
|
||||
@@ -307,12 +311,7 @@ func (b *BTCMarkets) UpdateTradablePairs(ctx context.Context, forceUpdate bool)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
p, err := currency.NewPairsFromStrings(pairs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return b.UpdatePairs(p, asset.Spot, false, forceUpdate)
|
||||
return b.UpdatePairs(pairs, asset.Spot, false, forceUpdate)
|
||||
}
|
||||
|
||||
// UpdateTickers updates the ticker for all currency pairs of a given asset type
|
||||
|
||||
@@ -247,20 +247,24 @@ func (b *BTSE) Run() {
|
||||
}
|
||||
|
||||
// FetchTradablePairs returns a list of the exchanges tradable pairs
|
||||
func (b *BTSE) FetchTradablePairs(ctx context.Context, a asset.Item) ([]string, error) {
|
||||
func (b *BTSE) FetchTradablePairs(ctx context.Context, a asset.Item) (currency.Pairs, error) {
|
||||
m, err := b.GetMarketSummary(ctx, "", a == asset.Spot)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
currencies := make([]string, 0, len(m))
|
||||
pairs := make([]currency.Pair, 0, len(m))
|
||||
for x := range m {
|
||||
if !m[x].Active {
|
||||
continue
|
||||
}
|
||||
currencies = append(currencies, m[x].Symbol)
|
||||
var pair currency.Pair
|
||||
pair, err = currency.NewPairFromString(m[x].Symbol)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pairs = append(pairs, pair)
|
||||
}
|
||||
return currencies, nil
|
||||
return pairs, nil
|
||||
}
|
||||
|
||||
// UpdateTradablePairs updates the exchanges available pairs and stores
|
||||
@@ -272,13 +276,7 @@ func (b *BTSE) UpdateTradablePairs(ctx context.Context, forceUpdate bool) error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
p, err := currency.NewPairsFromStrings(pairs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = b.UpdatePairs(p, a[i], false, forceUpdate)
|
||||
err = b.UpdatePairs(pairs, a[i], false, forceUpdate)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -277,20 +277,26 @@ func (by *Bybit) Run() {
|
||||
}
|
||||
|
||||
// FetchTradablePairs returns a list of the exchanges tradable pairs
|
||||
func (by *Bybit) FetchTradablePairs(ctx context.Context, a asset.Item) ([]string, error) {
|
||||
func (by *Bybit) FetchTradablePairs(ctx context.Context, a asset.Item) (currency.Pairs, error) {
|
||||
if !by.SupportsAsset(a) {
|
||||
return nil, fmt.Errorf("asset type of %s is not supported by %s", a, by.Name)
|
||||
}
|
||||
|
||||
var pair currency.Pair
|
||||
switch a {
|
||||
case asset.Spot:
|
||||
allPairs, err := by.GetAllSpotPairs(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pairs := make([]string, len(allPairs))
|
||||
pairs := make([]currency.Pair, len(allPairs))
|
||||
for x := range allPairs {
|
||||
pairs[x] = allPairs[x].BaseCurrency + currency.DashDelimiter + allPairs[x].QuoteCurrency
|
||||
pair, err = currency.NewPairFromStrings(allPairs[x].BaseCurrency,
|
||||
allPairs[x].QuoteCurrency)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pairs[x] = pair
|
||||
}
|
||||
return pairs, nil
|
||||
case asset.CoinMarginedFutures:
|
||||
@@ -298,7 +304,7 @@ func (by *Bybit) FetchTradablePairs(ctx context.Context, a asset.Item) ([]string
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pairs := make([]string, 0, len(allPairs))
|
||||
pairs := make([]currency.Pair, 0, len(allPairs))
|
||||
for x := range allPairs {
|
||||
if allPairs[x].Status != "Trading" || allPairs[x].QuoteCurrency != "USD" {
|
||||
continue
|
||||
@@ -313,8 +319,12 @@ func (by *Bybit) FetchTradablePairs(ctx context.Context, a asset.Item) ([]string
|
||||
continue
|
||||
}
|
||||
|
||||
symbol := allPairs[x].BaseCurrency + currency.DashDelimiter + contractSplit[1]
|
||||
pairs = append(pairs, symbol)
|
||||
pair, err = currency.NewPairFromStrings(allPairs[x].BaseCurrency,
|
||||
contractSplit[1])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pairs = append(pairs, pair)
|
||||
}
|
||||
return pairs, nil
|
||||
case asset.USDTMarginedFutures:
|
||||
@@ -322,16 +332,18 @@ func (by *Bybit) FetchTradablePairs(ctx context.Context, a asset.Item) ([]string
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pairs := make([]string, 0, len(allPairs))
|
||||
pairs := make([]currency.Pair, 0, len(allPairs))
|
||||
for x := range allPairs {
|
||||
if allPairs[x].Status != "Trading" || allPairs[x].QuoteCurrency != "USDT" {
|
||||
continue
|
||||
}
|
||||
|
||||
symbol := allPairs[x].BaseCurrency +
|
||||
currency.DashDelimiter +
|
||||
allPairs[x].QuoteCurrency
|
||||
pairs = append(pairs, symbol)
|
||||
pair, err = currency.NewPairFromStrings(allPairs[x].BaseCurrency,
|
||||
allPairs[x].QuoteCurrency)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pairs = append(pairs, pair)
|
||||
}
|
||||
return pairs, nil
|
||||
case asset.Futures:
|
||||
@@ -339,7 +351,7 @@ func (by *Bybit) FetchTradablePairs(ctx context.Context, a asset.Item) ([]string
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pairs := make([]string, 0, len(allPairs))
|
||||
pairs := make([]currency.Pair, 0, len(allPairs))
|
||||
for x := range allPairs {
|
||||
if allPairs[x].Status != "Trading" {
|
||||
continue
|
||||
@@ -347,11 +359,15 @@ func (by *Bybit) FetchTradablePairs(ctx context.Context, a asset.Item) ([]string
|
||||
|
||||
symbol := allPairs[x].BaseCurrency + allPairs[x].QuoteCurrency
|
||||
filter := strings.Split(allPairs[x].Name, symbol)
|
||||
|
||||
if len(filter) != 2 || filter[1] == "" {
|
||||
continue
|
||||
}
|
||||
pairs = append(pairs, symbol+currency.DashDelimiter+filter[1])
|
||||
|
||||
pair, err = currency.NewPairFromStrings(symbol, filter[1])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pairs = append(pairs, pair)
|
||||
}
|
||||
return pairs, nil
|
||||
case asset.USDCMarginedFutures:
|
||||
@@ -359,9 +375,13 @@ func (by *Bybit) FetchTradablePairs(ctx context.Context, a asset.Item) ([]string
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pairs := make([]string, len(allPairs))
|
||||
pairs := make([]currency.Pair, len(allPairs))
|
||||
for x := range allPairs {
|
||||
pairs[x] = allPairs[x].BaseCoin + currency.DashDelimiter + "PERP"
|
||||
pair, err = currency.NewPairFromStrings(allPairs[x].BaseCoin, "PERP")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pairs[x] = pair
|
||||
}
|
||||
return pairs, nil
|
||||
}
|
||||
@@ -377,13 +397,7 @@ func (by *Bybit) UpdateTradablePairs(ctx context.Context, forceUpdate bool) erro
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
p, err := currency.NewPairsFromStrings(pairs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = by.UpdatePairs(p, assetTypes[i], false, forceUpdate)
|
||||
err = by.UpdatePairs(pairs, assetTypes[i], false, forceUpdate)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -8,13 +8,23 @@ import (
|
||||
|
||||
// Product holds product information
|
||||
type Product struct {
|
||||
ID string `json:"id"`
|
||||
BaseCurrency string `json:"base_currency"`
|
||||
QuoteCurrency string `json:"quote_currency"`
|
||||
BaseMinSize float64 `json:"base_min_size,string"`
|
||||
BaseMaxSize interface{} `json:"base_max_size"`
|
||||
QuoteIncrement float64 `json:"quote_increment,string"`
|
||||
DisplayName string `json:"string"`
|
||||
ID string `json:"id"`
|
||||
BaseCurrency string `json:"base_currency"`
|
||||
QuoteCurrency string `json:"quote_currency"`
|
||||
QuoteIncrement float64 `json:"quote_increment,string"`
|
||||
BaseIncrement float64 `json:"base_increment,string"`
|
||||
DisplayName string `json:"display_name"`
|
||||
MinimumMarketFunds float64 `json:"min_market_funds,string"`
|
||||
MarginEnabled bool `json:"margin_enabled"`
|
||||
PostOnly bool `json:"post_only"`
|
||||
LimitOnly bool `json:"limit_only"`
|
||||
CancelOnly bool `json:"cancel_only"`
|
||||
Status string `json:"status"`
|
||||
StatusMessage string `json:"status_message"`
|
||||
TradingDisabled bool `json:"trading_disabled"`
|
||||
ForeignExchangeStableCoin bool `json:"fx_stablecoin"`
|
||||
MaxSlippagePercentage float64 `json:"max_slippage_percentage,string"`
|
||||
AuctionMode bool `json:"auction_mode"`
|
||||
}
|
||||
|
||||
// Ticker holds basic ticker information
|
||||
|
||||
@@ -283,23 +283,25 @@ func (c *CoinbasePro) Run() {
|
||||
}
|
||||
|
||||
// FetchTradablePairs returns a list of the exchanges tradable pairs
|
||||
func (c *CoinbasePro) FetchTradablePairs(ctx context.Context, asset asset.Item) ([]string, error) {
|
||||
pairs, err := c.GetProducts(ctx)
|
||||
func (c *CoinbasePro) FetchTradablePairs(ctx context.Context, a asset.Item) (currency.Pairs, error) {
|
||||
products, err := c.GetProducts(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
format, err := c.GetPairFormat(asset, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
pairs := make([]currency.Pair, 0, len(products))
|
||||
for x := range products {
|
||||
if products[x].TradingDisabled {
|
||||
continue
|
||||
}
|
||||
var pair currency.Pair
|
||||
pair, err = currency.NewPairDelimiter(products[x].ID, currency.DashDelimiter)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pairs = append(pairs, pair)
|
||||
}
|
||||
|
||||
products := make([]string, len(pairs))
|
||||
for x := range pairs {
|
||||
products[x] = pairs[x].BaseCurrency + format.Delimiter + pairs[x].QuoteCurrency
|
||||
}
|
||||
|
||||
return products, nil
|
||||
return pairs, nil
|
||||
}
|
||||
|
||||
// UpdateTradablePairs updates the exchanges available pairs and stores
|
||||
@@ -309,13 +311,7 @@ func (c *CoinbasePro) UpdateTradablePairs(ctx context.Context, forceUpdate bool)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
p, err := currency.NewPairsFromStrings(pairs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return c.UpdatePairs(p, asset.Spot, false, forceUpdate)
|
||||
return c.UpdatePairs(pairs, asset.Spot, false, forceUpdate)
|
||||
}
|
||||
|
||||
// UpdateAccountInfo retrieves balances for all enabled currencies for the
|
||||
|
||||
@@ -264,35 +264,31 @@ func (c *COINUT) Run() {
|
||||
}
|
||||
|
||||
// FetchTradablePairs returns a list of the exchanges tradable pairs
|
||||
func (c *COINUT) FetchTradablePairs(ctx context.Context, asset asset.Item) ([]string, error) {
|
||||
var instruments map[string][]InstrumentBase
|
||||
func (c *COINUT) FetchTradablePairs(ctx context.Context, a asset.Item) (currency.Pairs, error) {
|
||||
var resp Instruments
|
||||
var err error
|
||||
if c.Websocket.IsConnected() {
|
||||
resp, err = c.WsGetInstruments()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
resp, err = c.GetInstruments(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
format, err := c.GetPairFormat(asset, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
instruments = resp.Instruments
|
||||
pairs := make([]string, 0, len(instruments))
|
||||
for i := range instruments {
|
||||
c.instrumentMap.Seed(instruments[i][0].Base+instruments[i][0].Quote, instruments[i][0].InstrumentID)
|
||||
p := instruments[i][0].Base + format.Delimiter + instruments[i][0].Quote
|
||||
pairs = append(pairs, p)
|
||||
pairs := make([]currency.Pair, 0, len(resp.Instruments))
|
||||
var pair currency.Pair
|
||||
for _, instrument := range resp.Instruments {
|
||||
if len(instrument) == 0 {
|
||||
return nil, errors.New("invalid data received")
|
||||
}
|
||||
c.instrumentMap.Seed(instrument[0].Base+instrument[0].Quote, instrument[0].InstrumentID)
|
||||
pair, err = currency.NewPairFromStrings(instrument[0].Base, instrument[0].Quote)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pairs = append(pairs, pair)
|
||||
}
|
||||
|
||||
return pairs, nil
|
||||
}
|
||||
|
||||
@@ -303,12 +299,7 @@ func (c *COINUT) UpdateTradablePairs(ctx context.Context, forceUpdate bool) erro
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
p, err := currency.NewPairsFromStrings(pairs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return c.UpdatePairs(p, asset.Spot, false, forceUpdate)
|
||||
return c.UpdatePairs(pairs, asset.Spot, false, forceUpdate)
|
||||
}
|
||||
|
||||
// UpdateAccountInfo retrieves balances for all enabled currencies for the
|
||||
|
||||
@@ -167,18 +167,28 @@ func (e *EXMO) Run() {
|
||||
}
|
||||
|
||||
// FetchTradablePairs returns a list of the exchanges tradable pairs
|
||||
func (e *EXMO) FetchTradablePairs(ctx context.Context, asset asset.Item) ([]string, error) {
|
||||
pairs, err := e.GetPairSettings(ctx)
|
||||
func (e *EXMO) FetchTradablePairs(ctx context.Context, a asset.Item) (currency.Pairs, error) {
|
||||
if !e.SupportsAsset(a) {
|
||||
return nil, asset.ErrNotSupported
|
||||
}
|
||||
|
||||
symbols, err := e.GetPairSettings(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
currencies := make([]string, 0, len(pairs))
|
||||
for x := range pairs {
|
||||
currencies = append(currencies, x)
|
||||
pairs := make([]currency.Pair, len(symbols))
|
||||
var target int
|
||||
for key := range symbols {
|
||||
var pair currency.Pair
|
||||
pair, err = currency.NewPairFromString(key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pairs[target] = pair
|
||||
target++
|
||||
}
|
||||
|
||||
return currencies, nil
|
||||
return pairs, nil
|
||||
}
|
||||
|
||||
// UpdateTradablePairs updates the exchanges available pairs and stores
|
||||
@@ -188,13 +198,7 @@ func (e *EXMO) UpdateTradablePairs(ctx context.Context, forceUpdate bool) error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
p, err := currency.NewPairsFromStrings(pairs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return e.UpdatePairs(p, asset.Spot, false, forceUpdate)
|
||||
return e.UpdatePairs(pairs, asset.Spot, false, forceUpdate)
|
||||
}
|
||||
|
||||
// UpdateTickers updates the ticker for all currency pairs of a given asset type
|
||||
|
||||
@@ -266,7 +266,7 @@ func (f *FTX) Run() {
|
||||
}
|
||||
|
||||
// FetchTradablePairs returns a list of the exchanges tradable pairs
|
||||
func (f *FTX) FetchTradablePairs(ctx context.Context, a asset.Item) ([]string, error) {
|
||||
func (f *FTX) FetchTradablePairs(ctx context.Context, a asset.Item) (currency.Pairs, error) {
|
||||
if !f.SupportsAsset(a) {
|
||||
return nil, fmt.Errorf("asset type of %s is not supported by %s", a, f.Name)
|
||||
}
|
||||
@@ -274,31 +274,30 @@ func (f *FTX) FetchTradablePairs(ctx context.Context, a asset.Item) ([]string, e
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
format, err := f.GetPairFormat(a, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var pairs []string
|
||||
pairs := make([]currency.Pair, 0, len(markets))
|
||||
var pair currency.Pair
|
||||
switch a {
|
||||
case asset.Spot:
|
||||
for x := range markets {
|
||||
if markets[x].MarketType == spotString {
|
||||
curr, err := currency.NewPairFromString(markets[x].Name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pairs = append(pairs, format.Format(curr))
|
||||
if markets[x].MarketType != spotString {
|
||||
continue
|
||||
}
|
||||
pair, err = currency.NewPairFromString(markets[x].Name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pairs = append(pairs, pair)
|
||||
}
|
||||
case asset.Futures:
|
||||
for x := range markets {
|
||||
if markets[x].MarketType == futuresString {
|
||||
curr, err := currency.NewPairFromString(markets[x].Name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pairs = append(pairs, format.Format(curr))
|
||||
if markets[x].MarketType != futuresString {
|
||||
continue
|
||||
}
|
||||
pair, err := currency.NewPairFromString(markets[x].Name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pairs = append(pairs, pair)
|
||||
}
|
||||
}
|
||||
return pairs, nil
|
||||
@@ -313,11 +312,7 @@ func (f *FTX) UpdateTradablePairs(ctx context.Context, forceUpdate bool) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
p, err := currency.NewPairsFromStrings(pairs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = f.UpdatePairs(p, assets[x], false, forceUpdate)
|
||||
err = f.UpdatePairs(pairs, assets[x], false, forceUpdate)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -220,8 +220,15 @@ func (g *Gateio) Run() {
|
||||
}
|
||||
|
||||
// FetchTradablePairs returns a list of the exchanges tradable pairs
|
||||
func (g *Gateio) FetchTradablePairs(ctx context.Context, asset asset.Item) ([]string, error) {
|
||||
return g.GetSymbols(ctx)
|
||||
func (g *Gateio) FetchTradablePairs(ctx context.Context, a asset.Item) (currency.Pairs, error) {
|
||||
if !g.SupportsAsset(a) {
|
||||
return nil, asset.ErrNotSupported
|
||||
}
|
||||
symbols, err := g.GetSymbols(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return currency.NewPairsFromStrings(symbols)
|
||||
}
|
||||
|
||||
// UpdateTradablePairs updates the exchanges available pairs and stores
|
||||
@@ -231,12 +238,7 @@ func (g *Gateio) UpdateTradablePairs(ctx context.Context, forceUpdate bool) erro
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
p, err := currency.NewPairsFromStrings(pairs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return g.UpdatePairs(p, asset.Spot, false, forceUpdate)
|
||||
return g.UpdatePairs(pairs, asset.Spot, false, forceUpdate)
|
||||
}
|
||||
|
||||
// UpdateTickers updates the ticker for all currency pairs of a given asset type
|
||||
|
||||
@@ -56,11 +56,7 @@ func TestGetSymbols(t *testing.T) {
|
||||
|
||||
func TestFetchTradablePairs(t *testing.T) {
|
||||
t.Parallel()
|
||||
r, err := g.FetchTradablePairs(context.Background(), asset.Spot)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
pairs, err := currency.NewPairsFromStrings(r)
|
||||
pairs, err := g.FetchTradablePairs(context.Background(), asset.Spot)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -272,24 +272,33 @@ func (g *Gemini) Run() {
|
||||
}
|
||||
|
||||
// FetchTradablePairs returns a list of the exchanges tradable pairs
|
||||
func (g *Gemini) FetchTradablePairs(ctx context.Context, asset asset.Item) ([]string, error) {
|
||||
pairs, err := g.GetSymbols(ctx)
|
||||
func (g *Gemini) FetchTradablePairs(ctx context.Context, a asset.Item) (currency.Pairs, error) {
|
||||
if !g.SupportsAsset(a) {
|
||||
return nil, asset.ErrNotSupported
|
||||
}
|
||||
|
||||
symbols, err := g.GetSymbols(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var tradablePairs []string
|
||||
for x := range pairs {
|
||||
switch len(pairs[x]) {
|
||||
pairs := make([]currency.Pair, len(symbols))
|
||||
for x := range symbols {
|
||||
var pair currency.Pair
|
||||
switch len(symbols[x]) {
|
||||
case 8:
|
||||
tradablePairs = append(tradablePairs, pairs[x][0:5]+currency.DashDelimiter+pairs[x][5:])
|
||||
pair, err = currency.NewPairFromStrings(symbols[x][0:5], symbols[x][5:])
|
||||
case 7:
|
||||
tradablePairs = append(tradablePairs, pairs[x][0:4]+currency.DashDelimiter+pairs[x][4:])
|
||||
pair, err = currency.NewPairFromStrings(symbols[x][0:4], symbols[x][4:])
|
||||
default:
|
||||
tradablePairs = append(tradablePairs, pairs[x][0:3]+currency.DashDelimiter+pairs[x][3:])
|
||||
pair, err = currency.NewPairFromStrings(symbols[x][0:3], symbols[x][3:])
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pairs[x] = pair
|
||||
}
|
||||
return tradablePairs, nil
|
||||
return pairs, nil
|
||||
}
|
||||
|
||||
// UpdateTradablePairs updates the exchanges available pairs and stores
|
||||
@@ -299,13 +308,7 @@ func (g *Gemini) UpdateTradablePairs(ctx context.Context, forceUpdate bool) erro
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
p, err := currency.NewPairsFromStrings(pairs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return g.UpdatePairs(p, asset.Spot, false, forceUpdate)
|
||||
return g.UpdatePairs(pairs, asset.Spot, false, forceUpdate)
|
||||
}
|
||||
|
||||
// UpdateAccountInfo Retrieves balances for all enabled currencies for the
|
||||
|
||||
@@ -280,20 +280,20 @@ func (h *HitBTC) Run() {
|
||||
}
|
||||
|
||||
// FetchTradablePairs returns a list of the exchanges tradable pairs
|
||||
func (h *HitBTC) FetchTradablePairs(ctx context.Context, asset asset.Item) ([]string, error) {
|
||||
func (h *HitBTC) FetchTradablePairs(ctx context.Context, a asset.Item) (currency.Pairs, error) {
|
||||
symbols, err := h.GetSymbolsDetailed(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
format, err := h.GetPairFormat(asset, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pairs := make([]string, len(symbols))
|
||||
pairs := make([]currency.Pair, len(symbols))
|
||||
for x := range symbols {
|
||||
pairs[x] = symbols[x].BaseCurrency + format.Delimiter + symbols[x].QuoteCurrency
|
||||
var pair currency.Pair
|
||||
pair, err = currency.NewPairFromStrings(symbols[x].BaseCurrency, symbols[x].QuoteCurrency)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pairs[x] = pair
|
||||
}
|
||||
return pairs, nil
|
||||
}
|
||||
@@ -305,12 +305,7 @@ func (h *HitBTC) UpdateTradablePairs(ctx context.Context, forceUpdate bool) erro
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
p, err := currency.NewPairsFromStrings(pairs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return h.UpdatePairs(p, asset.Spot, false, forceUpdate)
|
||||
return h.UpdatePairs(pairs, asset.Spot, false, forceUpdate)
|
||||
}
|
||||
|
||||
// UpdateTickers updates the ticker for all currency pairs of a given asset type
|
||||
|
||||
@@ -457,12 +457,8 @@ func TestFOrder(t *testing.T) {
|
||||
if len(tradablePairs) == 0 {
|
||||
t.Fatal("no tradable pairs")
|
||||
}
|
||||
cp, err := currency.NewPairFromString(tradablePairs[0])
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
_, err = h.FOrder(context.Background(),
|
||||
currency.EMPTYPAIR, cp.Base.Upper().String(),
|
||||
currency.EMPTYPAIR, tradablePairs[0].Base.Upper().String(),
|
||||
"quarter", "123", "BUY", "open", "limit", 1, 1, 1)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
@@ -529,11 +525,7 @@ func TestFCancelAllOrders(t *testing.T) {
|
||||
if len(tradablePairs) == 0 {
|
||||
t.Fatal("no tradable pairs")
|
||||
}
|
||||
cp, err := currency.NewPairFromString(tradablePairs[0])
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
_, err = h.FCancelAllOrders(context.Background(), cp, "", "")
|
||||
_, err = h.FCancelAllOrders(context.Background(), tradablePairs[0], "", "")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -598,12 +590,8 @@ func TestFGetOrderHistory(t *testing.T) {
|
||||
if len(tradablePairs) == 0 {
|
||||
t.Fatal("no tradable pairs")
|
||||
}
|
||||
cp, err := currency.NewPairFromString(tradablePairs[0])
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
_, err = h.FGetOrderHistory(context.Background(),
|
||||
currency.EMPTYPAIR, cp.Base.Upper().String(),
|
||||
currency.EMPTYPAIR, tradablePairs[0].Base.Upper().String(),
|
||||
"all", "all", "limit",
|
||||
[]order.Status{},
|
||||
5, 0, 0)
|
||||
@@ -726,11 +714,7 @@ func TestUpdateTickerFutures(t *testing.T) {
|
||||
if len(tradablePairs) == 0 {
|
||||
t.Fatal("no tradable pairs")
|
||||
}
|
||||
cp2, err := currency.NewPairFromString(tradablePairs[0])
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
_, err = h.UpdateTicker(context.Background(), cp2, asset.Futures)
|
||||
_, err = h.UpdateTicker(context.Background(), tradablePairs[0], asset.Futures)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -770,11 +754,7 @@ func TestUpdateOrderbookFuture(t *testing.T) {
|
||||
if len(tradablePairs) == 0 {
|
||||
t.Fatal("no tradable pairs")
|
||||
}
|
||||
cp2, err := currency.NewPairFromString(tradablePairs[0])
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
_, err = h.UpdateOrderbook(context.Background(), cp2, asset.Futures)
|
||||
_, err = h.UpdateOrderbook(context.Background(), tradablePairs[0], asset.Futures)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -786,11 +766,7 @@ func TestUpdateOrderbookFuture(t *testing.T) {
|
||||
if len(tradablePairs) == 0 {
|
||||
t.Fatal("no tradable pairs")
|
||||
}
|
||||
cp2, err = currency.NewPairFromString(tradablePairs[0])
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
_, err = h.UpdateOrderbook(context.Background(), cp2, asset.CoinMarginedFutures)
|
||||
_, err = h.UpdateOrderbook(context.Background(), tradablePairs[0], asset.CoinMarginedFutures)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -842,11 +818,7 @@ func TestGetOrderHistory(t *testing.T) {
|
||||
if len(tradablePairs) == 0 {
|
||||
t.Fatal("no tradable pairs")
|
||||
}
|
||||
cp2, err := currency.NewPairFromString(tradablePairs[0])
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
getOrdersRequest.Pairs = []currency.Pair{cp2}
|
||||
getOrdersRequest.Pairs = []currency.Pair{tradablePairs[0]}
|
||||
getOrdersRequest.AssetType = asset.Futures
|
||||
_, err = h.GetOrderHistory(context.Background(), &getOrdersRequest)
|
||||
if err != nil {
|
||||
@@ -2746,11 +2718,7 @@ func TestFormatFuturesPair(t *testing.T) {
|
||||
}
|
||||
// test getting a tradable pair in the format of BTC210827 but make it lower
|
||||
// case to test correct formatting
|
||||
p, err := currency.NewPairFromString(strings.ToLower(availInstruments[0]))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
r, err = h.formatFuturesPair(p)
|
||||
r, err = h.formatFuturesPair(availInstruments[0])
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -337,18 +337,13 @@ func (h *HUOBI) Run() {
|
||||
}
|
||||
|
||||
// FetchTradablePairs returns a list of the exchanges tradable pairs
|
||||
func (h *HUOBI) FetchTradablePairs(ctx context.Context, a asset.Item) ([]string, error) {
|
||||
func (h *HUOBI) FetchTradablePairs(ctx context.Context, a asset.Item) (currency.Pairs, error) {
|
||||
if !h.SupportsAsset(a) {
|
||||
return nil, fmt.Errorf("asset type of %s is not supported by %s", a, h.Name)
|
||||
}
|
||||
|
||||
var pairs []string
|
||||
|
||||
format, err := h.GetPairFormat(a, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var pairs []currency.Pair
|
||||
var pair currency.Pair
|
||||
switch a {
|
||||
case asset.Spot:
|
||||
symbols, err := h.GetSymbols(ctx)
|
||||
@@ -356,44 +351,51 @@ func (h *HUOBI) FetchTradablePairs(ctx context.Context, a asset.Item) ([]string,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pairs = make([]currency.Pair, 0, len(symbols))
|
||||
for x := range symbols {
|
||||
if symbols[x].State != "online" {
|
||||
continue
|
||||
}
|
||||
pairs = append(pairs, symbols[x].BaseCurrency+
|
||||
format.Delimiter+
|
||||
symbols[x].QuoteCurrency)
|
||||
}
|
||||
|
||||
pair, err = currency.NewPairFromStrings(symbols[x].BaseCurrency,
|
||||
symbols[x].QuoteCurrency)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pairs = append(pairs, pair)
|
||||
}
|
||||
case asset.CoinMarginedFutures:
|
||||
symbols, err := h.GetSwapMarkets(ctx, currency.EMPTYPAIR)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pairs = make([]currency.Pair, 0, len(symbols))
|
||||
for z := range symbols {
|
||||
if symbols[z].ContractStatus == 1 {
|
||||
curr, err := currency.NewPairFromString(symbols[z].ContractCode)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pairs = append(pairs, format.Format(curr))
|
||||
if symbols[z].ContractStatus != 1 {
|
||||
continue
|
||||
}
|
||||
pair, err := currency.NewPairFromString(symbols[z].ContractCode)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pairs = append(pairs, pair)
|
||||
}
|
||||
case asset.Futures:
|
||||
symbols, err := h.FGetContractInfo(ctx, "", "", currency.EMPTYPAIR)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pairs = make([]currency.Pair, 0, len(symbols.Data))
|
||||
for c := range symbols.Data {
|
||||
if symbols.Data[c].ContractStatus == 1 {
|
||||
curr, err := currency.NewPairFromString(symbols.Data[c].ContractCode)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pairs = append(pairs, format.Format(curr))
|
||||
if symbols.Data[c].ContractStatus != 1 {
|
||||
continue
|
||||
}
|
||||
pair, err := currency.NewPairFromString(symbols.Data[c].ContractCode)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pairs = append(pairs, pair)
|
||||
}
|
||||
}
|
||||
return pairs, nil
|
||||
@@ -402,41 +404,18 @@ func (h *HUOBI) FetchTradablePairs(ctx context.Context, a asset.Item) ([]string,
|
||||
// UpdateTradablePairs updates the exchanges available pairs and stores
|
||||
// them in the exchanges config
|
||||
func (h *HUOBI) UpdateTradablePairs(ctx context.Context, forceUpdate bool) error {
|
||||
spotPairs, err := h.FetchTradablePairs(ctx, asset.Spot)
|
||||
if err != nil {
|
||||
return err
|
||||
assets := h.GetAssetTypes(false)
|
||||
for x := range assets {
|
||||
pairs, err := h.FetchTradablePairs(ctx, assets[x])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = h.UpdatePairs(pairs, assets[x], false, forceUpdate)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
p, err := currency.NewPairsFromStrings(spotPairs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = h.UpdatePairs(p, asset.Spot, false, forceUpdate)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
futuresPairs, err := h.FetchTradablePairs(ctx, asset.Futures)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fp, err := currency.NewPairsFromStrings(futuresPairs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = h.UpdatePairs(fp, asset.Futures, false, forceUpdate)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
coinmarginedFuturesPairs, err := h.FetchTradablePairs(ctx, asset.CoinMarginedFutures)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cp, err := currency.NewPairsFromStrings(coinmarginedFuturesPairs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return h.UpdatePairs(cp, asset.CoinMarginedFutures, false, forceUpdate)
|
||||
return nil
|
||||
}
|
||||
|
||||
// UpdateTickers updates the ticker for all currency pairs of a given asset type
|
||||
|
||||
@@ -34,7 +34,7 @@ type IBotExchange interface {
|
||||
UpdateTickers(ctx context.Context, a asset.Item) error
|
||||
FetchOrderbook(ctx context.Context, p currency.Pair, a asset.Item) (*orderbook.Base, error)
|
||||
UpdateOrderbook(ctx context.Context, p currency.Pair, a asset.Item) (*orderbook.Base, error)
|
||||
FetchTradablePairs(ctx context.Context, a asset.Item) ([]string, error)
|
||||
FetchTradablePairs(ctx context.Context, a asset.Item) (currency.Pairs, error)
|
||||
UpdateTradablePairs(ctx context.Context, forceUpdate bool) error
|
||||
GetEnabledPairs(a asset.Item) (currency.Pairs, error)
|
||||
GetAvailablePairs(a asset.Item) (currency.Pairs, error)
|
||||
|
||||
@@ -136,7 +136,7 @@ func (i *ItBit) Run() {
|
||||
}
|
||||
|
||||
// FetchTradablePairs returns a list of the exchanges tradable pairs
|
||||
func (i *ItBit) FetchTradablePairs(ctx context.Context, asset asset.Item) ([]string, error) {
|
||||
func (i *ItBit) FetchTradablePairs(ctx context.Context, a asset.Item) (currency.Pairs, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
|
||||
@@ -428,7 +428,7 @@ func (k *Kraken) GetTrades(ctx context.Context, symbol currency.Pair) ([]RecentT
|
||||
if !ok {
|
||||
return nil, errors.New("unable to parse individual trade data")
|
||||
}
|
||||
if len(individualTrade) != 6 {
|
||||
if len(individualTrade) != 7 {
|
||||
return nil, errors.New("unrecognised trade data received")
|
||||
}
|
||||
r.Price, err = strconv.ParseFloat(individualTrade[0].(string), 64)
|
||||
@@ -455,6 +455,11 @@ func (k *Kraken) GetTrades(ctx context.Context, symbol currency.Pair) ([]RecentT
|
||||
if !ok {
|
||||
return nil, errors.New("unable to parse misc field for individual trade data")
|
||||
}
|
||||
tradeID, ok := individualTrade[6].(float64)
|
||||
if !ok {
|
||||
return nil, errors.New("unable to parse TradeID field for individual trade data")
|
||||
}
|
||||
r.TradeID = int64(tradeID)
|
||||
recentTrades[x] = r
|
||||
}
|
||||
return recentTrades, nil
|
||||
|
||||
@@ -172,6 +172,7 @@ type RecentTrades struct {
|
||||
BuyOrSell string
|
||||
MarketOrLimit string
|
||||
Miscellaneous interface{}
|
||||
TradeID int64
|
||||
}
|
||||
|
||||
// OrderbookBase stores the orderbook price and amount data
|
||||
|
||||
@@ -340,61 +340,66 @@ func (k *Kraken) Run() {
|
||||
}
|
||||
|
||||
// FetchTradablePairs returns a list of the exchanges tradable pairs
|
||||
func (k *Kraken) FetchTradablePairs(ctx context.Context, assetType asset.Item) ([]string, error) {
|
||||
var products []string
|
||||
format, err := k.GetPairFormat(assetType, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch assetType {
|
||||
func (k *Kraken) FetchTradablePairs(ctx context.Context, a asset.Item) (currency.Pairs, error) {
|
||||
var pairs []currency.Pair
|
||||
var pair currency.Pair
|
||||
switch a {
|
||||
case asset.Spot:
|
||||
if !assetTranslator.Seeded() {
|
||||
if err := k.SeedAssets(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
pairs, err := k.GetAssetPairs(ctx, []string{}, "")
|
||||
symbols, err := k.GetAssetPairs(ctx, nil, "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for i := range pairs {
|
||||
if strings.Contains(pairs[i].Altname, ".d") {
|
||||
|
||||
pairs = make([]currency.Pair, 0, len(symbols))
|
||||
for i := range symbols {
|
||||
if strings.Contains(symbols[i].Altname, ".d") {
|
||||
continue
|
||||
}
|
||||
base := assetTranslator.LookupAltname(pairs[i].Base)
|
||||
base := assetTranslator.LookupAltname(symbols[i].Base)
|
||||
if base == "" {
|
||||
log.Warnf(log.ExchangeSys,
|
||||
"%s unable to lookup altname for base currency %s",
|
||||
k.Name,
|
||||
pairs[i].Base)
|
||||
symbols[i].Base)
|
||||
continue
|
||||
}
|
||||
quote := assetTranslator.LookupAltname(pairs[i].Quote)
|
||||
quote := assetTranslator.LookupAltname(symbols[i].Quote)
|
||||
if quote == "" {
|
||||
log.Warnf(log.ExchangeSys,
|
||||
"%s unable to lookup altname for quote currency %s",
|
||||
k.Name,
|
||||
pairs[i].Quote)
|
||||
symbols[i].Quote)
|
||||
continue
|
||||
}
|
||||
products = append(products, base+format.Delimiter+quote)
|
||||
pair, err = currency.NewPairFromStrings(base, quote)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pairs = append(pairs, pair)
|
||||
}
|
||||
case asset.Futures:
|
||||
pairs, err := k.GetFuturesMarkets(ctx)
|
||||
symbols, err := k.GetFuturesMarkets(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for x := range pairs.Instruments {
|
||||
if pairs.Instruments[x].Tradable {
|
||||
curr, err := currency.NewPairFromString(pairs.Instruments[x].Symbol)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
products = append(products, format.Format(curr))
|
||||
pairs = make([]currency.Pair, 0, len(symbols.Instruments))
|
||||
for x := range symbols.Instruments {
|
||||
if !symbols.Instruments[x].Tradable {
|
||||
continue
|
||||
}
|
||||
pair, err := currency.NewPairFromString(symbols.Instruments[x].Symbol)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pairs = append(pairs, pair)
|
||||
}
|
||||
}
|
||||
return products, nil
|
||||
return pairs, nil
|
||||
}
|
||||
|
||||
// UpdateTradablePairs updates the exchanges available pairs and stores
|
||||
@@ -406,11 +411,7 @@ func (k *Kraken) UpdateTradablePairs(ctx context.Context, forceUpdate bool) erro
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
p, err := currency.NewPairsFromStrings(pairs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = k.UpdatePairs(p, assets[x], false, forceUpdate)
|
||||
err = k.UpdatePairs(pairs, assets[x], false, forceUpdate)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -698,6 +699,7 @@ func (k *Kraken) GetRecentTrades(ctx context.Context, p currency.Pair, assetType
|
||||
Price: tradeData[i].Price,
|
||||
Amount: tradeData[i].Volume,
|
||||
Timestamp: convert.TimeFromUnixTimestampDecimal(tradeData[i].Time),
|
||||
TID: strconv.FormatInt(tradeData[i].TradeID, 10),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -177,12 +177,12 @@ func (l *Lbank) Run() {
|
||||
}
|
||||
|
||||
// FetchTradablePairs returns a list of the exchanges tradable pairs
|
||||
func (l *Lbank) FetchTradablePairs(ctx context.Context, asset asset.Item) ([]string, error) {
|
||||
func (l *Lbank) FetchTradablePairs(ctx context.Context, a asset.Item) (currency.Pairs, error) {
|
||||
currencies, err := l.GetCurrencyPairs(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return currencies, nil
|
||||
return currency.NewPairsFromStrings(currencies)
|
||||
}
|
||||
|
||||
// UpdateTradablePairs updates the exchanges available pairs and stores
|
||||
@@ -192,12 +192,7 @@ func (l *Lbank) UpdateTradablePairs(ctx context.Context, forceUpdate bool) error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
p, err := currency.NewPairsFromStrings(pairs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return l.UpdatePairs(p, asset.Spot, false, forceUpdate)
|
||||
return l.UpdatePairs(pairs, asset.Spot, false, forceUpdate)
|
||||
}
|
||||
|
||||
// UpdateTickers updates the ticker for all currency pairs of a given asset type
|
||||
|
||||
@@ -151,17 +151,21 @@ func (l *LocalBitcoins) Run() {
|
||||
}
|
||||
|
||||
// FetchTradablePairs returns a list of the exchanges tradable pairs
|
||||
func (l *LocalBitcoins) FetchTradablePairs(ctx context.Context, asset asset.Item) ([]string, error) {
|
||||
func (l *LocalBitcoins) FetchTradablePairs(ctx context.Context, a asset.Item) (currency.Pairs, error) {
|
||||
currencies, err := l.GetTradableCurrencies(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pairs := make([]string, len(currencies))
|
||||
pairs := make([]currency.Pair, len(currencies))
|
||||
for x := range currencies {
|
||||
pairs[x] = "BTC" + currencies[x]
|
||||
var pair currency.Pair
|
||||
pair, err = currency.NewPairFromStrings("BTC", currencies[x])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pairs[x] = pair
|
||||
}
|
||||
|
||||
return pairs, nil
|
||||
}
|
||||
|
||||
@@ -172,11 +176,7 @@ func (l *LocalBitcoins) UpdateTradablePairs(ctx context.Context, forceUpdate boo
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
p, err := currency.NewPairsFromStrings(pairs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return l.UpdatePairs(p, asset.Spot, false, forceUpdate)
|
||||
return l.UpdatePairs(pairs, asset.Spot, false, forceUpdate)
|
||||
}
|
||||
|
||||
// UpdateTickers updates the ticker for all currency pairs of a given asset type
|
||||
|
||||
@@ -247,22 +247,21 @@ func (o *OKCoin) Run() {
|
||||
}
|
||||
|
||||
// FetchTradablePairs returns a list of the exchanges tradable pairs
|
||||
func (o *OKCoin) FetchTradablePairs(ctx context.Context, asset asset.Item) ([]string, error) {
|
||||
func (o *OKCoin) FetchTradablePairs(ctx context.Context, a asset.Item) (currency.Pairs, error) {
|
||||
prods, err := o.GetSpotTokenPairDetails(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
format, err := o.GetPairFormat(asset, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pairs := make([]string, len(prods))
|
||||
pairs := make([]currency.Pair, len(prods))
|
||||
for x := range prods {
|
||||
pairs[x] = prods[x].BaseCurrency + format.Delimiter + prods[x].QuoteCurrency
|
||||
var pair currency.Pair
|
||||
pair, err = currency.NewPairFromStrings(prods[x].BaseCurrency, prods[x].QuoteCurrency)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pairs[x] = pair
|
||||
}
|
||||
|
||||
return pairs, nil
|
||||
}
|
||||
|
||||
@@ -273,11 +272,7 @@ func (o *OKCoin) UpdateTradablePairs(ctx context.Context, forceUpdate bool) erro
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
p, err := currency.NewPairsFromStrings(pairs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return o.UpdatePairs(p, asset.Spot, false, forceUpdate)
|
||||
return o.UpdatePairs(pairs, asset.Spot, false, forceUpdate)
|
||||
}
|
||||
|
||||
// UpdateTickers updates the ticker for all currency pairs of a given asset type
|
||||
|
||||
@@ -274,7 +274,11 @@ func TestGetOptionMarketData(t *testing.T) {
|
||||
|
||||
func TestGetEstimatedDeliveryPrice(t *testing.T) {
|
||||
t.Parallel()
|
||||
if _, err := ok.GetEstimatedDeliveryPrice(context.Background(), "BTC-USD"); err != nil && !strings.Contains(err.Error(), "Instrument ID does not exist.") {
|
||||
r, err := ok.FetchTradablePairs(context.Background(), asset.Futures)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := ok.GetEstimatedDeliveryPrice(context.Background(), r[0].String()); err != nil {
|
||||
t.Error("Okx GetEstimatedDeliveryPrice() error", err)
|
||||
}
|
||||
}
|
||||
@@ -302,7 +306,7 @@ func TestGetLiquidationOrders(t *testing.T) {
|
||||
}
|
||||
if _, err := ok.GetLiquidationOrders(context.Background(), &LiquidationOrderRequestParams{
|
||||
InstrumentType: okxInstTypeMargin,
|
||||
Underlying: insts[0],
|
||||
Underlying: insts[0].String(),
|
||||
Currency: currency.BTC,
|
||||
Limit: 2,
|
||||
}); err != nil {
|
||||
@@ -2724,11 +2728,7 @@ func TestEstimatedDeliveryExercisePriceSubscription(t *testing.T) {
|
||||
if len(futuresPairs) == 0 {
|
||||
t.SkipNow()
|
||||
}
|
||||
currencyPair, err := currency.NewPairFromString(futuresPairs[0])
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err := ok.EstimatedDeliveryExercisePriceSubscription("subscribe", asset.Futures, currencyPair); err != nil {
|
||||
if err := ok.EstimatedDeliveryExercisePriceSubscription("subscribe", asset.Futures, futuresPairs[0]); err != nil {
|
||||
t.Errorf("%s EstimatedDeliveryExercisePriceSubscription() error: %v", ok.Name, err)
|
||||
}
|
||||
}
|
||||
@@ -2742,11 +2742,7 @@ func TestMarkPriceSubscription(t *testing.T) {
|
||||
if len(futuresPairs) == 0 {
|
||||
t.SkipNow()
|
||||
}
|
||||
currencyPair, err := currency.NewPairFromString(futuresPairs[0])
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err := ok.MarkPriceSubscription("subscribe", asset.Futures, currencyPair); err != nil {
|
||||
if err := ok.MarkPriceSubscription("subscribe", asset.Futures, futuresPairs[0]); err != nil {
|
||||
t.Errorf("%s MarkPriceSubscription() error: %v", ok.Name, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -270,15 +270,12 @@ func (ok *Okx) GetServerTime(ctx context.Context, ai asset.Item) (time.Time, err
|
||||
}
|
||||
|
||||
// FetchTradablePairs returns a list of the exchanges tradable pairs
|
||||
func (ok *Okx) FetchTradablePairs(ctx context.Context, a asset.Item) ([]string, error) {
|
||||
func (ok *Okx) FetchTradablePairs(ctx context.Context, a asset.Item) (currency.Pairs, error) {
|
||||
if !ok.SupportsAsset(a) {
|
||||
return nil, fmt.Errorf("asset type of %s is not supported by %s", a, ok.Name)
|
||||
}
|
||||
format, err := ok.GetPairFormat(a, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
insts := []Instrument{}
|
||||
var insts []Instrument
|
||||
var err error
|
||||
switch a {
|
||||
case asset.Spot:
|
||||
insts, err = ok.GetInstruments(ctx, &InstrumentsFetchParams{
|
||||
@@ -298,8 +295,8 @@ func (ok *Okx) FetchTradablePairs(ctx context.Context, a asset.Item) ([]string,
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var instruments []Instrument
|
||||
for x := range underlyings {
|
||||
var instruments []Instrument
|
||||
instruments, err = ok.GetInstruments(ctx, &InstrumentsFetchParams{
|
||||
InstrumentType: okxInstTypeOption,
|
||||
Underlying: underlyings[x],
|
||||
@@ -320,13 +317,12 @@ func (ok *Okx) FetchTradablePairs(ctx context.Context, a asset.Item) ([]string,
|
||||
if len(insts) == 0 {
|
||||
return nil, errNoInstrumentFound
|
||||
}
|
||||
pairs := make([]string, len(insts))
|
||||
pairs := make([]currency.Pair, len(insts))
|
||||
for x := range insts {
|
||||
c, err := currency.NewPairFromString(insts[x].InstrumentID)
|
||||
pairs[x], err = currency.NewPairFromString(insts[x].InstrumentID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pairs[x] = format.Format(c)
|
||||
}
|
||||
return pairs, nil
|
||||
}
|
||||
@@ -335,11 +331,7 @@ func (ok *Okx) FetchTradablePairs(ctx context.Context, a asset.Item) ([]string,
|
||||
func (ok *Okx) UpdateTradablePairs(ctx context.Context, forceUpdate bool) error {
|
||||
assetTypes := ok.GetAssetTypes(false)
|
||||
for i := range assetTypes {
|
||||
p, err := ok.FetchTradablePairs(ctx, assetTypes[i])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
pairs, err := currency.NewPairsFromStrings(p)
|
||||
pairs, err := ok.FetchTradablePairs(ctx, assetTypes[i])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -254,18 +254,24 @@ func (p *Poloniex) Run() {
|
||||
}
|
||||
|
||||
// FetchTradablePairs returns a list of the exchanges tradable pairs
|
||||
func (p *Poloniex) FetchTradablePairs(ctx context.Context, asset asset.Item) ([]string, error) {
|
||||
func (p *Poloniex) FetchTradablePairs(ctx context.Context, a asset.Item) (currency.Pairs, error) {
|
||||
resp, err := p.GetTicker(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
currencies := make([]string, 0, len(resp))
|
||||
for x := range resp {
|
||||
currencies = append(currencies, x)
|
||||
pairs := make([]currency.Pair, len(resp))
|
||||
var target int
|
||||
for key := range resp {
|
||||
var pair currency.Pair
|
||||
pair, err = currency.NewPairFromString(key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pairs[target] = pair
|
||||
target++
|
||||
}
|
||||
|
||||
return currencies, nil
|
||||
return pairs, nil
|
||||
}
|
||||
|
||||
// UpdateTradablePairs updates the exchanges available pairs and stores
|
||||
@@ -275,11 +281,7 @@ func (p *Poloniex) UpdateTradablePairs(ctx context.Context, forceUpgrade bool) e
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ps, err := currency.NewPairsFromStrings(pairs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return p.UpdatePairs(ps, asset.Spot, false, forceUpgrade)
|
||||
return p.UpdatePairs(pairs, asset.Spot, false, forceUpgrade)
|
||||
}
|
||||
|
||||
// UpdateTickers updates the ticker for all currency pairs of a given asset type
|
||||
|
||||
@@ -84,7 +84,7 @@ func (c *CustomEx) UpdateOrderbook(ctx context.Context, p currency.Pair, a asset
|
||||
}
|
||||
|
||||
// FetchTradablePairs is a mock method for CustomEx
|
||||
func (c *CustomEx) FetchTradablePairs(ctx context.Context, a asset.Item) ([]string, error) {
|
||||
func (c *CustomEx) FetchTradablePairs(ctx context.Context, a asset.Item) (currency.Pairs, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"math"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -159,18 +158,24 @@ func (y *Yobit) Run() {
|
||||
}
|
||||
|
||||
// FetchTradablePairs returns a list of the exchanges tradable pairs
|
||||
func (y *Yobit) FetchTradablePairs(ctx context.Context, asset asset.Item) ([]string, error) {
|
||||
func (y *Yobit) FetchTradablePairs(ctx context.Context, a asset.Item) (currency.Pairs, error) {
|
||||
info, err := y.GetInfo(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
currencies := make([]string, 0, len(info.Pairs))
|
||||
for x := range info.Pairs {
|
||||
currencies = append(currencies, strings.ToUpper(x))
|
||||
pairs := make([]currency.Pair, len(info.Pairs))
|
||||
var target int
|
||||
for key := range info.Pairs {
|
||||
var pair currency.Pair
|
||||
pair, err = currency.NewPairFromString(key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pairs[target] = pair
|
||||
target++
|
||||
}
|
||||
|
||||
return currencies, nil
|
||||
return pairs, nil
|
||||
}
|
||||
|
||||
// UpdateTradablePairs updates the exchanges available pairs and stores
|
||||
@@ -180,11 +185,7 @@ func (y *Yobit) UpdateTradablePairs(ctx context.Context, forceUpdate bool) error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
p, err := currency.NewPairsFromStrings(pairs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return y.UpdatePairs(p, asset.Spot, false, forceUpdate)
|
||||
return y.UpdatePairs(pairs, asset.Spot, false, forceUpdate)
|
||||
}
|
||||
|
||||
// UpdateTickers updates the ticker for all currency pairs of a given asset type
|
||||
|
||||
@@ -221,18 +221,24 @@ func (z *ZB) Run() {
|
||||
}
|
||||
|
||||
// FetchTradablePairs returns a list of the exchanges tradable pairs
|
||||
func (z *ZB) FetchTradablePairs(ctx context.Context, asset asset.Item) ([]string, error) {
|
||||
func (z *ZB) FetchTradablePairs(ctx context.Context, a asset.Item) (currency.Pairs, error) {
|
||||
markets, err := z.GetMarkets(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
currencies := make([]string, 0, len(markets))
|
||||
for x := range markets {
|
||||
currencies = append(currencies, x)
|
||||
pairs := make([]currency.Pair, len(markets))
|
||||
var target int
|
||||
for key := range markets {
|
||||
var pair currency.Pair
|
||||
pair, err = currency.NewPairFromString(key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pairs[target] = pair
|
||||
target++
|
||||
}
|
||||
|
||||
return currencies, nil
|
||||
return pairs, nil
|
||||
}
|
||||
|
||||
// UpdateTradablePairs updates the exchanges available pairs and stores
|
||||
@@ -242,11 +248,7 @@ func (z *ZB) UpdateTradablePairs(ctx context.Context, forceUpdate bool) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
p, err := currency.NewPairsFromStrings(pairs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return z.UpdatePairs(p, asset.Spot, false, forceUpdate)
|
||||
return z.UpdatePairs(pairs, asset.Spot, false, forceUpdate)
|
||||
}
|
||||
|
||||
// UpdateTickers updates the ticker for all currency pairs of a given asset type
|
||||
|
||||
Reference in New Issue
Block a user