-
Notifications
You must be signed in to change notification settings - Fork 17
/
main.go
145 lines (99 loc) · 3.08 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
134
135
136
137
138
139
140
141
142
143
144
145
package main
// go:generate sqlboiler postgres
import (
"database/sql"
"fmt"
"net/http"
_ "github.com/lib/pq"
"github.com/spf13/viper"
"github.com/vattle/sqlboiler/boil"
log15 "gopkg.in/inconshreveable/log15.v2"
)
// Open handle to database like normal
var log = log15.New()
func main() {
viper.SetConfigFile("./config.json")
// Searches for config file in given paths and read it
if err := viper.ReadInConfig(); err != nil {
panic(err)
}
viper.SetDefault("POW", "http://api.f2pool.com/decred/address")
viper.SetDefault("ExchangeData", "https://bittrex.com/api/v1.1/public/getmarkethistory")
psqlInfo := fmt.Sprintf("host=%s port=%d user=%s "+"password=%s dbname=%s sslmode=disable", viper.Get("Database.pghost"), viper.Get("Database.pgport"), viper.Get("Database.pguser"), viper.Get("Database.pgpass"), viper.Get("Database.pgdbname"))
db, err := sql.Open("postgres", psqlInfo)
if err != nil {
panic(err.Error())
return
}
boil.SetDB(db)
// getHistoricData(1, "BTC-DCR", "1514764800", "1514851200") //parameters : exchangeID,currency pair, start time, end time
getPOSdata()
// for {
// getHistoricData(1, "BTC-DCR", "1514764800", "1514851200") //parameters : exchangeID,currency pair, start time, end time //parameters : Currency pair
// getChartData(1, "BTC_DCR", "1405699200", "9999999999") //parameters: exchange id,Currency Pair, start time , end time
// }
// getPOWData(2, "") //parameters: pool id
}
// Exchange id = 0 for Poloneix
// Exchange id =1 for Bittrex
// func fetchHistoricData(exchangeID int, date string) {
// if exchangeID == 0 { //Poloniex exchange
// user := Poloniex{
// client: &http.Client{},
// }
// user.fetchPoloniexData(date)
// }
// if exchangeID == 1 { //Bittrex Exchange
// user := Bittrex{
// client: &http.Client{},
// }
// user.fetchBittrexData(date)
// }
// }
func getPOSdata() {
user := POS{
client: &http.Client{},
}
user.getPOS()
}
func getPOWData(PoolID int, apiKey string) {
user := POW{
client: &http.Client{},
}
user.getPOW(PoolID, viper.GetString("POW"+"["+string(PoolID)+"]"), apiKey)
}
// Exchange id = 0 for Poloneix
// Exchange id =1 for Bittrex
func getHistoricData(exchangeID int, currencyPair string, startTime string, endTime string) {
if exchangeID == 0 { //Poloniex exchange
user := Poloniex{
client: &http.Client{},
}
user.getPoloniexData(currencyPair, startTime, endTime)
}
if exchangeID == 1 { //Bittrex Exchange
user := Bittrex{
client: &http.Client{},
}
user.getBittrexData(currencyPair)
}
//Time delay of 24 hours
// time.Sleep(86400 * time.Second)
}
//Get chart data from exchanges
// if exchange id =0 , get chart data from poloniex exchange
// exchange id =1 get chart data from bittrex exchange
func getChartData(exchangeID int, currencyPair string, startTime string, endTime string) {
if exchangeID == 0 {
user := Poloniex{
client: &http.Client{},
}
user.getChartData(currencyPair, startTime, endTime)
}
if exchangeID == 1 {
user := Bittrex{
client: &http.Client{},
}
user.getTicks(currencyPair)
}
}