Exchanges: Bypass websocket book validation (#613)

* Exchanges: Bypass websocket book validation on exchanges when checksum is implemented, fix FTX test, go mod tidy

* Orderbook: Change orderbook base field name
This commit is contained in:
Ryan O'Hara-Reid
2021-01-05 15:55:46 +11:00
committed by GitHub
parent eb0571cc9b
commit 010fab02ca
8 changed files with 28 additions and 18 deletions

View File

@@ -966,6 +966,7 @@ func (b *Bitfinex) WsInsertSnapshot(p currency.Pair, assetType asset.Item, books
book.Pair = p
book.ExchangeName = b.Name
book.NotAggregated = true
book.HasChecksumValidation = true
book.IsFundingRate = fundingRate
return b.Websocket.Orderbook.LoadSnapshot(&book)
}

View File

@@ -25,7 +25,7 @@ const (
apiSecret = ""
canManipulateRealOrders = false
spotPair = "FTT/BTC"
futuresPair = "LEO-0327"
futuresPair = "DOGE-PERP"
testToken = "ADAMOON"
btcusd = "BTC/USD"
)

View File

@@ -506,12 +506,13 @@ func (f *FTX) WsProcessPartialOB(data *WsOrderbookData, p currency.Pair, a asset
}
newOrderBook := orderbook.Base{
Asks: asks,
Bids: bids,
AssetType: a,
LastUpdated: timestampFromFloat64(data.Time),
Pair: p,
ExchangeName: f.Name,
Asks: asks,
Bids: bids,
AssetType: a,
LastUpdated: timestampFromFloat64(data.Time),
Pair: p,
ExchangeName: f.Name,
HasChecksumValidation: true,
}
return f.Websocket.Orderbook.LoadSnapshot(&newOrderBook)
}

View File

@@ -847,6 +847,7 @@ func (k *Kraken) wsProcessOrderBookPartial(channelData *WebsocketChannelData, as
}
base.LastUpdated = highestLastUpdate
base.ExchangeName = k.Name
base.HasChecksumValidation = true
return k.Websocket.Orderbook.LoadSnapshot(&base)
}

View File

@@ -678,12 +678,13 @@ func (o *OKGroup) WsProcessPartialOrderBook(wsEventData *WebsocketOrderBook, ins
}
newOrderBook := orderbook.Base{
Asks: asks,
Bids: bids,
AssetType: a,
LastUpdated: wsEventData.Timestamp,
Pair: instrument,
ExchangeName: o.Name,
Asks: asks,
Bids: bids,
AssetType: a,
LastUpdated: wsEventData.Timestamp,
Pair: instrument,
ExchangeName: o.Name,
HasChecksumValidation: true,
}
return o.Websocket.Orderbook.LoadSnapshot(&newOrderBook)
}

View File

@@ -275,9 +275,11 @@ func (b *Base) Process() error {
b.LastUpdated = time.Now()
}
err := b.Verify()
if err != nil {
return err
if !b.HasChecksumValidation {
err := b.Verify()
if err != nil {
return err
}
}
return service.Update(b)

View File

@@ -79,10 +79,15 @@ type Base struct {
LastUpdateID int64 `json:"lastUpdateId"`
AssetType asset.Item `json:"assetType"`
ExchangeName string `json:"exchangeName"`
// NotAggregated defines whether an orderbook can contain duplicate prices
// in a payload
NotAggregated bool `json:"-"`
IsFundingRate bool `json:"fundingRate"`
// HasChecksumValidation defines an allowance to bypass internal
// verification if the book has been verified by checksum.
HasChecksumValidation bool `json:"-"`
}
type byOBPrice []Item

3
go.sum
View File

@@ -116,8 +116,7 @@ github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V
github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/gofrs/uuid v3.3.0+incompatible h1:8K4tyRfvU1CYPgJsveYFQMhpFd/wXNM7iK6rR7UHz84=
github.com/gofrs/uuid v3.3.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/gofrs/uuid v3.4.0+incompatible h1:d3y9DuA2LnGr8hiQ+1dPQrNsydLvutmRq9cjULPWYZQ=
github.com/gofrs/uuid v3.4.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/gogo/protobuf v1.2.1 h1:/s5zKNz0uPFCZ5hddgPdo2TK2TVrUNMn0OOX8/aZMTE=