forked from c9s/bbgo
/
deposit.go
70 lines (59 loc) · 1.76 KB
/
deposit.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package cmd
import (
"context"
"fmt"
"time"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/c9s/bbgo/pkg/bbgo"
"github.com/c9s/bbgo/pkg/types"
)
func init() {
depositsCmd.Flags().String("session", "", "the exchange session name for querying balances")
depositsCmd.Flags().String("asset", "", "the trading pair, like btcusdt")
RootCmd.AddCommand(depositsCmd)
}
// go run ./cmd/bbgo deposits --session=ftx --asset="BTC"
// This is a testing util and will query deposits in last 7 days.
var depositsCmd = &cobra.Command{
Use: "deposits",
Short: "A testing utility that will query deposition history in last 7 days",
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
ctx := context.Background()
environ := bbgo.NewEnvironment()
if err := environ.ConfigureExchangeSessions(userConfig); err != nil {
return err
}
sessionName, err := cmd.Flags().GetString("session")
if err != nil {
return err
}
session, ok := environ.Session(sessionName)
if !ok {
return fmt.Errorf("session %s not found", sessionName)
}
asset, err := cmd.Flags().GetString("asset")
if err != nil {
return fmt.Errorf("can't get the asset from flags: %w", err)
}
if asset == "" {
return fmt.Errorf("asset is not found")
}
until := time.Now()
since := until.Add(-7 * 24 * time.Hour)
exchange, ok := session.Exchange.(types.ExchangeTransferService)
if !ok {
return fmt.Errorf("exchange session %s does not implement transfer service", sessionName)
}
histories, err := exchange.QueryDepositHistory(ctx, asset, since, until)
if err != nil {
return err
}
log.Infof("%d histories", len(histories))
for _, h := range histories {
log.Infof("deposit history: %+v", h)
}
return nil
},
}