-
Notifications
You must be signed in to change notification settings - Fork 76
/
balance.go
40 lines (33 loc) · 1.07 KB
/
balance.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
package main
import (
"context"
"fmt"
"time"
"github.com/Akagi201/cryptotrader/binance"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
)
type BalanceCmd struct {
Exchange string `short:"e" long:"exchange" description:"The exchange to query balance"`
AccessKey string `long:"access" default:"" description:"access key for the exchange"`
SecretKey string `long:"secret" default:"" description:"secret key for the exchange"`
}
func (bc *BalanceCmd) Execute(args []string) error {
log.Infof("balance command exchange: %v, args: %v", bc.Exchange, args)
switch bc.Exchange {
case "binance":
log.Info("binance")
c := binance.New(bc.AccessKey, bc.SecretKey)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
b, _ := c.GetAccount(ctx, 0)
fmt.Printf("%v: %+v\n", bc.Exchange, b)
default:
return errors.New("exchange not supported")
}
return nil
}
var balanceCmd BalanceCmd
func init() {
parser.AddCommand("balance", "get the balance from an exchange", "The balance command get the balance from an exchange", &balanceCmd)
}