forked from irinazheltisheva/powergate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathasks_get.go
More file actions
51 lines (44 loc) · 1.19 KB
/
asks_get.go
File metadata and controls
51 lines (44 loc) · 1.19 KB
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
package cmd
import (
"context"
"os"
"strconv"
"github.com/caarlos0/spin"
"github.com/logrusorgru/aurora"
"github.com/spf13/cobra"
)
func init() {
asksCmd.AddCommand(getCmd)
}
var getCmd = &cobra.Command{
Use: "get",
Short: "Get the asks index",
Long: `Get the asks index`,
Run: func(cmd *cobra.Command, args []string) {
ctx, cancel := context.WithTimeout(context.Background(), cmdTimeout)
defer cancel()
s := spin.New("%s Getting storage asks...")
s.Start()
index, err := fcClient.Asks.Get(ctx)
s.Stop()
checkErr(err)
if len(index.Storage) > 0 {
Message("Storage median price price: %v", index.StorageMedianPrice)
Message("Last updated: %v", index.LastUpdated.Format("01/02/06 15:04 MST"))
data := make([][]string, len(index.Storage))
i := 0
for _, a := range index.Storage {
data[i] = []string{
a.Miner,
strconv.Itoa(int(a.Price)),
strconv.Itoa(int(a.MinPieceSize)),
strconv.FormatInt(a.Timestamp, 10),
strconv.FormatInt(a.Expiry, 10),
}
i++
}
RenderTable(os.Stdout, []string{"miner", "price", "min piece size", "timestamp", "expiry"}, data)
}
Message("Found %d asks", aurora.White(len(index.Storage)).Bold())
},
}