-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathmain.go
60 lines (52 loc) · 1.24 KB
/
main.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
package main
import (
"flag"
"fmt"
"log"
"math/rand"
"os"
"time"
"github.com/gateio/gateapi-go/v5"
)
var logger = log.New(flag.CommandLine.Output(), "", log.LstdFlags)
func panicGateError(err error) {
if e, ok := err.(gateapi.GateAPIError); ok {
log.Fatal(fmt.Sprintf("Gate API error, label: %s, message: %s", e.Label, e.Message))
}
log.Fatal(err)
}
func main() {
var key, secret, baseUrl string
flag.StringVar(&key, "k", "", "Gate APIv4 key")
flag.StringVar(&secret, "s", "", "Gate APIv4 secret")
flag.StringVar(&baseUrl, "u", "", "API based URL used")
flag.Parse()
usage := fmt.Sprintf("Usage: %s -k <api-key> -s <api-secret> <spot|margin|futures>", os.Args[0])
if key == "" || secret == "" {
logger.Println(usage)
flag.PrintDefaults()
os.Exit(1)
}
if flag.NArg() < 1 {
logger.Println(usage)
flag.PrintDefaults()
os.Exit(1)
}
runConfig, err := NewRunConfig(key, secret, &baseUrl)
if err != nil {
logger.Fatal(err)
}
rand.Seed(time.Now().Unix())
for _, demo := range flag.Args() {
switch demo {
case "spot":
SpotDemo(runConfig)
case "margin":
MarginDemo(runConfig)
case "futures":
FuturesDemo(runConfig)
default:
logger.Fatal("Invalid demo provided. Available: spot, margin or futures")
}
}
}