exchanges/refactor: Use strings.Builder for string construction (#2046)

* refactor: use strings.builder

Signed-off-by: keeghcet <keeghcet@outlook.com>

* Apply suggestion from @shazbert

Co-authored-by: Ryan O'Hara-Reid <oharareid.ryan@gmail.com>

---------

Signed-off-by: keeghcet <keeghcet@outlook.com>
Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io>
Co-authored-by: Ryan O'Hara-Reid <oharareid.ryan@gmail.com>
This commit is contained in:
keeghcet
2025-09-10 19:03:03 +08:00
committed by GitHub
parent 16f543666f
commit 560b22e2ba
2 changed files with 7 additions and 6 deletions

View File

@@ -425,11 +425,12 @@ func orderbookChecksum(ob *orderbook.Book) uint32 {
// concatOrderbookLiquidity concatenates price and amounts together for checksum processing
func concatOrderbookLiquidity(liquidity orderbook.Levels) string {
var c string
var c strings.Builder
for x := range min(10, len(liquidity)) {
c += trim(liquidity[x].Price) + trim(liquidity[x].Amount)
c.WriteString(trim(liquidity[x].Price))
c.WriteString(trim(liquidity[x].Amount))
}
return c
return c.String()
}
// trim turns value into string, removes the decimal point and all the leading zeros

View File

@@ -2593,16 +2593,16 @@ func (e *Exchange) SendAuthHTTPRequestV5(ctx context.Context, ePath exchange.URL
return fmt.Errorf("%w code: %d message: %s", request.ErrAuthRequestFailed, response.RetCode, response.RetMsg)
}
if len(response.RetExtInfo.List) > 0 && response.RetCode != 0 {
var errMessage string
var errMessage strings.Builder
var failed bool
for i := range response.RetExtInfo.List {
if response.RetExtInfo.List[i].Code != 0 {
failed = true
errMessage += fmt.Sprintf("code: %d message: %s ", response.RetExtInfo.List[i].Code, response.RetExtInfo.List[i].Message)
errMessage.WriteString(fmt.Sprintf("code: %d message: %s ", response.RetExtInfo.List[i].Code, response.RetExtInfo.List[i].Message))
}
}
if failed {
return fmt.Errorf("%w %s", request.ErrAuthRequestFailed, errMessage)
return fmt.Errorf("%w %s", request.ErrAuthRequestFailed, errMessage.String())
}
}
return err