Skip to content

Commit

Permalink
feat(download): include flag to futures market (#250)
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigo-brito authored Apr 1, 2023
1 parent e6f2747 commit 2c7b579
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
28 changes: 25 additions & 3 deletions cmd/ninjabot/ninjabot.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/rodrigo-brito/ninjabot/download"
"github.com/rodrigo-brito/ninjabot/exchange"
"github.com/rodrigo-brito/ninjabot/service"

"github.com/urfave/cli/v2"
)
Expand Down Expand Up @@ -59,11 +60,32 @@ func main() {
Usage: "eg. ./btc.csv",
Required: true,
},
&cli.BoolFlag{
Name: "futures",
Aliases: []string{"f"},
Usage: "true or false",
Value: false,
Required: false,
},
},
Action: func(c *cli.Context) error {
exc, err := exchange.NewBinance(c.Context)
if err != nil {
return err
var (
exc service.Feeder
err error
)

if c.Bool("futures") {
// fetch data from binance futures
exc, err = exchange.NewBinanceFuture(c.Context)
if err != nil {
return err
}
} else {
// fetch data from binance spot
exc, err = exchange.NewBinance(c.Context)
if err != nil {
return err
}
}

var options []download.Option
Expand Down
4 changes: 2 additions & 2 deletions download/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import (
const batchSize = 500

type Downloader struct {
exchange service.Exchange
exchange service.Feeder
}

func NewDownloader(exchange service.Exchange) Downloader {
func NewDownloader(exchange service.Feeder) Downloader {
return Downloader{
exchange: exchange,
}
Expand Down
1 change: 0 additions & 1 deletion download/download_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ func TestDownloader_download(t *testing.T) {
require.NoError(t, err)

fakeExchange := struct {
service.Broker
service.Feeder
}{
Feeder: csvFeed,
Expand Down
2 changes: 1 addition & 1 deletion exchange/binance_future.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func NewBinanceFuture(ctx context.Context, options ...BinanceFutureOption) (*Bin
exchange.assetsInfo[info.Symbol] = tradeLimits
}

log.Info("[SETUP] Using Binance exchange")
log.Info("[SETUP] Using Binance Futures exchange")

return exchange, nil
}
Expand Down

0 comments on commit 2c7b579

Please sign in to comment.