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

Commit b6eb041

Browse files
authored
Fix cursor and cost param in trade parsing and ccxtExchange_test (#332)
* 1 - fix Cursor check in TestGetTrades_Ccxt * 2 - fix Cost assignment in trades along with validateTrades()
1 parent f942cf8 commit b6eb041

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

plugins/ccxtExchange.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package plugins
33
import (
44
"fmt"
55
"log"
6+
"math"
67
"sort"
78
"strconv"
89
"time"
@@ -300,6 +301,7 @@ func (c ccxtExchange) readTrade(pair *model.TradingPair, pairString string, rawT
300301
Timestamp: model.MakeTimestamp(rawTrade.Timestamp),
301302
},
302303
TransactionID: model.MakeTransactionID(rawTrade.ID),
304+
Cost: model.NumberFromFloat(rawTrade.Cost, int8(math.Max(float64(pricePrecision), float64(volumePrecision)))),
303305
Fee: model.NumberFromFloat(rawTrade.Fee.Cost, feecCostPrecision),
304306
}
305307

plugins/ccxtExchange_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ func TestGetTrades_Ccxt(t *testing.T) {
102102
if !assert.NoError(t, e) {
103103
return
104104
}
105-
assert.Equal(t, nil, tradeResult.Cursor)
105+
wantCursorInt64 := tradeResult.Trades[len(tradeResult.Trades)-1].Timestamp.AsInt64() + 1
106+
assert.Equal(t, strconv.FormatInt(wantCursorInt64, 10), tradeResult.Cursor)
106107

107108
validateTrades(t, pair, tradeResult.Trades)
108109
})
@@ -158,14 +159,17 @@ func validateTrades(t *testing.T, pair model.TradingPair, trades []model.Trade)
158159
if !assert.NotNil(t, trade.TransactionID) {
159160
return
160161
}
162+
if !assert.NotNil(t, trade.Cost) {
163+
return
164+
}
161165
if !assert.NotNil(t, trade.Fee) {
162166
return
163167
}
164168
if trade.OrderAction != model.OrderActionBuy && trade.OrderAction != model.OrderActionSell {
165169
assert.Fail(t, "trade.OrderAction should be either OrderActionBuy or OrderActionSell: %v", trade.OrderAction)
166170
return
167171
}
168-
if trade.Cost != nil && !assert.True(t, trade.Cost.AsFloat() > 0, fmt.Sprintf("%s x %s = %s", trade.Price.AsString(), trade.Volume.AsString(), trade.Cost.AsString())) {
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())) {
169173
return
170174
}
171175
}

0 commit comments

Comments
 (0)