forked from c9s/bbgo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:c9s/bbgo into feature/302-record-as…
…sets-review
- Loading branch information
Showing
48 changed files
with
3,079 additions
and
286 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
|
||
/.env.local | ||
/.env.*.local | ||
/.env.production | ||
|
||
.DS_Store | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Kucoin command-line tool | ||
|
||
```shell | ||
go run ./examples/kucoin accounts | ||
go run ./examples/kucoin subaccounts | ||
go run ./examples/kucoin symbols | ||
go run ./examples/kucoin tickers | ||
go run ./examples/kucoin tickers BTC-USDT | ||
go run ./examples/kucoin orderbook BTC-USDT 20 | ||
go run ./examples/kucoin orderbook BTC-USDT 100 | ||
|
||
go run ./examples/kucoin orders place --symbol LTC-USDT --price 50 --size 1 --order-type limit --side buy | ||
go run ./examples/kucoin orders --symbol LTC-USDT --status active | ||
go run ./examples/kucoin orders --symbol LTC-USDT --status done | ||
go run ./examples/kucoin orders cancel --order-id 61b48b73b4de3e0001251382 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"strings" | ||
|
||
"github.com/c9s/bbgo/pkg/exchange/kucoin/kucoinapi" | ||
"github.com/joho/godotenv" | ||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
func init() { | ||
rootCmd.PersistentFlags().String("kucoin-api-key", "", "okex api key") | ||
rootCmd.PersistentFlags().String("kucoin-api-secret", "", "okex api secret") | ||
rootCmd.PersistentFlags().String("kucoin-api-passphrase", "", "okex api secret") | ||
} | ||
|
||
var rootCmd = &cobra.Command{ | ||
Use: "kucoin-accounts", | ||
Short: "kucoin accounts", | ||
|
||
// SilenceUsage is an option to silence usage when an error occurs. | ||
SilenceUsage: true, | ||
|
||
RunE: func(cmd *cobra.Command, args []string) error { | ||
accounts, err := client.AccountService.ListAccounts() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
log.Infof("accounts: %+v", accounts) | ||
return nil | ||
}, | ||
} | ||
|
||
var client *kucoinapi.RestClient = nil | ||
|
||
func main() { | ||
if _, err := os.Stat(".env.local"); err == nil { | ||
if err := godotenv.Load(".env.local"); err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
viper.AutomaticEnv() | ||
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_")) | ||
|
||
if err := viper.BindPFlags(rootCmd.PersistentFlags()); err != nil { | ||
log.WithError(err).Error("bind pflags error") | ||
} | ||
|
||
client = kucoinapi.NewClient() | ||
|
||
key, secret, passphrase := viper.GetString("kucoin-api-key"), | ||
viper.GetString("kucoin-api-secret"), | ||
viper.GetString("kucoin-api-passphrase") | ||
|
||
if len(key) == 0 || len(secret) == 0 || len(passphrase) == 0 { | ||
log.Fatal("empty key, secret or passphrase") | ||
} | ||
|
||
client.Auth(key, secret, passphrase) | ||
|
||
if err := rootCmd.ExecuteContext(context.Background()); err != nil { | ||
log.WithError(err).Error("cmd error") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"strings" | ||
|
||
"github.com/c9s/bbgo/pkg/exchange/kucoin/kucoinapi" | ||
"github.com/joho/godotenv" | ||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
func init() { | ||
rootCmd.PersistentFlags().String("kucoin-api-key", "", "okex api key") | ||
rootCmd.PersistentFlags().String("kucoin-api-secret", "", "okex api secret") | ||
rootCmd.PersistentFlags().String("kucoin-api-passphrase", "", "okex api secret") | ||
} | ||
|
||
var rootCmd = &cobra.Command{ | ||
Use: "kucoin-subaccount", | ||
Short: "kucoin subaccount", | ||
|
||
// SilenceUsage is an option to silence usage when an error occurs. | ||
SilenceUsage: true, | ||
|
||
RunE: func(cmd *cobra.Command, args []string) error { | ||
subAccounts, err := client.AccountService.QuerySubAccounts() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
log.Infof("subAccounts: %+v", subAccounts) | ||
return nil | ||
}, | ||
} | ||
|
||
var client *kucoinapi.RestClient = nil | ||
|
||
func main() { | ||
if _, err := os.Stat(".env.local"); err == nil { | ||
if err := godotenv.Load(".env.local"); err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
viper.AutomaticEnv() | ||
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_")) | ||
|
||
if err := viper.BindPFlags(rootCmd.PersistentFlags()); err != nil { | ||
log.WithError(err).Error("bind pflags error") | ||
} | ||
|
||
client = kucoinapi.NewClient() | ||
|
||
key, secret, passphrase := viper.GetString("kucoin-api-key"), | ||
viper.GetString("kucoin-api-secret"), | ||
viper.GetString("kucoin-api-passphrase") | ||
|
||
if len(key) == 0 || len(secret) == 0 || len(passphrase) == 0 { | ||
log.Fatal("empty key, secret or passphrase") | ||
} | ||
|
||
client.Auth(key, secret, passphrase) | ||
|
||
if err := rootCmd.ExecuteContext(context.Background()); err != nil { | ||
log.WithError(err).Error("cmd error") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var accountsCmd = &cobra.Command{ | ||
Use: "accounts", | ||
|
||
// SilenceUsage is an option to silence usage when an error occurs. | ||
SilenceUsage: true, | ||
|
||
RunE: func(cmd *cobra.Command, args []string) error { | ||
if len(args) > 0 { | ||
account, err := client.AccountService.GetAccount(args[0]) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
logrus.Infof("account: %+v", account) | ||
return nil | ||
} | ||
|
||
accounts, err := client.AccountService.ListAccounts() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
logrus.Infof("accounts: %+v", accounts) | ||
return nil | ||
}, | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"strings" | ||
|
||
"github.com/c9s/bbgo/pkg/exchange/kucoin/kucoinapi" | ||
"github.com/joho/godotenv" | ||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
func init() { | ||
rootCmd.PersistentFlags().String("kucoin-api-key", "", "okex api key") | ||
rootCmd.PersistentFlags().String("kucoin-api-secret", "", "okex api secret") | ||
rootCmd.PersistentFlags().String("kucoin-api-passphrase", "", "okex api secret") | ||
|
||
rootCmd.AddCommand(accountsCmd) | ||
rootCmd.AddCommand(subAccountsCmd) | ||
rootCmd.AddCommand(symbolsCmd) | ||
rootCmd.AddCommand(tickersCmd) | ||
rootCmd.AddCommand(orderbookCmd) | ||
} | ||
|
||
var rootCmd = &cobra.Command{ | ||
Use: "kucoin", | ||
Short: "kucoin", | ||
|
||
// SilenceUsage is an option to silence usage when an error occurs. | ||
SilenceUsage: true, | ||
|
||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return nil | ||
}, | ||
} | ||
|
||
var client *kucoinapi.RestClient = nil | ||
|
||
func main() { | ||
if _, err := os.Stat(".env.local"); err == nil { | ||
if err := godotenv.Load(".env.local"); err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
viper.AutomaticEnv() | ||
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_")) | ||
|
||
if err := viper.BindPFlags(rootCmd.PersistentFlags()); err != nil { | ||
log.WithError(err).Error("bind pflags error") | ||
} | ||
|
||
client = kucoinapi.NewClient() | ||
|
||
key, secret, passphrase := viper.GetString("kucoin-api-key"), | ||
viper.GetString("kucoin-api-secret"), | ||
viper.GetString("kucoin-api-passphrase") | ||
|
||
if len(key) == 0 || len(secret) == 0 || len(passphrase) == 0 { | ||
log.Fatal("empty key, secret or passphrase") | ||
} | ||
|
||
client.Auth(key, secret, passphrase) | ||
|
||
if err := rootCmd.ExecuteContext(context.Background()); err != nil { | ||
log.WithError(err).Error("cmd error") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package main | ||
|
||
import ( | ||
"strconv" | ||
|
||
"github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var orderbookCmd = &cobra.Command{ | ||
Use: "orderbook", | ||
|
||
// SilenceUsage is an option to silence usage when an error occurs. | ||
SilenceUsage: true, | ||
|
||
Args: cobra.MinimumNArgs(1), | ||
|
||
RunE: func(cmd *cobra.Command, args []string) error { | ||
if len(args) == 0 { | ||
return nil | ||
} | ||
|
||
var depth = 0 | ||
if len(args) > 1 { | ||
v, err := strconv.Atoi(args[1]) | ||
if err != nil { | ||
return err | ||
} | ||
depth = v | ||
} | ||
|
||
orderBook, err := client.MarketDataService.GetOrderBook(args[0], depth) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
logrus.Infof("orderBook: %+v", orderBook) | ||
return nil | ||
}, | ||
} |
Oops, something went wrong.