Skip to content

Commit

Permalink
pkg/exchange: use fixedpoint as value
Browse files Browse the repository at this point in the history
  • Loading branch information
bailantaotao committed Feb 6, 2024
1 parent 54784f8 commit 836f1f9
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
5 changes: 3 additions & 2 deletions pkg/exchange/binance/binanceapi/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/stretchr/testify/assert"

"github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/c9s/bbgo/pkg/testutil"
)

Expand Down Expand Up @@ -206,7 +207,7 @@ func TestClient_NewPlaceMarginOrderRequest(t *testing.T) {

res, err := client.NewPlaceMarginOrderRequest().
Asset("USDT").
Amount("5").
Amount(fixedpoint.NewFromFloat(5)).
IsIsolated(true).
Symbol("BNBUSDT").
SetBorrowRepayType(BorrowRepayTypeBorrow).
Expand All @@ -233,7 +234,7 @@ func TestClient_NewPlaceMarginOrderRequest(t *testing.T) {

res, err = client.NewPlaceMarginOrderRequest().
Asset("USDT").
Amount("5").
Amount(fixedpoint.NewFromFloat(5)).
IsIsolated(true).
Symbol("BNBUSDT").
SetBorrowRepayType(BorrowRepayTypeRepay).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package binanceapi

import (
"github.com/c9s/requestgen"

"github.com/c9s/bbgo/pkg/fixedpoint"
)

//go:generate requestgen -method POST -url "/sapi/v1/margin/borrow-repay" -type PlaceMarginOrderRequest -responseType .TransferResponse
Expand All @@ -16,7 +18,7 @@ type PlaceMarginOrderRequest struct {
// Only for Isolated margin
symbol *string `param:"symbol"`

amount string `param:"amount"`
amount fixedpoint.Value `param:"amount"`

BorrowRepayType BorrowRepayType `param:"type"`
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/exchange/binance/exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ func (e *Exchange) QueryMarginAssetMaxBorrowable(ctx context.Context, asset stri
func (e *Exchange) borrowRepayAsset(ctx context.Context, asset string, amount fixedpoint.Value, marginType binanceapi.BorrowRepayType) error {
req := e.client2.NewPlaceMarginOrderRequest()
req.Asset(asset)
req.Amount(amount.String())
req.Amount(amount)
req.SetBorrowRepayType(marginType)
if e.IsIsolatedMargin {
req.IsIsolated(e.IsIsolatedMargin)
Expand Down

0 comments on commit 836f1f9

Please sign in to comment.