Coinbase: Update exchange implementation (#1480)

* Slight enhance of Coinbase tests

Continual enhance of Coinbase tests

The revamp continues

Oh jeez the Orderbook part's unfinished don't look

Coinbase revamp, Orderbook still unfinished

* Coinbase revamp; CreateReport is still WIP

* More coinbase improvements; onto sandbox testing

* Coinbase revamp continues

* Coinbase revamp continues

* Coinbasepro revamp is ceaseless

* Coinbase revamp, starting on advanced trade API

* Coinbase Advanced Trade Starts in Ernest

V3 done, onto V2

Coinbase revamp nears completion

Coinbase revamp nears completion

Test commit should fail

Coinbase revamp nears completion

* Coinbase revamp stage wrapper

* Coinbase wrapper coherence continues

* Coinbase wrapper continues writhing

* Coinbase wrapper & codebase cleanup

* Coinbase updates & wrap progress

* More Coinbase wrapper progress

* Wrapper is wrapped, kinda

* Test & type checking

* Coinbase REST revamp finished

* Post-merge fix

* WS revamp begins

* WS Main Revamp Done?

* CB websocket tidying up

* Coinbase WS wrapperupperer

* Coinbase revamp done??

* Linter progress

* Continued lint cleanup

* Further lint cleanup

* Increased lint coverage

* Does this fix all sloppy reassigns & shadowing?

* Undoing retry policy change

* Documentation regeneration

* Coinbase code improvements

* Providing warning about known issue

* Updating an error to new format

* Making gocritic happy

* Review adherence

* Endpoints moved to V3 & nil pointer fixes

* Removing seemingly superfluous constant

* Glorious improvements

* Removing unused error

* Partial public endpoint addition

* Slight improvements

* Wrapper improvements; still a few errors left in other packages

* A lil Coinbase progress

* Json cleaning

* Lint appeasement

* Config repair

* Config fix (real)

* Little fix

* New public endpoint incorporation

* Additional fixes

* Improvements & Appeasements

* LineSaver

* Additional fixes

* Another fix

* Fixing picked nits

* Quick fixies

* Lil fixes

* Subscriptions: Add List.Enabled

* CoinbasePro: Add subscription templating

* fixup! CoinbasePro: Add subscription templating

* fixup! CoinbasePro: Add subscription templating

* Comment fix

* Subsequent fixes

* Issues hopefully fixed

* Lint fix

* Glorious fixes

* Json formatting

* ShazNits

* (L/N)i(n/)t

* Adding a test

* Tiny test improvement

* Template patch testing

* Fixes

* Further shaznits

* Lint nit

* JWT move and other fixes

* Small nits

* Shaznit, singular

* Post-merge fix

* Post-merge fixes

* Typo fix

* Some glorious nits

* Required changes

* Stop going

* Alias attempt

* Alias fix & test cleanup

* Test fix

* GetDepositAddress logic improvement

* Status update: Fixed

* Lint fix

* Happy birthday to PR 1480

* Cleanups

* Necessary nit corrections

* Fixing sillybug

* As per request

* Programming progress

* Order fixes

* Further fixies

* Test fix

* Pre-merge fixes

* More shaznits

* Context

* Sonic error handling

* Import fix

* Better Sonic error handling

* Perfect Sonic error handling?

* F purge

* Coinbase improvements

* API Update Conformity

* Coinbase continuation

* Coinbase order improvements

* Coinbase order improvements

* CreateOrderConfig improvements

* Managing API updates

* Coinbase API update progression

* jwt rename

* Comment link fix

* Coinbase v2 cleanup

* Post-merge fixes

* Review fixes

* GK's suggestions

* Linter fix

* Minor gbjk fixes

* Nit fixes

* Merge fix

* Lint fixes

* Coinbase rename stage 1

* Coinbase rename stage 2

* Coinbase rename stage 3

* Coinbase rename stage 4

* Coinbase rename final fix

* Coinbase: PoC on converting to request structs

* Applying requested changes

* Many review fixes, handled

* Thrashed by nits

* More minor modifications

* The last nit!?

---------

Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com>
This commit is contained in:
cranktakular
2025-09-16 13:37:00 +10:00
committed by GitHub
parent d957ddae62
commit fd9aaf00a2
78 changed files with 8850 additions and 3937 deletions

View File

@@ -3021,12 +3021,15 @@ var (
FI = NewCode("FI")
USDM = NewCode("USDM")
USDTM = NewCode("USDTM")
CBETH = NewCode("CBETH")
PYUSD = NewCode("PYUSD")
EUROC = NewCode("EUROC")
LSETH = NewCode("LSETH")
LEVER = NewCode("LEVER")
NESS = NewCode("NESS")
KAS = NewCode("KAS")
NEXT = NewCode("NEXT")
VEXT = NewCode("VEXT")
PYUSD = NewCode("PYUSD")
SAIL = NewCode("SAIL")
VV = NewCode("VV")
ORDI = NewCode("ORDI")

View File

@@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"maps"
"slices"
"strings"
"sync"
@@ -11,6 +12,11 @@ import (
"github.com/thrasher-corp/gocryptotrader/log"
)
var (
errNoProvider = errors.New("no supporting foreign exchange providers set")
errUnsupportedCurrencies = errors.New("currencies not supported by provider")
)
// IFXProvider enforces standard functions for all foreign exchange providers
// supported in GoCryptoTrader
type IFXProvider interface {
@@ -106,47 +112,27 @@ func (f *FXHandler) GetCurrencyData(baseCurrency string, currencies []string) (m
return rates, nil
}
// backupGetRate uses the currencies that are supported and falls through, and
// errors when unsupported currency found
// backupGetRate uses the currencies that are supported and falls through, and errors when unsupported currency found
func (f *FXHandler) backupGetRate(base string, currencies []string) (map[string]float64, error) {
if f.Support == nil {
return nil, errors.New("no supporting foreign exchange providers set")
return nil, errNoProvider
}
var shunt []string
rate := make(map[string]float64)
for i := range f.Support {
if len(shunt) != 0 {
shunt = f.Support[i].CheckCurrencies(shunt)
newRate, err := f.Support[i].GetNewRate(base, shunt)
if err != nil {
continue
}
maps.Copy(rate, newRate)
if len(shunt) != 0 {
continue
}
return rate, nil
}
shunt = f.Support[i].CheckCurrencies(currencies)
newRate, err := f.Support[i].GetNewRate(base, currencies)
missed := f.Support[i].CheckCurrencies(currencies)
toGet := slices.DeleteFunc(currencies, func(s string) bool {
return common.StringSliceContains(missed, s)
})
newRate, err := f.Support[i].GetNewRate(base, toGet)
if err != nil {
continue
return nil, err
}
maps.Copy(rate, newRate)
if len(shunt) != 0 {
if len(missed) != 0 {
currencies = missed
continue
}
return rate, nil
}
return nil, fmt.Errorf("currencies %s not supported", shunt)
return nil, fmt.Errorf("%w: %s", errUnsupportedCurrencies, currencies)
}

View File

@@ -0,0 +1,66 @@
package base
import (
"errors"
"math/rand/v2"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
var errCurrencyNotSupported = errors.New("currency not supported")
type MockProvider struct {
IFXProvider
value float64
}
func (m *MockProvider) IsEnabled() bool {
return true
}
func (m *MockProvider) GetName() string {
return ""
}
func (m *MockProvider) GetRates(baseCurrency, symbols string) (map[string]float64, error) {
c := map[string]float64{}
for s := range strings.SplitSeq(symbols, ",") {
if s == "XRP" && m.value == 1.5 {
return nil, errCurrencyNotSupported
}
if s == "BTC" {
c[baseCurrency+s] = m.value
continue
}
c[baseCurrency+s] = 1 / (1 + rand.Float64()) //nolint:gosec // Doesn't need to be a strong random number
}
return c, nil
}
func TestBackupGetRate(t *testing.T) {
var f FXHandler
_, err := f.backupGetRate("", nil)
assert.ErrorIs(t, err, errNoProvider)
f.Support = append(f.Support, Provider{
SupportedCurrencies: []string{"BTC", "ETH", "XRP"},
Provider: &MockProvider{
value: 1.5,
},
}, Provider{
SupportedCurrencies: []string{"BTC", "LTC", "XRP"},
Provider: &MockProvider{
value: 2.5,
},
})
_, err = f.backupGetRate("", []string{"XRP"})
assert.ErrorIs(t, err, errCurrencyNotSupported)
_, err = f.backupGetRate("", []string{"NOTREALCURRENCY"})
assert.ErrorIs(t, err, errUnsupportedCurrencies)
f.Support[0].SupportedCurrencies = []string{"BTC", "ETH"}
r, err := f.backupGetRate("USD", []string{"BTC", "ETH", "LTC", "XRP"})
assert.NoError(t, err)
assert.Len(t, r, 4)
assert.Equal(t, 1.5, r["USDBTC"])
}

View File

@@ -145,7 +145,6 @@ list:
if p.Contains(check[x], exact) {
return fmt.Errorf("%s %w", check[x], ErrPairDuplication)
}
return fmt.Errorf("%s %w", check[x], ErrPairNotContainedInAvailablePairs)
}
return nil