-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmulti_price_trading_info.go
80 lines (63 loc) · 2.04 KB
/
multi_price_trading_info.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
package puzzle
import (
"encoding/json"
"fmt"
"log"
"strings"
)
// MultiPriceMarket - Contains the outermost layer of the response.
type MultiPriceMarket struct {
// Type - This can be Ex: "RAW" or "DISPLAY"
Type map[string]map[string]MultiPriceFrom
}
// MultiPriceFrom - Contains the name of the currency you take as base to compare to. Ex: "USD"
type MultiPriceFrom struct {
From string
// Contains list of the targetet currency.
To map[string]MultiPriceTo
}
// MultiPriceTo - Contains the targetet currency. Ex: "ETH"
type MultiPriceTo struct {
Name string
Field map[string]interface{}
}
// MultiPriceTradingInfo - Contains data from multiple currencies to multiple currencies.
func MultiPriceTradingInfo(from []string, to []string) MultiPriceMarket {
url := fmt.Sprintf("%s/pricemultifull?fsyms=%s&tsyms=%s", baseHref, strings.Join(from, ","), strings.Join(to, ","))
var unpacked map[string]map[string]map[string]map[string]interface{}
body := makeRequest(url)
json.Unmarshal(body, &unpacked)
err := json.Unmarshal(body, &unpacked)
if err != nil {
log.Fatal("Failed unmarshaling data. \n", err)
}
mulPriceType := MultiPriceMarket{}
sliceMulPriceCrypt := make(map[string]MultiPriceTo, 0)
sliceMulPriceCurr := make(map[string]MultiPriceFrom, 0)
mulPriceType.Type = make(map[string]map[string]MultiPriceFrom, 2)
for from, to := range unpacked {
for curr, crypt := range to {
for name, val := range crypt {
mulPriceCrypt := MultiPriceTo{
Name: name,
Field: val,
}
sliceMulPriceCrypt[mulPriceCrypt.Name] = mulPriceCrypt
}
mulPriceCurr := MultiPriceFrom{
From: curr,
To: sliceMulPriceCrypt,
}
sliceMulPriceCrypt = nil
sliceMulPriceCrypt = make(map[string]MultiPriceTo, 0)
sliceMulPriceCurr[mulPriceCurr.From] = mulPriceCurr
}
if mulPriceType.Type[from] == nil {
mulPriceType.Type[from] = make(map[string]MultiPriceFrom, 1)
}
mulPriceType.Type[from] = sliceMulPriceCurr
sliceMulPriceCurr = nil
sliceMulPriceCurr = make(map[string]MultiPriceFrom, 0)
}
return mulPriceType
}