Skip to content

Commit 2c7b579

Browse files
feat(download): include flag to futures market (#250)
1 parent e6f2747 commit 2c7b579

File tree

4 files changed

+28
-7
lines changed

4 files changed

+28
-7
lines changed

cmd/ninjabot/ninjabot.go

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/rodrigo-brito/ninjabot/download"
88
"github.com/rodrigo-brito/ninjabot/exchange"
9+
"github.com/rodrigo-brito/ninjabot/service"
910

1011
"github.com/urfave/cli/v2"
1112
)
@@ -59,11 +60,32 @@ func main() {
5960
Usage: "eg. ./btc.csv",
6061
Required: true,
6162
},
63+
&cli.BoolFlag{
64+
Name: "futures",
65+
Aliases: []string{"f"},
66+
Usage: "true or false",
67+
Value: false,
68+
Required: false,
69+
},
6270
},
6371
Action: func(c *cli.Context) error {
64-
exc, err := exchange.NewBinance(c.Context)
65-
if err != nil {
66-
return err
72+
var (
73+
exc service.Feeder
74+
err error
75+
)
76+
77+
if c.Bool("futures") {
78+
// fetch data from binance futures
79+
exc, err = exchange.NewBinanceFuture(c.Context)
80+
if err != nil {
81+
return err
82+
}
83+
} else {
84+
// fetch data from binance spot
85+
exc, err = exchange.NewBinance(c.Context)
86+
if err != nil {
87+
return err
88+
}
6789
}
6890

6991
var options []download.Option

download/download.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ import (
1616
const batchSize = 500
1717

1818
type Downloader struct {
19-
exchange service.Exchange
19+
exchange service.Feeder
2020
}
2121

22-
func NewDownloader(exchange service.Exchange) Downloader {
22+
func NewDownloader(exchange service.Feeder) Downloader {
2323
return Downloader{
2424
exchange: exchange,
2525
}

download/download_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ func TestDownloader_download(t *testing.T) {
7676
require.NoError(t, err)
7777

7878
fakeExchange := struct {
79-
service.Broker
8079
service.Feeder
8180
}{
8281
Feeder: csvFeed,

exchange/binance_future.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ func NewBinanceFuture(ctx context.Context, options ...BinanceFutureOption) (*Bin
134134
exchange.assetsInfo[info.Symbol] = tradeLimits
135135
}
136136

137-
log.Info("[SETUP] Using Binance exchange")
137+
log.Info("[SETUP] Using Binance Futures exchange")
138138

139139
return exchange, nil
140140
}

0 commit comments

Comments
 (0)