exchange/order/limits: Migrate to new package and integrate with exchanges (#1860)

* move limits, transition to key gen

* rollout NewExchangePairAssetKey everywhere

* test improvements

* self-review fixes

* ok, lets go

* fix merge issue

* slower value func,assertify,drop IsValidPairString

* remove binance reference for backtesting test

* Redundant nil checks removed due to redundancy

* Update order_test.go

* Move limits back into /exchanges/

* puts limits in a different box again

* SHAZBERT SPECIAL SUGGESTIONS

* Update gateio_wrapper.go

* fixes all build issues

* Many niteroos!

* something has gone awry

* bugfix

* gk's everywhere nits

* lint

* extra lint

* re-remove IsValidPairString

* lint fix

* standardise test

* revert some bads

* dupe rm

* another revert 360 mcgee

* un-in-revertify

* Update exchange/order/limits/levels_test.go

Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io>

* fix

* Update exchanges/binance/binance_test.go

HERE'S HOPING GITHUB FORMATS THIS CORRECTLY!

Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com>

* update text

* rn func, same line err gk4202000

---------

Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io>
Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com>
This commit is contained in:
Scott
2025-08-26 12:30:21 +10:00
committed by GitHub
parent fc0f262c42
commit 85403fe801
103 changed files with 1751 additions and 2168 deletions

View File

@@ -28,7 +28,7 @@ var (
func init() {
service = new(Service)
service.Tickers = make(map[key.ExchangePairAsset]*Ticker)
service.Tickers = make(map[key.ExchangeAssetPair]*Ticker)
service.Exchange = make(map[string]uuid.UUID)
service.mux = dispatch.GetNewMux(nil)
}
@@ -39,12 +39,7 @@ func SubscribeTicker(exchange string, p currency.Pair, a asset.Item) (dispatch.P
exchange = strings.ToLower(exchange)
service.mu.Lock()
defer service.mu.Unlock()
tick, ok := service.Tickers[key.ExchangePairAsset{
Exchange: exchange,
Base: p.Base.Item,
Quote: p.Quote.Item,
Asset: a,
}]
tick, ok := service.Tickers[key.NewExchangeAssetPair(exchange, a, p)]
if !ok {
return dispatch.Pipe{}, fmt.Errorf("ticker item not found for %s %s %s",
exchange,
@@ -77,17 +72,12 @@ func GetTicker(exchange string, p currency.Pair, a asset.Item) (*Price, error) {
return nil, currency.ErrCurrencyPairEmpty
}
if !a.IsValid() {
return nil, fmt.Errorf("%w %v", asset.ErrNotSupported, a)
return nil, fmt.Errorf("%w %q", asset.ErrNotSupported, a)
}
exchange = strings.ToLower(exchange)
service.mu.Lock()
defer service.mu.Unlock()
tick, ok := service.Tickers[key.ExchangePairAsset{
Exchange: exchange,
Base: p.Base.Item,
Quote: p.Quote.Item,
Asset: a,
}]
tick, ok := service.Tickers[key.NewExchangeAssetPair(exchange, a, p)]
if !ok {
return nil, fmt.Errorf("%w %s %s %s", ErrTickerNotFound, exchange, p, a)
}
@@ -191,12 +181,7 @@ func ProcessTicker(p *Price) error {
// update updates ticker price
func (s *Service) update(p *Price) error {
name := strings.ToLower(p.ExchangeName)
mapKey := key.ExchangePairAsset{
Exchange: name,
Base: p.Pair.Base.Item,
Quote: p.Pair.Quote.Item,
Asset: p.AssetType,
}
mapKey := key.NewExchangeAssetPair(name, p.AssetType, p.Pair)
s.mu.Lock()
t, ok := service.Tickers[mapKey]
if !ok || t == nil {

View File

@@ -445,7 +445,7 @@ func TestGetExchangeTickersPublic(t *testing.T) {
func TestGetExchangeTickers(t *testing.T) {
t.Parallel()
s := Service{
Tickers: make(map[key.ExchangePairAsset]*Ticker),
Tickers: make(map[key.ExchangeAssetPair]*Ticker),
Exchange: make(map[string]uuid.UUID),
}
@@ -455,12 +455,7 @@ func TestGetExchangeTickers(t *testing.T) {
_, err = s.getExchangeTickers("test")
assert.ErrorIs(t, err, errExchangeNotFound)
s.Tickers[key.ExchangePairAsset{
Exchange: "test",
Base: currency.XBT.Item,
Quote: currency.DOGE.Item,
Asset: asset.Futures,
}] = &Ticker{
s.Tickers[key.NewExchangeAssetPair("test", asset.Spot, currency.NewPair(currency.XBT, currency.DOGE))] = &Ticker{
Price: Price{
Pair: currency.NewPair(currency.XBT, currency.DOGE),
ExchangeName: "test",

View File

@@ -25,7 +25,7 @@ var (
// Service holds ticker information for each individual exchange
type Service struct {
Tickers map[key.ExchangePairAsset]*Ticker
Tickers map[key.ExchangeAssetPair]*Ticker
Exchange map[string]uuid.UUID
mux *dispatch.Mux
mu sync.Mutex