mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-08 15:11:07 +00:00
orderbook/buffer: data integrity and resubscription pass (#910)
* orderbook/buffer: data integrity and resubscription pass * btcmarkets: REMOVE THAT LIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIINE!!!!!!!!!!!!!!!!! * buffer: reinstate publish, refaactor, invalidate more and comments * buffer/orderbook: improve update and snapshot performance. Move Update type to orderbook package to util. pointer through entire function calls. (cleanup). Change action string to uint8 for easier comparison. Add parsing helper. Update current test benchmark comments. * dispatch: change publish func to variadic id param * dispatch: remove sender receiver wait time as this adds overhead and complexity. update tests. * dispatch: don't create pointers for every job container * rpcserver: fix assertion issues with data publishing change * linter: fixes * glorious: nits addr * depth: change validation handling to incorporate and store err * linter: fix more issues * dispatch: fix race * travis: update before fetching * depth: wrap and return wrapped error in invalidate call and fix tests * btcmarkets: fix commenting * workflow: check * workflow: check * orderbook: check error * buffer/depth: return invalidation error and fix tests * gctcli: display errors on orderbook streams * buffer: remove unused types * orderbook/bitmex: shift function to bitmex * orderbook: Add specific comments to unexported functions that don't have locking require locking. * orderbook: restrict published data functionality to orderbook.Outbound interface * common: add assertion failure helper for error * dispatch: remove atomics, add mutex protection, remove add/remove worker, redo main tests * dispatch: export function * engine: revert and change sub logger to manager * engine: remove old test * dispatch: add common variable ;) * btcmarket: don't overflow int in tests on 32bit systems * ci: force 1.17.7 usage for go * Revert "ci: force 1.17.7 usage for go" This reverts commit af2f95563bf218cf2b9f36a9fcf3258e2c6a2d91. * golangci: bump version add and remove linter items * Revert "golangci: bump version add and remove linter items" This reverts commit 3c98bffc9d030e39faca0387ea40c151df2ab06b. * dispatch: remove unsused mutex from mux * order: slight optimizations * nits: glorious * dispatch: fix regression on uuid generation and input inline with master * linter: fix * linter: fix * glorious: nit - rm slice segration * account: fix test after merge * coinbasepro: revert change * account: close channel instead of needing a receiver, push alert in routine to prepare for waiter. Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io>
This commit is contained in:
@@ -563,10 +563,12 @@ var stringsToOrderSide = []struct {
|
||||
{"ask", Ask, nil},
|
||||
{"ASK", Ask, nil},
|
||||
{"aSk", Ask, nil},
|
||||
{"lOnG", Long, nil},
|
||||
{"ShoRt", Short, nil},
|
||||
{"any", AnySide, nil},
|
||||
{"ANY", AnySide, nil},
|
||||
{"aNy", AnySide, nil},
|
||||
{"woahMan", Buy, errors.New("woahMan not recognised as order side")},
|
||||
{"woahMan", Buy, errors.New("WOAHMAN not recognised as order side")},
|
||||
}
|
||||
|
||||
func TestStringToOrderSide(t *testing.T) {
|
||||
@@ -585,6 +587,16 @@ func TestStringToOrderSide(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
var sideBenchmark Side
|
||||
|
||||
// 9756914 126.7 ns/op 0 B/op 0 allocs/op // PREV
|
||||
// 25200660 57.63 ns/op 3 B/op 1 allocs/op // CURRENT
|
||||
func BenchmarkStringToOrderSide(b *testing.B) {
|
||||
for x := 0; x < b.N; x++ {
|
||||
sideBenchmark, _ = StringToOrderSide("any")
|
||||
}
|
||||
}
|
||||
|
||||
var stringsToOrderType = []struct {
|
||||
in string
|
||||
out Type
|
||||
@@ -619,7 +631,7 @@ var stringsToOrderType = []struct {
|
||||
{"trigger", Trigger, nil},
|
||||
{"TRIGGER", Trigger, nil},
|
||||
{"tRiGgEr", Trigger, nil},
|
||||
{"woahMan", UnknownType, errors.New("woahMan not recognised as order type")},
|
||||
{"woahMan", UnknownType, errors.New("WOAHMAN not recognised as order type")},
|
||||
}
|
||||
|
||||
func TestStringToOrderType(t *testing.T) {
|
||||
@@ -638,6 +650,16 @@ func TestStringToOrderType(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
var typeBenchmark Type
|
||||
|
||||
// 5703705 299.9 ns/op 0 B/op 0 allocs/op // PREV
|
||||
// 16353608 81.23 ns/op 8 B/op 1 allocs/op // CURRENT
|
||||
func BenchmarkStringToOrderType(b *testing.B) {
|
||||
for x := 0; x < b.N; x++ {
|
||||
typeBenchmark, _ = StringToOrderType("trigger")
|
||||
}
|
||||
}
|
||||
|
||||
var stringsToOrderStatus = []struct {
|
||||
in string
|
||||
out Status
|
||||
@@ -682,7 +704,8 @@ var stringsToOrderStatus = []struct {
|
||||
{"PARTIALLY_CANCELLEd", PartiallyCancelled, nil},
|
||||
{"partially canceLLed", PartiallyCancelled, nil},
|
||||
{"opeN", Open, nil},
|
||||
{"woahMan", UnknownStatus, errors.New("woahMan not recognised as order status")},
|
||||
{"cLosEd", Closed, nil},
|
||||
{"woahMan", UnknownStatus, errors.New("WOAHMAN not recognised as order status")},
|
||||
}
|
||||
|
||||
func TestStringToOrderStatus(t *testing.T) {
|
||||
@@ -701,6 +724,16 @@ func TestStringToOrderStatus(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
var statusBenchmark Status
|
||||
|
||||
// 3569052 351.8 ns/op 0 B/op 0 allocs/op // PREV
|
||||
// 11126791 101.9 ns/op 24 B/op 1 allocs/op // CURRENT
|
||||
func BenchmarkStringToOrderStatus(b *testing.B) {
|
||||
for x := 0; x < b.N; x++ {
|
||||
statusBenchmark, _ = StringToOrderStatus("market_unavailable")
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdateOrderFromModify(t *testing.T) {
|
||||
var leet = "1337"
|
||||
od := Detail{
|
||||
|
||||
@@ -734,20 +734,21 @@ func SortOrdersBySide(orders *[]Detail, reverse bool) {
|
||||
// StringToOrderSide for converting case insensitive order side
|
||||
// and returning a real Side
|
||||
func StringToOrderSide(side string) (Side, error) {
|
||||
switch {
|
||||
case strings.EqualFold(side, Buy.String()):
|
||||
side = strings.ToUpper(side)
|
||||
switch Side(side) {
|
||||
case Buy:
|
||||
return Buy, nil
|
||||
case strings.EqualFold(side, Sell.String()):
|
||||
case Sell:
|
||||
return Sell, nil
|
||||
case strings.EqualFold(side, Bid.String()):
|
||||
case Bid:
|
||||
return Bid, nil
|
||||
case strings.EqualFold(side, Ask.String()):
|
||||
case Ask:
|
||||
return Ask, nil
|
||||
case strings.EqualFold(side, Long.String()):
|
||||
case Long:
|
||||
return Long, nil
|
||||
case strings.EqualFold(side, Short.String()):
|
||||
case Short:
|
||||
return Short, nil
|
||||
case strings.EqualFold(side, AnySide.String()):
|
||||
case AnySide:
|
||||
return AnySide, nil
|
||||
default:
|
||||
return UnknownSide, errors.New(side + " not recognised as order side")
|
||||
@@ -757,40 +758,29 @@ func StringToOrderSide(side string) (Side, error) {
|
||||
// StringToOrderType for converting case insensitive order type
|
||||
// and returning a real Type
|
||||
func StringToOrderType(oType string) (Type, error) {
|
||||
switch {
|
||||
case strings.EqualFold(oType, Limit.String()),
|
||||
strings.EqualFold(oType, "EXCHANGE LIMIT"):
|
||||
oType = strings.ToUpper(oType)
|
||||
switch oType {
|
||||
case Limit.String(), "EXCHANGE LIMIT":
|
||||
return Limit, nil
|
||||
case strings.EqualFold(oType, Market.String()),
|
||||
strings.EqualFold(oType, "EXCHANGE MARKET"):
|
||||
case Market.String(), "EXCHANGE MARKET":
|
||||
return Market, nil
|
||||
case strings.EqualFold(oType, ImmediateOrCancel.String()),
|
||||
strings.EqualFold(oType, "immediate or cancel"),
|
||||
strings.EqualFold(oType, "IOC"),
|
||||
strings.EqualFold(oType, "EXCHANGE IOC"):
|
||||
case ImmediateOrCancel.String(), "IMMEDIATE OR CANCEL", "IOC", "EXCHANGE IOC":
|
||||
return ImmediateOrCancel, nil
|
||||
case strings.EqualFold(oType, Stop.String()),
|
||||
strings.EqualFold(oType, "stop loss"),
|
||||
strings.EqualFold(oType, "stop_loss"),
|
||||
strings.EqualFold(oType, "EXCHANGE STOP"):
|
||||
case Stop.String(), "STOP LOSS", "STOP_LOSS", "EXCHANGE STOP":
|
||||
return Stop, nil
|
||||
case strings.EqualFold(oType, StopLimit.String()),
|
||||
strings.EqualFold(oType, "EXCHANGE STOP LIMIT"):
|
||||
case StopLimit.String(), "EXCHANGE STOP LIMIT":
|
||||
return StopLimit, nil
|
||||
case strings.EqualFold(oType, TrailingStop.String()),
|
||||
strings.EqualFold(oType, "trailing stop"),
|
||||
strings.EqualFold(oType, "EXCHANGE TRAILING STOP"):
|
||||
case TrailingStop.String(), "TRAILING STOP", "EXCHANGE TRAILING STOP":
|
||||
return TrailingStop, nil
|
||||
case strings.EqualFold(oType, FillOrKill.String()),
|
||||
strings.EqualFold(oType, "EXCHANGE FOK"):
|
||||
case FillOrKill.String(), "EXCHANGE FOK":
|
||||
return FillOrKill, nil
|
||||
case strings.EqualFold(oType, IOS.String()):
|
||||
case IOS.String():
|
||||
return IOS, nil
|
||||
case strings.EqualFold(oType, PostOnly.String()):
|
||||
case PostOnly.String():
|
||||
return PostOnly, nil
|
||||
case strings.EqualFold(oType, AnyType.String()):
|
||||
case AnyType.String():
|
||||
return AnyType, nil
|
||||
case strings.EqualFold(oType, Trigger.String()):
|
||||
case Trigger.String():
|
||||
return Trigger, nil
|
||||
default:
|
||||
return UnknownType, errors.New(oType + " not recognised as order type")
|
||||
@@ -800,49 +790,37 @@ func StringToOrderType(oType string) (Type, error) {
|
||||
// StringToOrderStatus for converting case insensitive order status
|
||||
// and returning a real Status
|
||||
func StringToOrderStatus(status string) (Status, error) {
|
||||
switch {
|
||||
case strings.EqualFold(status, AnyStatus.String()):
|
||||
status = strings.ToUpper(status)
|
||||
switch status {
|
||||
case AnyStatus.String():
|
||||
return AnyStatus, nil
|
||||
case strings.EqualFold(status, New.String()),
|
||||
strings.EqualFold(status, "placed"):
|
||||
case New.String(), "PLACED":
|
||||
return New, nil
|
||||
case strings.EqualFold(status, Active.String()),
|
||||
strings.EqualFold(status, "STATUS_ACTIVE"): // BTSE case
|
||||
case Active.String(), "STATUS_ACTIVE":
|
||||
return Active, nil
|
||||
case strings.EqualFold(status, PartiallyFilled.String()),
|
||||
strings.EqualFold(status, "partially matched"),
|
||||
strings.EqualFold(status, "partially filled"):
|
||||
case PartiallyFilled.String(), "PARTIALLY MATCHED", "PARTIALLY FILLED":
|
||||
return PartiallyFilled, nil
|
||||
case strings.EqualFold(status, Filled.String()),
|
||||
strings.EqualFold(status, "fully matched"),
|
||||
strings.EqualFold(status, "fully filled"),
|
||||
strings.EqualFold(status, "ORDER_FULLY_TRANSACTED"): // BTSE case
|
||||
case Filled.String(), "FULLY MATCHED", "FULLY FILLED", "ORDER_FULLY_TRANSACTED":
|
||||
return Filled, nil
|
||||
case strings.EqualFold(status, PartiallyCancelled.String()),
|
||||
strings.EqualFold(status, "partially cancelled"),
|
||||
strings.EqualFold(status, "ORDER_PARTIALLY_TRANSACTED"): // BTSE case
|
||||
case PartiallyCancelled.String(), "PARTIALLY CANCELLED", "ORDER_PARTIALLY_TRANSACTED":
|
||||
return PartiallyCancelled, nil
|
||||
case strings.EqualFold(status, Open.String()):
|
||||
case Open.String():
|
||||
return Open, nil
|
||||
case strings.EqualFold(status, Closed.String()):
|
||||
case Closed.String():
|
||||
return Closed, nil
|
||||
case strings.EqualFold(status, Cancelled.String()),
|
||||
strings.EqualFold(status, "CANCELED"), // Binance and Kraken case
|
||||
strings.EqualFold(status, "ORDER_CANCELLED"): // BTSE case
|
||||
case Cancelled.String(), "CANCELED", "ORDER_CANCELLED":
|
||||
return Cancelled, nil
|
||||
case strings.EqualFold(status, PendingCancel.String()),
|
||||
strings.EqualFold(status, "pending cancel"),
|
||||
strings.EqualFold(status, "pending cancellation"):
|
||||
case PendingCancel.String(), "PENDING CANCEL", "PENDING CANCELLATION":
|
||||
return PendingCancel, nil
|
||||
case strings.EqualFold(status, Rejected.String()):
|
||||
case Rejected.String():
|
||||
return Rejected, nil
|
||||
case strings.EqualFold(status, Expired.String()):
|
||||
case Expired.String():
|
||||
return Expired, nil
|
||||
case strings.EqualFold(status, Hidden.String()):
|
||||
case Hidden.String():
|
||||
return Hidden, nil
|
||||
case strings.EqualFold(status, InsufficientBalance.String()):
|
||||
case InsufficientBalance.String():
|
||||
return InsufficientBalance, nil
|
||||
case strings.EqualFold(status, MarketUnavailable.String()):
|
||||
case MarketUnavailable.String():
|
||||
return MarketUnavailable, nil
|
||||
default:
|
||||
return UnknownStatus, errors.New(status + " not recognised as order status")
|
||||
|
||||
Reference in New Issue
Block a user