Skip to content

Commit 7039e33

Browse files
Merge pull request #8 from chronicleprotocol/binance_us
Added BinanceUS as mock
2 parents 152481d + 1409e3a commit 7039e33

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

origin/binance_us.go

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package origin
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/chronicleprotocol/infestor/smocker"
7+
)
8+
9+
type BinanceUS struct{}
10+
11+
func (b BinanceUS) BuildMocks(e []ExchangeMock) ([]*smocker.Mock, error) {
12+
mocksOne, err := CombineMocks(e, b.build)
13+
if err != nil {
14+
return nil, err
15+
}
16+
tickers, err := CombineMocks(e, b.buildWholeDay)
17+
if err != nil {
18+
return nil, err
19+
}
20+
return append(mocksOne, tickers...), nil
21+
}
22+
23+
func (b BinanceUS) buildWholeDay(e ExchangeMock) (*smocker.Mock, error) {
24+
symbol := e.Symbol.Format("%s%s")
25+
body := `[{"symbol":"%s","lastPrice":"%.8f","bidPrice":"%.8f","askPrice":"%.8f","volume":"%.8f","closeTime":%d}]`
26+
27+
return &smocker.Mock{
28+
Request: smocker.MockRequest{
29+
Method: smocker.ShouldEqual("GET"),
30+
Path: smocker.ShouldEqual("/api/v3/ticker/24hr"),
31+
},
32+
Response: &smocker.MockResponse{
33+
Status: e.StatusCode,
34+
Headers: map[string]smocker.StringSlice{
35+
"Content-Type": []string{
36+
"application/json",
37+
},
38+
},
39+
Body: fmt.Sprintf(body, symbol, e.Price, e.Bid, e.Ask, e.Volume, e.Timestamp.UnixMilli()),
40+
},
41+
}, nil
42+
}
43+
44+
func (b BinanceUS) build(e ExchangeMock) (*smocker.Mock, error) {
45+
symbol := e.Symbol.Format("%s%s")
46+
body := `{"symbol": "%s","price": "%.8f"}`
47+
48+
return &smocker.Mock{
49+
Request: smocker.MockRequest{
50+
Method: smocker.ShouldEqual("GET"),
51+
Path: smocker.ShouldEqual("/api/v3/ticker/price"),
52+
QueryParams: map[string]smocker.StringMatcherSlice{
53+
"symbol": []smocker.StringMatcher{
54+
smocker.ShouldEqual(symbol),
55+
},
56+
},
57+
},
58+
Response: &smocker.MockResponse{
59+
Status: e.StatusCode,
60+
Headers: map[string]smocker.StringSlice{
61+
"Content-Type": []string{
62+
"application/json",
63+
},
64+
},
65+
Body: fmt.Sprintf(body, symbol, e.Price),
66+
},
67+
}, nil
68+
}

origin/exchange.go

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ var exchanges = map[string]Mockable{
3434
"rocketpool": RocketPool{},
3535
"balancer": Balancer{},
3636
"binance": Binance{},
37+
"binance_us": BinanceUS{},
3738
"bitfinex": Bitfinex{},
3839
"bitthumb": Bithumb{},
3940
"bithumb": Bithumb{},

0 commit comments

Comments
 (0)