-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.go
More file actions
83 lines (68 loc) · 2.04 KB
/
Copy pathinit.go
File metadata and controls
83 lines (68 loc) · 2.04 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
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
package main
import (
"flag"
"log"
"runtime"
"strings"
"github.com/rcolombo/tickertock/types"
"github.com/shopspring/decimal"
)
var (
apiKey = flag.String("api-key", "", "Your Huobi API Key")
apiSecret = flag.String("api-secret", "", "Your Huobi API Secret")
market = flag.String("market", "", "The name of the market in the form of base_quote (e.g. zrx_btc, xrp_btc")
stopPrice = flag.String("stop-price", "", "Issue order when the price hits this amount")
limitPrice = flag.String("limit-price", "", "The price on your order")
amount = flag.String("amount", "", "Amount to order")
orderSide = flag.String("order-side", "", "buy or sell")
cp types.CurrencyPair
stopPriceDec decimal.Decimal
limitPriceDec decimal.Decimal
amountDec decimal.Decimal
isBuy bool
)
func init() {
var err error
runtime.GOMAXPROCS(runtime.NumCPU())
flag.Parse()
if *apiKey == "" {
log.Fatal("Please enter an API Key")
}
if *apiSecret == "" {
log.Fatal("Please enter an API Secret Key")
}
if *stopPrice == "" {
log.Fatal("Please enter a stop price")
}
if *limitPrice == "" {
log.Fatal("Please enter a limit price")
}
if *amount == "" {
log.Fatal("Please enter an amount")
}
if *market == "" {
log.Fatal("Please enter a valid market (e.g zrx_btc)")
}
baseQuote := strings.Split(*market, "_")
if len(baseQuote) != 2 {
log.Fatal("Please enter a valid market (e.g zrx_btc)")
}
cp = types.CurrencyPair{Base: baseQuote[0], Quote: baseQuote[1]}
orderSideLower := strings.ToLower(*orderSide)
if !(orderSideLower == "buy" || orderSideLower == "sell") {
log.Fatal("Invalid order side. Please pick one of 'buy', 'sell'")
}
isBuy = orderSideLower == "buy"
stopPriceDec, err = decimal.NewFromString(*stopPrice)
if err != nil {
log.Fatal("Error parsing stop price: ", err)
}
limitPriceDec, err = decimal.NewFromString(*limitPrice)
if err != nil {
log.Fatal("Error parsing limit price: ", err)
}
amountDec, err = decimal.NewFromString(*amount)
if err != nil {
log.Fatal("Error parsing amount: ", err)
}
}