This repository has been archived by the owner on Apr 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
getmarketsummary.go
89 lines (76 loc) · 2.58 KB
/
getmarketsummary.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
//
// Copyright 2015-2019 Pedro Salgado
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package getmarketsummary
import (
"fmt"
"log"
"time"
"github.com/thebotguys/golang-bittrex-api/bittrex"
cli "gopkg.in/urfave/cli.v1"
)
// resolution number of digits after the decimal point.
const resolution = 8
var (
market string
)
// ValidateArg nothing to be validated.
func ValidateArg(c *cli.Context) error {
return nil
}
// Run get the last 24 hour summary of all active exchanges.
func Run(cctx *cli.Context) error {
for i := 0; i < 10; i++ {
summary, err := bittrex.GetMarketSummary(market)
if err != nil {
log.Fatal(err.Error())
}
if summary.MarketName != market {
// bug on v2 API may lead to getting the wrong summary
continue
}
printSummary(summary)
time.Sleep(2 * time.Second)
}
return nil
}
func printSummary(summary *bittrex.MarketSummary) {
//The name of the market (e.g. BTC-ETH).
fmt.Printf("%s\t", summary.MarketName)
// The 24h high for the market.
fmt.Printf("%s\t", summary.High.StringFixedBank(resolution))
// The 24h low for the market.
fmt.Printf("%s\t", summary.Low.StringFixedBank(resolution))
// The value of the last trade for the market (in base currency).
fmt.Printf("%s\t", summary.Last.StringFixedBank(resolution))
// The current highest bid value for the market.
fmt.Printf("%s\t", summary.Bid.StringFixedBank(resolution))
// The current lowest ask value for the market.
fmt.Printf("%s\t", summary.Ask.StringFixedBank(resolution))
// The 24h volume of the market, in market currency.
fmt.Printf("%s\t", summary.Volume)
// The 24h volume for the market, in base currency.
fmt.Printf("%s\t", summary.BaseVolume)
// The timestamp of the request.
fmt.Printf("%s\t", summary.Timestamp)
// The number of currently open buy orders.
fmt.Printf("%d\t", summary.OpenBuyOrders)
// The number of currently open sell orders.
fmt.Printf("%d\t", summary.OpenSellOrders)
// The closing price 24h before.
fmt.Printf("%s\t", summary.PrevDay.StringFixedBank(resolution))
// The timestamp of the creation of the market.
fmt.Printf("%s\n", summary.Created)
}