Skip to content

Commit

Permalink
Merge branch 'main' of github.com:c9s/bbgo into feature/302-record-as…
Browse files Browse the repository at this point in the history
…sets-review
  • Loading branch information
TonyQ committed Dec 14, 2021
2 parents aadd2a8 + ef8967d commit 28aad2f
Show file tree
Hide file tree
Showing 48 changed files with 3,079 additions and 286 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

/.env.local
/.env.*.local
/.env.production

.DS_Store

Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,12 @@ for lorca
make embed && go run -tags web ./cmd/bbgo-lorca
```

## FAQ

What's Position?

- Base Currency & Quote Currency <https://www.ig.com/au/glossary-trading-terms/base-currency-definition>
- How to calculate average cost? <https://www.janushenderson.com/en-us/investor/planning/calculate-average-cost/>

## Contributing

Expand Down
8 changes: 0 additions & 8 deletions config/pricealert-tg.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
---
notifications:
# object routing rules
routing:
trade: "$symbol"
order: "$symbol"
submitOrder: "$session" # not supported yet
pnL: "bbgo-pnl"

sessions:
binance:
exchange: binance
Expand Down
11 changes: 0 additions & 11 deletions doc/configuration/telegram.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,6 @@ TELEGRAM_BOT_AUTH_TOKEN=itsme55667788
The alerting strategies use Telegram bot notification without further configuration. You can check the [pricealert
yaml file](../../config/pricealert-tg.yaml) in the `config/` directory for example.

If you want the order submitting/filling notification, add the following to your `bbgo.yaml`:

```yaml
notifications:
routing:
trade: "$symbol"
order: "$symbol"
submitOrder: "$session"
pnL: "bbgo-pnl"
```
Run your bbgo.

Open your Telegram app, search your bot `bbgo_bot_711222333`
Expand Down
16 changes: 16 additions & 0 deletions doc/development/kucoin-cli.md
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
```
70 changes: 70 additions & 0 deletions examples/kucoin-accounts/main.go
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")
}
}
70 changes: 70 additions & 0 deletions examples/kucoin-subaccount/main.go
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")
}
}
34 changes: 34 additions & 0 deletions examples/kucoin/accounts.go
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
},
}

70 changes: 70 additions & 0 deletions examples/kucoin/main.go
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")
}
}
40 changes: 40 additions & 0 deletions examples/kucoin/orderbook.go
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
},
}
Loading

0 comments on commit 28aad2f

Please sign in to comment.