From 68064bfe4493dbbe891753b3eb90ed77bc96d697 Mon Sep 17 00:00:00 2001 From: c9s Date: Wed, 24 Aug 2022 12:58:06 +0800 Subject: [PATCH] move and fix binance exchange api examples --- examples/{ => exchange-api}/binance-book/main.go | 0 examples/{ => exchange-api}/binance-margin/main.go | 7 ++++--- pkg/exchange/binance/exchange.go | 8 ++++---- 3 files changed, 8 insertions(+), 7 deletions(-) rename examples/{ => exchange-api}/binance-book/main.go (100%) rename examples/{ => exchange-api}/binance-margin/main.go (93%) diff --git a/examples/binance-book/main.go b/examples/exchange-api/binance-book/main.go similarity index 100% rename from examples/binance-book/main.go rename to examples/exchange-api/binance-book/main.go diff --git a/examples/binance-margin/main.go b/examples/exchange-api/binance-margin/main.go similarity index 93% rename from examples/binance-margin/main.go rename to examples/exchange-api/binance-margin/main.go index dafaba331..1b06efa19 100644 --- a/examples/binance-margin/main.go +++ b/examples/exchange-api/binance-margin/main.go @@ -14,6 +14,7 @@ import ( "github.com/c9s/bbgo/pkg/cmd/cmdutil" "github.com/c9s/bbgo/pkg/exchange/binance" + "github.com/c9s/bbgo/pkg/fixedpoint" "github.com/c9s/bbgo/pkg/types" ) @@ -70,7 +71,7 @@ var rootCmd = &cobra.Command{ return fmt.Errorf("market %s is not defined", symbol) } - marginAccount, err := exchange.QueryMarginAccount(ctx) + marginAccount, err := exchange.QueryCrossMarginAccount(ctx) if err != nil { return err } @@ -98,8 +99,8 @@ var rootCmd = &cobra.Command{ Market: market, Side: types.SideTypeBuy, Type: types.OrderTypeLimit, - Price: price, - Quantity: quantity, + Price: fixedpoint.NewFromFloat(price), + Quantity: fixedpoint.NewFromFloat(quantity), MarginSideEffect: types.SideEffectTypeMarginBuy, TimeInForce: "GTC", }) diff --git a/pkg/exchange/binance/exchange.go b/pkg/exchange/binance/exchange.go index 27a910669..c6ef35577 100644 --- a/pkg/exchange/binance/exchange.go +++ b/pkg/exchange/binance/exchange.go @@ -374,7 +374,7 @@ func (e *Exchange) transferCrossMarginAccountAsset(ctx context.Context, asset st return err } -func (e *Exchange) queryCrossMarginAccount(ctx context.Context) (*types.Account, error) { +func (e *Exchange) QueryCrossMarginAccount(ctx context.Context) (*types.Account, error) { marginAccount, err := e.client.NewGetMarginAccountService().Do(ctx) if err != nil { return nil, err @@ -406,7 +406,7 @@ func (e *Exchange) queryCrossMarginAccount(ctx context.Context) (*types.Account, return a, nil } -func (e *Exchange) queryIsolatedMarginAccount(ctx context.Context) (*types.Account, error) { +func (e *Exchange) QueryIsolatedMarginAccount(ctx context.Context) (*types.Account, error) { req := e.client.NewGetIsolatedMarginAccountService() req.Symbols(e.IsolatedMarginSymbol) @@ -677,9 +677,9 @@ func (e *Exchange) QueryAccount(ctx context.Context) (*types.Account, error) { if e.IsFutures { account, err = e.QueryFuturesAccount(ctx) } else if e.IsIsolatedMargin { - account, err = e.queryIsolatedMarginAccount(ctx) + account, err = e.QueryIsolatedMarginAccount(ctx) } else if e.IsMargin { - account, err = e.queryCrossMarginAccount(ctx) + account, err = e.QueryCrossMarginAccount(ctx) } else { account, err = e.QuerySpotAccount(ctx) }