forked from stellar-deprecated/kelp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
krakenExchange_test.go
189 lines (154 loc) · 4.68 KB
/
krakenExchange_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
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
package plugins
import (
"fmt"
"strconv"
"testing"
"github.com/lightyeario/kelp/api"
"github.com/Beldur/kraken-go-api-client"
"github.com/lightyeario/kelp/model"
"github.com/stretchr/testify/assert"
)
var testKrakenExchange api.Exchange = krakenExchange{
assetConverter: model.KrakenAssetConverter,
api: krakenapi.New("", ""),
delimiter: "",
precision: 8,
withdrawKeys: asset2Address2Key{},
isSimulated: true,
}
func TestGetTickerPrice(t *testing.T) {
pair := model.TradingPair{Base: model.XLM, Quote: model.BTC}
pairs := []model.TradingPair{pair}
m, e := testKrakenExchange.GetTickerPrice(pairs)
if !assert.NoError(t, e) {
return
}
assert.Equal(t, 1, len(m))
ticker := m[pair]
assert.True(t, ticker.AskPrice.AsFloat() < 1, ticker.AskPrice.AsString())
}
func TestGetAccountBalances(t *testing.T) {
assetList := []model.Asset{
model.USD,
model.XLM,
model.BTC,
model.LTC,
model.ETH,
model.REP,
}
m, e := testKrakenExchange.GetAccountBalances(assetList)
if !assert.NoError(t, e) {
return
}
assert.Equal(t, 6, len(m))
// print balances here for convenience
for _, assetKey := range assetList {
fmt.Printf("Balance %s = %.8f\n", assetKey, m[assetKey].AsFloat())
}
for _, a := range assetList {
bal := m[a]
assert.True(t, bal.AsFloat() > 0, bal.AsString())
}
assert.Fail(t, "force fail")
}
func TestGetOrderBook(t *testing.T) {
pair := model.TradingPair{Base: model.XLM, Quote: model.BTC}
ob, e := testKrakenExchange.GetOrderBook(&pair, 10)
if !assert.NoError(t, e) {
return
}
assert.True(t, len(ob.Asks()) > 0, len(ob.Asks()))
assert.True(t, len(ob.Bids()) > 0, len(ob.Bids()))
assert.True(t, ob.Asks()[0].OrderAction.IsSell())
assert.True(t, ob.Asks()[0].OrderType.IsLimit())
assert.True(t, ob.Bids()[0].OrderAction.IsBuy())
assert.True(t, ob.Bids()[0].OrderType.IsLimit())
}
func TestGetTrades(t *testing.T) {
pair := model.TradingPair{Base: model.XLM, Quote: model.BTC}
trades, e := testKrakenExchange.GetTrades(&pair, nil)
if !assert.NoError(t, e) {
return
}
cursor := trades.Cursor.(int64)
assert.True(t, cursor > 0, strconv.FormatInt(cursor, 10))
assert.True(t, len(trades.Trades) > 0)
}
func TestGetTradeHistory(t *testing.T) {
tradeHistoryResult, e := testKrakenExchange.GetTradeHistory(nil, nil)
if !assert.NoError(t, e) {
return
}
// print here for convenience
fmt.Printf("total number of trades: %d\n", len(tradeHistoryResult.Trades))
for _, t := range tradeHistoryResult.Trades {
fmt.Println(t.String())
}
assert.True(t, len(tradeHistoryResult.Trades) > 0)
assert.Fail(t, "force fail")
}
func TestGetOpenOrders(t *testing.T) {
m, e := testKrakenExchange.GetOpenOrders()
if !assert.NoError(t, e) {
return
}
// print open orders here for convenience
for pair, openOrders := range m {
fmt.Printf("Open Orders for pair: %s\n", pair.String())
for _, o := range openOrders {
fmt.Printf(" %s\n", o.String())
}
}
assert.True(t, len(m) > 0, "there were no open orders")
assert.Fail(t, "force fail")
}
func TestAddOrder(t *testing.T) {
txID, e := testKrakenExchange.AddOrder(&model.Order{
Pair: &model.TradingPair{Base: model.REP, Quote: model.ETH},
OrderAction: model.OrderActionBuy,
OrderType: model.OrderTypeLimit,
Price: model.NumberFromFloat(0.00001, 5),
Volume: model.NumberFromFloat(0.3145, 5),
})
if !assert.NoError(t, e) {
return
}
fmt.Printf("transactionID from order: %s\n", txID)
assert.NotNil(t, txID)
assert.Fail(t, "force fail")
}
func TestCancelOrder(t *testing.T) {
// need to add some transactionID here to run this test
txID := model.MakeTransactionID("")
result, e := testKrakenExchange.CancelOrder(txID)
if !assert.NoError(t, e) {
return
}
fmt.Printf("result from cancel order (transactionID=%s): %s\n", txID.String(), result.String())
assert.Equal(t, model.CancelResultCancelSuccessful, result)
assert.Fail(t, "force fail")
}
func TestPrepareDeposit(t *testing.T) {
result, e := testKrakenExchange.PrepareDeposit(model.BTC, model.NumberFromFloat(1.0, 7))
if !assert.NoError(t, e) {
return
}
fmt.Printf("fee=%v, address=%v, expireTs=%v\n", result.Fee, result.Address, result.ExpireTs)
assert.Fail(t, "force fail")
}
func TestGetWithdrawInfo(t *testing.T) {
result, e := testKrakenExchange.GetWithdrawInfo(model.BTC, model.NumberFromFloat(1.0, 7), "")
if !assert.NoError(t, e) {
return
}
fmt.Printf("amountToReceive=%v\n", result.AmountToReceive.AsFloat())
assert.Fail(t, "force fail")
}
func TestWithdrawFunds(t *testing.T) {
result, e := testKrakenExchange.WithdrawFunds(model.XLM, model.NumberFromFloat(0.0000001, 7), "")
if !assert.NoError(t, e) {
return
}
fmt.Printf("refid=%v\n", result.WithdrawalID)
assert.Fail(t, "force fail")
}