-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtrading_test.go
76 lines (57 loc) · 1.65 KB
/
trading_test.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
package gokraken
import (
"context"
"net/http"
"net/http/httptest"
"testing"
"github.com/danmrichards/gokraken/pairs"
)
func TestTrading_AddOrder(t *testing.T) {
mockResponse := []byte(`{"error":[],"result":{"descr":{"pair":0,"close":"4321","leverage":"","order":"1234","ordertype":"","price":"","price2":"","type":""},"txid":["2345","3456"]}}`)
expectedResult := &AddOrderResponse{
Description: OrderDescription{
Order: "1234",
Close: "4321",
},
TxIDs: []string{"2345", "3456"},
}
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
w.Write(mockResponse)
}))
defer ts.Close()
k := NewWithAuth("api_key", "cHJpdmF0ZV9rZXk=")
k.BaseURL = ts.URL
order := UserOrder{
Pair: pairs.BCHEUR,
Type: TradeSell,
OrderType: OrderTypeMarket,
Volume: 1.23,
}
res, err := k.Trading.AddOrder(context.Background(), order)
if err != nil {
t.Fatal(err)
}
assert(expectedResult, res, t)
}
func TestTrading_CancelOrder(t *testing.T) {
mockResponse := []byte(`{"error":[],"result":{"count": 1, "pending": true}}`)
expectedResult := &CancelOrderResponse{
Count: 1,
Pending: true,
}
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
w.Write(mockResponse)
}))
defer ts.Close()
k := NewWithAuth("api_key", "cHJpdmF0ZV9rZXk=")
k.BaseURL = ts.URL
res, err := k.Trading.CancelOrder(context.Background(), 1234)
if err != nil {
t.Fatal(err)
}
assert(expectedResult, res, t)
}