mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 15:09:42 +00:00
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:
@@ -1918,7 +1918,7 @@ func (s *RPCServer) GetExchangePairs(_ context.Context, r *gctrpc.GetExchangePai
|
||||
return nil, err
|
||||
}
|
||||
if !assetTypes.Contains(a) {
|
||||
return nil, fmt.Errorf("%w %v", asset.ErrNotSupported, a)
|
||||
return nil, fmt.Errorf("%w %q", asset.ErrNotSupported, a)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -117,12 +117,7 @@ func (f fExchange) GetOpenInterest(_ context.Context, k ...key.PairAsset) ([]fut
|
||||
if len(k) > 0 {
|
||||
return []futures.OpenInterest{
|
||||
{
|
||||
Key: key.ExchangePairAsset{
|
||||
Exchange: f.GetName(),
|
||||
Base: k[0].Base,
|
||||
Quote: k[0].Quote,
|
||||
Asset: k[0].Asset,
|
||||
},
|
||||
Key: key.NewExchangeAssetPair(f.GetName(), k[0].Asset, k[0].Pair()),
|
||||
OpenInterest: 1337,
|
||||
},
|
||||
}, nil
|
||||
|
||||
@@ -89,7 +89,7 @@ func SetupSyncManager(c *config.SyncManagerConfig, exchangeManager iExchangeMana
|
||||
fiatDisplayCurrency: c.FiatDisplayCurrency,
|
||||
format: *c.PairFormatDisplay,
|
||||
tickerBatchLastRequested: make(map[key.ExchangeAsset]time.Time),
|
||||
currencyPairs: make(map[key.ExchangePairAsset]*currencyPairSyncAgent),
|
||||
currencyPairs: make(map[key.ExchangeAssetPair]*currencyPairSyncAgent),
|
||||
}
|
||||
|
||||
log.Debugf(log.SyncMgr,
|
||||
@@ -177,12 +177,7 @@ func (m *SyncManager) Start() error {
|
||||
continue
|
||||
}
|
||||
for i := range enabledPairs {
|
||||
k := key.ExchangePairAsset{
|
||||
Asset: assetTypes[y],
|
||||
Exchange: exchangeName,
|
||||
Base: enabledPairs[i].Base.Item,
|
||||
Quote: enabledPairs[i].Quote.Item,
|
||||
}
|
||||
k := key.NewExchangeAssetPair(exchangeName, assetTypes[y], enabledPairs[i])
|
||||
if e := m.get(k); e != nil {
|
||||
continue
|
||||
}
|
||||
@@ -251,14 +246,14 @@ func (m *SyncManager) Stop() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *SyncManager) get(k key.ExchangePairAsset) *currencyPairSyncAgent {
|
||||
func (m *SyncManager) get(k key.ExchangeAssetPair) *currencyPairSyncAgent {
|
||||
m.mux.Lock()
|
||||
defer m.mux.Unlock()
|
||||
|
||||
return m.currencyPairs[k]
|
||||
}
|
||||
|
||||
func newCurrencyPairSyncAgent(k key.ExchangePairAsset) *currencyPairSyncAgent {
|
||||
func newCurrencyPairSyncAgent(k key.ExchangeAssetPair) *currencyPairSyncAgent {
|
||||
return ¤cyPairSyncAgent{
|
||||
Key: k,
|
||||
Pair: currency.NewPair(k.Base.Currency(), k.Quote.Currency()),
|
||||
@@ -268,7 +263,7 @@ func newCurrencyPairSyncAgent(k key.ExchangePairAsset) *currencyPairSyncAgent {
|
||||
}
|
||||
}
|
||||
|
||||
func (m *SyncManager) add(k key.ExchangePairAsset, s syncBase) *currencyPairSyncAgent {
|
||||
func (m *SyncManager) add(k key.ExchangeAssetPair, s syncBase) *currencyPairSyncAgent {
|
||||
m.mux.Lock()
|
||||
defer m.mux.Unlock()
|
||||
|
||||
@@ -335,7 +330,7 @@ func (m *SyncManager) add(k key.ExchangePairAsset, s syncBase) *currencyPairSync
|
||||
}
|
||||
|
||||
if m.currencyPairs == nil {
|
||||
m.currencyPairs = make(map[key.ExchangePairAsset]*currencyPairSyncAgent)
|
||||
m.currencyPairs = make(map[key.ExchangeAssetPair]*currencyPairSyncAgent)
|
||||
}
|
||||
|
||||
m.currencyPairs[k] = c
|
||||
@@ -373,16 +368,10 @@ func (m *SyncManager) WebsocketUpdate(exchangeName string, p currency.Pair, a as
|
||||
return fmt.Errorf("%v %w", syncType, errUnknownSyncItem)
|
||||
}
|
||||
|
||||
k := key.ExchangePairAsset{
|
||||
Asset: a,
|
||||
Exchange: exchangeName,
|
||||
Base: p.Base.Item,
|
||||
Quote: p.Quote.Item,
|
||||
}
|
||||
|
||||
k := key.NewExchangeAssetPair(exchangeName, a, p)
|
||||
c, exists := m.currencyPairs[k]
|
||||
if !exists {
|
||||
return fmt.Errorf("%w for %s %s %s %s %s",
|
||||
return fmt.Errorf("%w for %q %q %q %q %q",
|
||||
errCouldNotSyncNewData,
|
||||
k.Exchange,
|
||||
k.Base,
|
||||
@@ -507,12 +496,7 @@ func (m *SyncManager) worker() {
|
||||
return
|
||||
}
|
||||
|
||||
k := key.ExchangePairAsset{
|
||||
Asset: assetTypes[y],
|
||||
Exchange: exchangeName,
|
||||
Base: enabledPairs[i].Base.Item,
|
||||
Quote: enabledPairs[i].Quote.Item,
|
||||
}
|
||||
k := key.NewExchangeAssetPair(exchangeName, assetTypes[y], enabledPairs[i])
|
||||
c := m.get(k)
|
||||
if c == nil {
|
||||
c = m.add(k, syncBase{
|
||||
|
||||
@@ -258,9 +258,7 @@ func TestSyncManagerWebsocketUpdate(t *testing.T) {
|
||||
err = m.WebsocketUpdate("", currency.EMPTYPAIR, asset.Spot, SyncItemOrderbook, nil)
|
||||
require.ErrorIs(t, err, errCouldNotSyncNewData)
|
||||
|
||||
m.add(key.ExchangePairAsset{
|
||||
Asset: asset.Spot,
|
||||
}, syncBase{})
|
||||
m.add(key.NewExchangeAssetPair("", asset.Spot, currency.EMPTYPAIR), syncBase{})
|
||||
m.initSyncWG.Add(3)
|
||||
// orderbook match
|
||||
err = m.WebsocketUpdate("", currency.EMPTYPAIR, asset.Spot, SyncItemOrderbook, errors.New("test"))
|
||||
|
||||
@@ -20,7 +20,7 @@ type syncBase struct {
|
||||
|
||||
// currencyPairSyncAgent stores the sync agent info
|
||||
type currencyPairSyncAgent struct {
|
||||
Key key.ExchangePairAsset
|
||||
Key key.ExchangeAssetPair
|
||||
Pair currency.Pair
|
||||
Created time.Time
|
||||
trackers []*syncBase
|
||||
@@ -41,7 +41,7 @@ type SyncManager struct {
|
||||
initSyncWG sync.WaitGroup
|
||||
inService sync.WaitGroup
|
||||
|
||||
currencyPairs map[key.ExchangePairAsset]*currencyPairSyncAgent
|
||||
currencyPairs map[key.ExchangeAssetPair]*currencyPairSyncAgent
|
||||
tickerBatchLastRequested map[key.ExchangeAsset]time.Time
|
||||
|
||||
remoteConfig *config.RemoteControlConfig
|
||||
|
||||
Reference in New Issue
Block a user