This repository has been archived by the owner on Sep 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.go
133 lines (109 loc) · 3.47 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
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package main
import (
"fmt"
"os"
"strings"
abcc "github.com/hexoul/go-abcc"
coinsuper "github.com/hexoul/go-coinsuper"
kucoin "github.com/hexoul/go-kucoin"
upbit "github.com/hexoul/go-upbit"
bittrex "github.com/toorop/go-bittrex"
"github.com/jasonlvhit/gocron"
"github.com/hexoul/go-coinmarketcap/statistics"
"github.com/hexoul/go-coinmarketcap/types"
)
// Clients struct
type Clients struct {
abcc *abcc.Client
bittrex *bittrex.Bittrex
kucoin *kucoin.Client
coinsuper *coinsuper.Client
upbit *upbit.Client
}
var (
targetSymbol string
targetAddr string
targetQuotes = "USD"
targetSlugs = "binance"
accessKey = map[string]string{}
secretKey = map[string]string{}
clients Clients
)
func init() {
for _, val := range os.Args {
arg := strings.Split(val, "=")
if len(arg) < 2 {
continue
} else if arg[0] == "-targetSymbol" {
targetSymbol = arg[1]
} else if arg[0] == "-targetAddr" {
targetAddr = arg[1]
} else if arg[0] == "-targetQuotes" {
targetQuotes = arg[1]
} else if arg[0] == "-targetSlugs" {
targetSlugs = arg[1]
} else if strings.Contains(arg[0], "accesskey") {
accessKey[strings.Split(arg[0], ":")[0][1:]] = arg[1]
} else if strings.Contains(arg[0], "secretkey") {
secretKey[strings.Split(arg[0], ":")[0][1:]] = arg[1]
}
}
clients.bittrex = bittrex.New(accessKey["bittrex"], secretKey["bittrex"])
}
func main() {
fmt.Println("Initializing...")
// Initialize CryptoQuote
cryptoQuoteOptions := &types.Options{
Symbol: targetSymbol,
Convert: targetQuotes,
}
statistics.TaskGatherCryptoQuote(cryptoQuoteOptions)
// Initialize ExchangeMarketPairs
var exchangeMarketPairsOptions []*types.Options
for _, slug := range strings.Split(targetSlugs, ",") {
exchangeMarketPairsOptions = append(exchangeMarketPairsOptions, &types.Options{
Slug: slug,
Convert: targetQuotes,
Limit: 300,
})
statistics.TaskGatherExchangeMarketPairs(exchangeMarketPairsOptions[len(exchangeMarketPairsOptions)-1], targetSymbol)
}
// Initialize TokenMetric
// statistics.TaskGatherTokenMetric(targetSymbol, targetAddr)
// Initialize OHLCV
var ohlcvOptions []*types.Options
for _, quote := range strings.Split(targetQuotes, ",") {
ohlcvOptions = append(ohlcvOptions, &types.Options{
Symbol: targetSymbol,
Convert: quote,
})
}
// Initialize Balance
clients.GetBalances()
// Initialize Trade
clients.GetTrades()
fmt.Printf("Done\nScheduling...\n")
// Schedule CryptoQuote
statistics.GatherCryptoQuote(cryptoQuoteOptions, gocron.Every(10).Minutes())
statistics.GatherCryptoQuote(cryptoQuoteOptions, gocron.Every(1).Day().At("23:59"))
// Schedule ExchangeMarketPairs
for _, option := range exchangeMarketPairsOptions {
statistics.GatherExchangeMarketPairs(option, targetSymbol, gocron.Every(10).Minutes())
statistics.GatherExchangeMarketPairs(option, targetSymbol, gocron.Every(1).Day().At("23:59"))
}
// Schedule TokenMetric
// statistics.GatherTokenMetric(targetSymbol, targetAddr, gocron.Every(30).Minutes())
// statistics.GatherTokenMetric(targetSymbol, targetAddr, gocron.Every(1).Day().At("23:59"))
// Schedule OHLCV
for _, option := range ohlcvOptions {
statistics.GatherOhlcv(option, gocron.Every(1).Day().At("12:00"))
}
// Schedule Balance
gocron.Every(10).Minutes().Do(clients.GetBalances)
// Schedule Trade
gocron.Every(2).Minutes().Do(clients.GetTrades)
// Schedule Git commit and push
gocron.Every(3).Hours().Do(gitPushChanges)
fmt.Printf("Done\nStart!!\n")
<-gocron.Start()
}