Skip to content
This repository was archived by the owner on Feb 1, 2024. It is now read-only.

Commit afb5628

Browse files
authored
new price feed: last trade price (closes #333) (#334)
* 1 - add lastPrice to api.Ticker and to CCXT * 2 - add last price to tickerAPI of krakenExchange.go * 3 - log lastTradePrice in exchangeFeed.go * 4 - add support for "last" price modifier in exchangeFeed and sample config files * 5 - add note in LIST_OF_HACKS for backward compatibility in defaulting to "mid" price in exchangeFeed * 6 - move validation check on modifier input to exchange factory method * 7 - rename GetMidPrice() -> GetFeedPairPrice() in FeedPair
1 parent b6eb041 commit afb5628

13 files changed

Lines changed: 100 additions & 52 deletions

LIST_OF_HACKS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
Incomplete list of hacks in the codebase that should be fixed before upgrading to v2.0 which will change the API to Kelp in some way
66

77
- LOH-1 - support backward-compatible case of not having any pre-specified function
8+
- LOH-2 - support backward-compatible case of defaulting to "mid" price when left unspecified
89

910
## Workarounds
1011

api/exchange.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ type Account interface {
3636

3737
// Ticker encapsulates all the data for a given Trading Pair
3838
type Ticker struct {
39-
AskPrice *model.Number
40-
BidPrice *model.Number
39+
AskPrice *model.Number
40+
BidPrice *model.Number
41+
LastPrice *model.Number
4142
}
4243

4344
// TradesResult is the result of a GetTrades call

api/priceFeed.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ type PriceFeed interface {
77
GetPrice() (float64, error)
88
}
99

10+
// TODO this should be structured as a specific impl. of the PriceFeed interface
1011
// FeedPair is the struct representing a price feed for a trading pair
1112
type FeedPair struct {
1213
FeedA PriceFeed
1314
FeedB PriceFeed
1415
}
1516

16-
// GetMidPrice fetches the mid price from this feed pair
17-
func (p *FeedPair) GetMidPrice() (float64, error) {
17+
// GetFeedPairPrice fetches the price by dividing FeedA by FeedB
18+
func (p *FeedPair) GetFeedPairPrice() (float64, error) {
1819
pA, err := p.FeedA.GetPrice()
1920
if err != nil {
2021
return 0, err
@@ -26,7 +27,7 @@ func (p *FeedPair) GetMidPrice() (float64, error) {
2627
return 0, err
2728
}
2829

29-
midPrice := pA / pB
30-
log.Printf("feedPair prices: feedA=%.7f, feedB=%.7f; midPrice=%.7f\n", pA, pB, midPrice)
31-
return midPrice, nil
30+
price := pA / pB
31+
log.Printf("feedPair prices: feedA=%.8f, feedB=%.8f; price=%.8f\n", pA, pB, price)
32+
return price, nil
3233
}

examples/configs/trader/sample_buysell.cfg

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ DATA_TYPE_A="exchange"
1919
# this code can be retrieved from the exchange's website or from the ccxt manual for ccxt-based exchanges.
2020
# modifier:
2121
# this is a modifier that can be included only for feed type "exchange".
22-
# a modifier allows you to fetch the "mid" price, "ask" price, or "bid" price for now.
23-
# if left unspecified then this is defaulted to "mid" for backwards compatibility (until v2.0 is released)
22+
# a modifier allows you to fetch the "mid" price, "ask" price, "bid" price, or "last" price for now.
23+
# if left unspecified then this is defaulted to "mid" for backwards compatibility (until v2.0 is released) (LOH-2)
2424
# uncomment below to use binance, poloniex, or bittrex as your price feed. You will need to set up CCXT to use this, see the "Using CCXT" section in the README for details.
2525
# be careful about using USD vs. USDT since some exchanges support only one, or both, or in some cases neither.
26-
#DATA_FEED_A_URL="ccxt-kraken/XLM/USD/mid"
26+
#DATA_FEED_A_URL="ccxt-kraken/XLM/USD/last"
2727
#DATA_FEED_A_URL="ccxt-binance/XLM/USDT/ask"
2828
#DATA_FEED_A_URL="ccxt-poloniex/XLM/USDT/bid"
2929
# bittrex does not have an XLM/USD market so this config lists XLM/BTC instead; you should NOT use this when trying to price an asset based on the XLM/USD price (unless you know what you are doing).

examples/configs/trader/sample_sell.cfg

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ DATA_TYPE_A="exchange"
2121
# this code can be retrieved from the exchange's website or from the ccxt manual for ccxt-based exchanges.
2222
# modifier:
2323
# this is a modifier that can be included only for feed type "exchange".
24-
# a modifier allows you to fetch the "mid" price, "ask" price, or "bid" price for now.
25-
# if left unspecified then this is defaulted to "mid" for backwards compatibility (until v2.0 is released)
24+
# a modifier allows you to fetch the "mid" price, "ask" price, "bid" price, or "last" price for now.
25+
# if left unspecified then this is defaulted to "mid" for backwards compatibility (until v2.0 is released) (LOH-2)
2626
# uncomment below to use binance, poloniex, or bittrex as your price feed. You will need to set up CCXT to use this, see the "Using CCXT" section in the README for details.
2727
# be careful about using USD vs. USDT since some exchanges support only one, or both, or in some cases neither.
28-
#DATA_FEED_A_URL="ccxt-kraken/XLM/USD/mid"
28+
#DATA_FEED_A_URL="ccxt-kraken/XLM/USD/last"
2929
#DATA_FEED_A_URL="ccxt-binance/XLM/USDT/ask"
3030
#DATA_FEED_A_URL="ccxt-poloniex/XLM/USDT/bid"
3131
# bittrex does not have an XLM/USD market so this config lists XLM/BTC instead; you should NOT use this when trying to price an asset based on the XLM/USD price (unless you know what you are doing).

plugins/ccxtExchange.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,22 @@ func (c ccxtExchange) GetTickerPrice(pairs []model.TradingPair) (map[model.Tradi
8080

8181
askPrice, e := utils.CheckFetchFloat(tickerMap, "ask")
8282
if e != nil {
83-
return nil, fmt.Errorf("unable to correctly fetch value from tickerMap: %s", e)
83+
return nil, fmt.Errorf("unable to correctly fetch 'ask' value from tickerMap: %s", e)
8484
}
8585
bidPrice, e := utils.CheckFetchFloat(tickerMap, "bid")
8686
if e != nil {
87-
return nil, fmt.Errorf("unable to correctly fetch value from tickerMap: %s", e)
87+
return nil, fmt.Errorf("unable to correctly fetch 'bid' value from tickerMap: %s", e)
88+
}
89+
lastPrice, e := utils.CheckFetchFloat(tickerMap, "last")
90+
if e != nil {
91+
return nil, fmt.Errorf("unable to correctly fetch 'last' value from tickerMap: %s", e)
8892
}
8993

94+
pricePrecision := c.GetOrderConstraints(&p).PricePrecision
9095
priceResult[p] = api.Ticker{
91-
AskPrice: model.NumberFromFloat(askPrice, c.GetOrderConstraints(&p).PricePrecision),
92-
BidPrice: model.NumberFromFloat(bidPrice, c.GetOrderConstraints(&p).PricePrecision),
96+
AskPrice: model.NumberFromFloat(askPrice, pricePrecision),
97+
BidPrice: model.NumberFromFloat(bidPrice, pricePrecision),
98+
LastPrice: model.NumberFromFloat(lastPrice, pricePrecision),
9399
}
94100
}
95101

@@ -114,7 +120,11 @@ func (c ccxtExchange) GetOrderConstraints(pair *model.TradingPair) *model.OrderC
114120
if ccxtMarket == nil {
115121
panic(fmt.Errorf("CCXT does not have precision and limit data for the passed in market: %s", pairString))
116122
}
117-
oc := model.MakeOrderConstraintsWithCost(ccxtMarket.Precision.Price, ccxtMarket.Precision.Amount, ccxtMarket.Limits.Amount.Min, ccxtMarket.Limits.Cost.Min)
123+
volumePrecision := ccxtMarket.Precision.Amount
124+
if volumePrecision == 0 {
125+
volumePrecision = ccxtMarket.Precision.Price
126+
}
127+
oc := model.MakeOrderConstraintsWithCost(ccxtMarket.Precision.Price, volumePrecision, ccxtMarket.Limits.Amount.Min, ccxtMarket.Limits.Cost.Min)
118128

119129
return c.ocOverridesHandler.Apply(pair, oc)
120130
}

plugins/ccxtExchange_test.go

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package plugins
33
import (
44
"fmt"
55
"log"
6+
"math"
67
"strconv"
78
"testing"
89
"time"
@@ -12,16 +13,22 @@ import (
1213
"github.com/stretchr/testify/assert"
1314
)
1415

15-
var supportedExchanges = []string{"binance"}
16+
var supportedExchanges = []string{"binance", "kraken"}
1617
var emptyAPIKey = api.ExchangeAPIKey{}
1718
var emptyParams = api.ExchangeParam{}
1819
var supportedTradingExchanges = map[string]api.ExchangeAPIKey{
1920
"binance": {},
2021
}
2122

22-
var testOrderConstraints = map[model.TradingPair]model.OrderConstraints{
23-
*model.MakeTradingPair(model.XLM, model.USDT): *model.MakeOrderConstraints(4, 5, 0.1),
24-
*model.MakeTradingPair(model.XLM, model.BTC): *model.MakeOrderConstraints(8, 4, 1.0),
23+
var testOrderConstraints = map[string]map[model.TradingPair]model.OrderConstraints{
24+
"binance": map[model.TradingPair]model.OrderConstraints{
25+
*model.MakeTradingPair(model.XLM, model.USDT): *model.MakeOrderConstraints(4, 5, 0.1),
26+
*model.MakeTradingPair(model.XLM, model.BTC): *model.MakeOrderConstraints(8, 4, 1.0),
27+
},
28+
"kraken": map[model.TradingPair]model.OrderConstraints{
29+
*model.MakeTradingPair(model.XLM, model.USD): *model.MakeOrderConstraints(6, 8, 30.0),
30+
*model.MakeTradingPair(model.XLM, model.BTC): *model.MakeOrderConstraints(8, 8, 30.0),
31+
},
2532
}
2633

2734
func TestGetTickerPrice_Ccxt(t *testing.T) {
@@ -31,7 +38,7 @@ func TestGetTickerPrice_Ccxt(t *testing.T) {
3138

3239
for _, exchangeName := range supportedExchanges {
3340
t.Run(exchangeName, func(t *testing.T) {
34-
testCcxtExchange, e := makeCcxtExchange(exchangeName, testOrderConstraints, []api.ExchangeAPIKey{emptyAPIKey}, []api.ExchangeParam{emptyParams}, []api.ExchangeHeader{}, false)
41+
testCcxtExchange, e := makeCcxtExchange(exchangeName, testOrderConstraints[exchangeName], []api.ExchangeAPIKey{emptyAPIKey}, []api.ExchangeParam{emptyParams}, []api.ExchangeHeader{}, false)
3542
if !assert.NoError(t, e) {
3643
return
3744
}
@@ -47,6 +54,9 @@ func TestGetTickerPrice_Ccxt(t *testing.T) {
4754

4855
ticker := m[pair]
4956
assert.True(t, ticker.AskPrice.AsFloat() < 1, ticker.AskPrice.AsString())
57+
assert.True(t, ticker.BidPrice.AsFloat() < 1, ticker.BidPrice.AsString())
58+
assert.True(t, ticker.BidPrice.AsFloat() < ticker.AskPrice.AsFloat(), fmt.Sprintf("bid price (%s) should be less than ask price (%s)", ticker.BidPrice.AsString(), ticker.AskPrice.AsString()))
59+
assert.True(t, ticker.LastPrice.AsFloat() < 1, ticker.LastPrice.AsString())
5060
})
5161
}
5262
}
@@ -58,7 +68,7 @@ func TestGetOrderBook_Ccxt(t *testing.T) {
5868

5969
for _, exchangeName := range supportedExchanges {
6070
t.Run(exchangeName, func(t *testing.T) {
61-
testCcxtExchange, e := makeCcxtExchange(exchangeName, testOrderConstraints, []api.ExchangeAPIKey{emptyAPIKey}, []api.ExchangeParam{emptyParams}, []api.ExchangeHeader{}, false)
71+
testCcxtExchange, e := makeCcxtExchange(exchangeName, testOrderConstraints[exchangeName], []api.ExchangeAPIKey{emptyAPIKey}, []api.ExchangeParam{emptyParams}, []api.ExchangeHeader{}, false)
6272
if !assert.NoError(t, e) {
6373
return
6474
}
@@ -91,7 +101,7 @@ func TestGetTrades_Ccxt(t *testing.T) {
91101

92102
for _, exchangeName := range supportedExchanges {
93103
t.Run(exchangeName, func(t *testing.T) {
94-
testCcxtExchange, e := makeCcxtExchange(exchangeName, testOrderConstraints, []api.ExchangeAPIKey{emptyAPIKey}, []api.ExchangeParam{}, []api.ExchangeHeader{}, false)
104+
testCcxtExchange, e := makeCcxtExchange(exchangeName, testOrderConstraints[exchangeName], []api.ExchangeAPIKey{emptyAPIKey}, []api.ExchangeParam{}, []api.ExchangeHeader{}, false)
95105
if !assert.NoError(t, e) {
96106
return
97107
}
@@ -117,7 +127,7 @@ func TestGetTradeHistory_Ccxt(t *testing.T) {
117127

118128
for exchangeName, apiKey := range supportedTradingExchanges {
119129
t.Run(exchangeName, func(t *testing.T) {
120-
testCcxtExchange, e := makeCcxtExchange(exchangeName, testOrderConstraints, []api.ExchangeAPIKey{apiKey}, []api.ExchangeParam{emptyParams}, []api.ExchangeHeader{}, false)
130+
testCcxtExchange, e := makeCcxtExchange(exchangeName, testOrderConstraints[exchangeName], []api.ExchangeAPIKey{apiKey}, []api.ExchangeParam{emptyParams}, []api.ExchangeHeader{}, false)
121131
if !assert.NoError(t, e) {
122132
return
123133
}
@@ -144,10 +154,10 @@ func validateTrades(t *testing.T, pair model.TradingPair, trades []model.Trade)
144154
if !assert.Equal(t, &pair, trade.Pair) {
145155
return
146156
}
147-
if !assert.True(t, trade.Price.AsFloat() > 0, fmt.Sprintf("%.7f", trade.Price.AsFloat())) {
157+
if !assert.True(t, trade.Price.AsFloat() > 0, trade.Price.AsString()) {
148158
return
149159
}
150-
if !assert.True(t, trade.Volume.AsFloat() > 0, fmt.Sprintf("%.7f", trade.Volume.AsFloat())) {
160+
if !assert.True(t, trade.Volume.AsFloat() > 0, trade.Volume.AsString()) {
151161
return
152162
}
153163
if !assert.Equal(t, trade.OrderType, model.OrderTypeLimit) {
@@ -169,7 +179,9 @@ func validateTrades(t *testing.T, pair model.TradingPair, trades []model.Trade)
169179
assert.Fail(t, "trade.OrderAction should be either OrderActionBuy or OrderActionSell: %v", trade.OrderAction)
170180
return
171181
}
172-
if !assert.True(t, trade.Cost.AsFloat() > 0, fmt.Sprintf("(price) %s x (volume) %s = (cost) %s", trade.Price.AsString(), trade.Volume.AsString(), trade.Cost.AsString())) {
182+
minPrecision := math.Min(float64(trade.Price.Precision()), float64(trade.Volume.Precision()))
183+
nonZeroCalculatedCost := trade.Price.AsFloat()*trade.Volume.AsFloat() > math.Pow(10, -minPrecision)
184+
if nonZeroCalculatedCost && !assert.True(t, trade.Cost.AsFloat() > 0, fmt.Sprintf("(price) %s x (volume) %s = (cost) %s", trade.Price.AsString(), trade.Volume.AsString(), trade.Cost.AsString())) {
173185
return
174186
}
175187
}
@@ -178,7 +190,7 @@ func validateTrades(t *testing.T, pair model.TradingPair, trades []model.Trade)
178190
func TestGetLatestTradeCursor_Ccxt(t *testing.T) {
179191
for exchangeName, apiKey := range supportedTradingExchanges {
180192
t.Run(exchangeName, func(t *testing.T) {
181-
testCcxtExchange, e := makeCcxtExchange(exchangeName, testOrderConstraints, []api.ExchangeAPIKey{apiKey}, []api.ExchangeParam{emptyParams}, []api.ExchangeHeader{}, false)
193+
testCcxtExchange, e := makeCcxtExchange(exchangeName, testOrderConstraints[exchangeName], []api.ExchangeAPIKey{apiKey}, []api.ExchangeParam{emptyParams}, []api.ExchangeHeader{}, false)
182194
if !assert.NoError(t, e) {
183195
return
184196
}
@@ -217,7 +229,7 @@ func TestGetAccountBalances_Ccxt(t *testing.T) {
217229

218230
for exchangeName, apiKey := range supportedTradingExchanges {
219231
t.Run(exchangeName, func(t *testing.T) {
220-
testCcxtExchange, e := makeCcxtExchange(exchangeName, testOrderConstraints, []api.ExchangeAPIKey{apiKey}, []api.ExchangeParam{emptyParams}, []api.ExchangeHeader{}, false)
232+
testCcxtExchange, e := makeCcxtExchange(exchangeName, testOrderConstraints[exchangeName], []api.ExchangeAPIKey{apiKey}, []api.ExchangeParam{emptyParams}, []api.ExchangeHeader{}, false)
221233
if !assert.NoError(t, e) {
222234
return
223235
}
@@ -262,7 +274,7 @@ func TestGetOpenOrders_Ccxt(t *testing.T) {
262274
for exchangeName, apiKey := range supportedTradingExchanges {
263275
for _, pair := range tradingPairs {
264276
t.Run(exchangeName, func(t *testing.T) {
265-
testCcxtExchange, e := makeCcxtExchange(exchangeName, testOrderConstraints, []api.ExchangeAPIKey{apiKey}, []api.ExchangeParam{emptyParams}, []api.ExchangeHeader{}, false)
277+
testCcxtExchange, e := makeCcxtExchange(exchangeName, testOrderConstraints[exchangeName], []api.ExchangeAPIKey{apiKey}, []api.ExchangeParam{emptyParams}, []api.ExchangeHeader{}, false)
266278
if !assert.NoError(t, e) {
267279
return
268280
}
@@ -377,7 +389,7 @@ func TestAddOrder_Ccxt(t *testing.T) {
377389
},
378390
} {
379391
t.Run(exchangeName, func(t *testing.T) {
380-
testCcxtExchange, e := makeCcxtExchange(exchangeName, testOrderConstraints, []api.ExchangeAPIKey{apiKey}, []api.ExchangeParam{emptyParams}, []api.ExchangeHeader{}, false)
392+
testCcxtExchange, e := makeCcxtExchange(exchangeName, testOrderConstraints[exchangeName], []api.ExchangeAPIKey{apiKey}, []api.ExchangeParam{emptyParams}, []api.ExchangeHeader{}, false)
381393
if !assert.NoError(t, e) {
382394
return
383395
}
@@ -427,7 +439,7 @@ func TestCancelOrder_Ccxt(t *testing.T) {
427439
},
428440
} {
429441
t.Run(exchangeName, func(t *testing.T) {
430-
testCcxtExchange, e := makeCcxtExchange(exchangeName, testOrderConstraints, []api.ExchangeAPIKey{apiKey}, []api.ExchangeParam{emptyParams}, []api.ExchangeHeader{}, false)
442+
testCcxtExchange, e := makeCcxtExchange(exchangeName, testOrderConstraints[exchangeName], []api.ExchangeAPIKey{apiKey}, []api.ExchangeParam{emptyParams}, []api.ExchangeHeader{}, false)
431443
if !assert.NoError(t, e) {
432444
return
433445
}
@@ -473,7 +485,7 @@ func TestGetOrderConstraints_Ccxt_Precision(t *testing.T) {
473485
exchangeName: "binance",
474486
pair: &model.TradingPair{Base: model.XLM, Quote: model.BTC},
475487
wantPricePrecision: 8,
476-
wantVolPrecision: 0,
488+
wantVolPrecision: 8,
477489
},
478490
}
479491

plugins/exchangeFeed.go

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,17 @@ type exchangeFeed struct {
1919
// ensure that it implements PriceFeed
2020
var _ api.PriceFeed = &exchangeFeed{}
2121

22-
func newExchangeFeed(name string, tickerAPI *api.TickerAPI, pair *model.TradingPair, modifier string) *exchangeFeed {
22+
func newExchangeFeed(name string, tickerAPI *api.TickerAPI, pair *model.TradingPair, modifier string) (*exchangeFeed, error) {
23+
if modifier != "mid" && modifier != "ask" && modifier != "bid" && modifier != "last" {
24+
return nil, fmt.Errorf("unsupported modifier '%s' on exchange type URL", modifier)
25+
}
26+
2327
return &exchangeFeed{
2428
name: name,
2529
tickerAPI: tickerAPI,
2630
pairs: []model.TradingPair{*pair},
2731
modifier: modifier,
28-
}
32+
}, nil
2933
}
3034

3135
// GetPrice impl
@@ -41,15 +45,27 @@ func (f *exchangeFeed) GetPrice() (float64, error) {
4145
return 0, fmt.Errorf("could not get price for trading pair: %s", f.pairs[0].String())
4246
}
4347

44-
midPrice := (p.BidPrice.AsFloat() + p.AskPrice.AsFloat()) / 2
45-
var price float64
48+
midPrice := p.BidPrice.Add(*p.AskPrice).Scale(0.5)
49+
var price *model.Number
4650
if f.modifier == "ask" {
47-
price = p.AskPrice.AsFloat()
51+
price = p.AskPrice
4852
} else if f.modifier == "bid" {
49-
price = p.BidPrice.AsFloat()
53+
price = p.BidPrice
54+
} else if f.modifier == "last" {
55+
price = p.LastPrice
5056
} else {
57+
// LOH-2 - support backward-compatible case of defaulting to "mid" price when left unspecified
5158
price = midPrice
5259
}
53-
log.Printf("(modifier: %s) price from exchange feed (%s): bidPrice=%.7f, askPrice=%.7f, midPrice=%.7f; price=%.7f", f.modifier, f.name, p.BidPrice.AsFloat(), p.AskPrice.AsFloat(), midPrice, price)
54-
return price, nil
60+
61+
log.Printf("(modifier: %s) price from exchange feed (%s): bidPrice=%s, askPrice=%s, midPrice=%s, lastTradePrice=%s; price=%s",
62+
f.modifier,
63+
f.name,
64+
p.BidPrice.AsString(),
65+
p.AskPrice.AsString(),
66+
midPrice.AsString(),
67+
p.LastPrice.AsString(),
68+
price.AsString(),
69+
)
70+
return price.AsFloat(), nil
5571
}

plugins/krakenExchange.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,9 @@ func (k *krakenExchange) GetTickerPrice(pairs []model.TradingPair) (map[model.Tr
322322
orderConstraints := k.GetOrderConstraints(&p)
323323
pairTickerInfo := resp.GetPairTickerInfo(pairsMap[p])
324324
priceResult[p] = api.Ticker{
325-
AskPrice: model.MustNumberFromString(pairTickerInfo.Ask[0], orderConstraints.PricePrecision),
326-
BidPrice: model.MustNumberFromString(pairTickerInfo.Bid[0], orderConstraints.PricePrecision),
325+
AskPrice: model.MustNumberFromString(pairTickerInfo.Ask[0], orderConstraints.PricePrecision),
326+
BidPrice: model.MustNumberFromString(pairTickerInfo.Bid[0], orderConstraints.PricePrecision),
327+
LastPrice: model.MustNumberFromString(pairTickerInfo.Close[0], orderConstraints.PricePrecision),
327328
}
328329
}
329330

plugins/krakenExchange_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,20 @@ func TestGetTickerPrice(t *testing.T) {
3535
assert.Equal(t, 1, len(m))
3636

3737
ticker := m[pair]
38-
fmt.Printf("ticker price: bid=%.8f, ask=%.8f\n", ticker.BidPrice.AsFloat(), ticker.AskPrice.AsFloat())
38+
fmt.Printf("ticker price: bid=%s, ask=%s, last=%s\n", ticker.BidPrice.AsString(), ticker.AskPrice.AsString(), ticker.LastPrice.AsString())
3939

4040
if !assert.True(t, ticker.AskPrice.AsFloat() < 1, ticker.AskPrice.AsString()) {
4141
return
4242
}
4343
if !assert.True(t, ticker.BidPrice.AsFloat() < 1, ticker.BidPrice.AsString()) {
4444
return
4545
}
46+
if !assert.True(t, ticker.BidPrice.AsFloat() < ticker.AskPrice.AsFloat(), fmt.Sprintf("bid price (%s) should be less than ask price (%s)", ticker.BidPrice.AsString(), ticker.AskPrice.AsString())) {
47+
return
48+
}
49+
if !assert.True(t, ticker.LastPrice.AsFloat() < 1, ticker.LastPrice.AsString()) {
50+
return
51+
}
4652
}
4753

4854
func TestGetAccountBalances(t *testing.T) {

0 commit comments

Comments
 (0)