/
appspot_feed.go
56 lines (42 loc) · 971 Bytes
/
appspot_feed.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
package feed
import (
"time"
. "github.com/korobool/btcticker/product"
)
var (
appspotEurUri = "http://rate-exchange-1.appspot.com/currency?from=EUR&to=USD"
)
type AppspotMsgCurrency struct {
To string `json:"to"`
Form string `json:"from"`
Rate float64 `json:"rate"`
}
type AppspotFeed struct {
RestFeed
}
func NewAppspotFeed(agr *Aggregator) (Feed, error) {
pollInterval := 5 * time.Second
reqTimeout := 1 * time.Second
info := FeedInfo{ProductEurUsd, "appspot"}
rf, err := NewRestFeed(info, agr, pollInterval, reqTimeout)
if err != nil {
return nil, err
}
f := &AppspotFeed{RestFeed: *rf}
f.SetPollHandler(f.poll)
return f, nil
}
func (f *AppspotFeed) poll() (*TickMsg, error) {
var msg AppspotMsgCurrency
err := f.requestGet(appspotEurUri, &msg, f.reqTimeout)
if err != nil {
return nil, err
}
ts := time.Now().Unix()
return &TickMsg{
Info: f.GetInfo(),
Ts: ts,
TsBuy: ts,
BidPrice: msg.Rate,
}, nil
}