From 060f598a86aa27e8b8103a4070da8fc006545bd4 Mon Sep 17 00:00:00 2001 From: ycdesu Date: Sat, 27 Feb 2021 11:47:21 +0800 Subject: [PATCH 1/4] module: go mod tidy --- go.sum | 6 ------ 1 file changed, 6 deletions(-) diff --git a/go.sum b/go.sum index a653a6d92..7f2248cc0 100644 --- a/go.sum +++ b/go.sum @@ -35,10 +35,6 @@ github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4Yn github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4= github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc h1:biVzkmvwrH8WK8raXaxBx6fRVTlJILwEwQGL1I/ByEI= github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8= -github.com/c9s/rockhopper v1.2.1-0.20210206025705-bbb1e34bd7a9 h1:umJ5T1aKfA6zmHTJffe5axqM9mtr/tscllnX2wnZzBA= -github.com/c9s/rockhopper v1.2.1-0.20210206025705-bbb1e34bd7a9/go.mod h1:KJnQjZSrWA83jjwGF/+O7Y96VCVirYTYEvXJJOc6kMU= -github.com/c9s/rockhopper v1.2.1-0.20210217092450-26684f4e643f h1:iTAG++brwoPvhI22emSTSBS8eeVYP1Vq9OaJUNdWohI= -github.com/c9s/rockhopper v1.2.1-0.20210217092450-26684f4e643f/go.mod h1:KJnQjZSrWA83jjwGF/+O7Y96VCVirYTYEvXJJOc6kMU= github.com/c9s/rockhopper v1.2.1-0.20210217093258-2661955904a9 h1:Wlr5DjDOf5Kygoo0LoUthxwAhNwLEXMWHqCKXbMHCsw= github.com/c9s/rockhopper v1.2.1-0.20210217093258-2661955904a9/go.mod h1:KJnQjZSrWA83jjwGF/+O7Y96VCVirYTYEvXJJOc6kMU= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= @@ -476,8 +472,6 @@ golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c h1:VwygUrnw9jn88c4u8GD3rZQbqrP/tgas88tPUbBxQrk= -golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210217090653-ed5674b6da4a h1:m4knbKtdWq+rPB3TE+ApaRzkETZngkKdhYjvTnnRq4s= golang.org/x/sys v0.0.0-20210217090653-ed5674b6da4a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221 h1:/ZHdbVpdR/jk3g30/d4yUL0JU9kksj8+F/bnQUVLGDM= From 45da7ca1f57f926df142c6aa816ed00b6dbf0b0a Mon Sep 17 00:00:00 2001 From: ycdesu Date: Sat, 27 Feb 2021 17:23:59 +0800 Subject: [PATCH 2/4] cmd: add ftx flags --- pkg/cmd/root.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/cmd/root.go b/pkg/cmd/root.go index 7706030f5..488c1ffa8 100644 --- a/pkg/cmd/root.go +++ b/pkg/cmd/root.go @@ -74,6 +74,10 @@ func init() { RootCmd.PersistentFlags().String("max-api-key", "", "max api key") RootCmd.PersistentFlags().String("max-api-secret", "", "max api secret") + + RootCmd.PersistentFlags().String("ftx-api-key", "", "ftx api key") + RootCmd.PersistentFlags().String("ftx-api-secret", "", "ftx api secret") + RootCmd.PersistentFlags().String("ftx-subaccount-name", "", "subaccount name. Specify it if the credential is for subaccount.") } func Execute() { From c52f918dd4ada9f37515cbcc9b27d2232a58274d Mon Sep 17 00:00:00 2001 From: ycdesu Date: Sat, 27 Feb 2021 17:24:08 +0800 Subject: [PATCH 3/4] ftx: add missing types.exchange methods --- pkg/exchange/ftx/exchange.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pkg/exchange/ftx/exchange.go b/pkg/exchange/ftx/exchange.go index b552ebbac..707e6023e 100644 --- a/pkg/exchange/ftx/exchange.go +++ b/pkg/exchange/ftx/exchange.go @@ -112,3 +112,11 @@ func (e *Exchange) QueryClosedOrders(ctx context.Context, symbol string, since, func (e *Exchange) CancelOrders(ctx context.Context, orders ...types.Order) error { panic("implement me") } + +func (e *Exchange) QueryTicker(ctx context.Context, symbol string) (*types.Ticker, error) { + panic("implement me") +} + +func (e *Exchange) QueryTickers(ctx context.Context, symbol ...string) (map[string]types.Ticker, error) { + panic("implement me") +} From fd5574b0060ef208b5583737b7b881bbab4c317c Mon Sep 17 00:00:00 2001 From: ycdesu Date: Sat, 27 Feb 2021 17:24:59 +0800 Subject: [PATCH 4/4] cmd: add balances testing cmd Only support ftx --- pkg/cmd/balances.go | 56 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 pkg/cmd/balances.go diff --git a/pkg/cmd/balances.go b/pkg/cmd/balances.go new file mode 100644 index 000000000..2ec725192 --- /dev/null +++ b/pkg/cmd/balances.go @@ -0,0 +1,56 @@ +package cmd + +import ( + "context" + "fmt" + + log "github.com/sirupsen/logrus" + "github.com/spf13/cobra" + "github.com/spf13/viper" + + "github.com/c9s/bbgo/pkg/exchange/ftx" + "github.com/c9s/bbgo/pkg/types" +) + +//godotenv -f .env.local go run ./cmd/bbgo balances --session=ftx +var balancesCmd = &cobra.Command{ + Use: "balances", + SilenceUsage: true, + RunE: func(cmd *cobra.Command, args []string) error { + ctx := context.Background() + session, err := cmd.Flags().GetString("session") + if err != nil { + return fmt.Errorf("can't get session from flags: %w", err) + } + ex, err := newExchange(session) + if err != nil { + return err + } + b, err := ex.QueryAccountBalances(ctx) + if err != nil { + return err + } + log.Infof("balances: %+v", b) + + return nil + }, +} + +func init() { + balancesCmd.Flags().String("session", "", "the exchange session name for sync") + + RootCmd.AddCommand(balancesCmd) +} + +func newExchange(session string) (types.Exchange, error) { + switch session { + case "ftx": + return ftx.NewExchange( + viper.GetString("ftx-api-key"), + viper.GetString("ftx-api-secret"), + viper.GetString("ftx-subaccount-name"), + ), nil + + } + return nil, fmt.Errorf("unsupported session %s", session) +}