This repository has been archived by the owner on Feb 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve precision for BTC markets, can still improve precision furthe…
…r (related to #405)
- Loading branch information
1 parent
b0d8617
commit be1f917
Showing
3 changed files
with
161 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package plugins | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/stellar/go/txnbuild" | ||
"github.com/stellar/kelp/model" | ||
"github.com/stellar/kelp/support/utils" | ||
) | ||
|
||
func TestManageOffer2Order(t *testing.T) { | ||
testCases := []struct { | ||
op *txnbuild.ManageSellOffer | ||
oc *model.OrderConstraints | ||
wantAction model.OrderAction | ||
wantAmount float64 | ||
wantPrice float64 | ||
}{ | ||
{ | ||
op: makeSellOpAmtPrice(0.0018, 50500.0), | ||
oc: model.MakeOrderConstraints(2, 4, 0.001), | ||
wantAction: model.OrderActionSell, | ||
wantAmount: 0.0018, | ||
wantPrice: 50500.0, | ||
}, { | ||
op: makeBuyOpAmtPrice(0.0018, 50500.0), | ||
oc: model.MakeOrderConstraints(2, 4, 0.001), | ||
wantAction: model.OrderActionBuy, | ||
wantAmount: 0.0018, | ||
// 1/50500.0 = 0.000019801980198, we need to reduce it to 7 decimals precision because of sdex op, giving 0.0000198 which when inverted is 50505.05 at price precision = 2 | ||
wantPrice: 50505.05, | ||
}, | ||
} | ||
|
||
for _, k := range testCases { | ||
baseAsset := utils.Asset2Asset2(testBaseAsset) | ||
quoteAsset := utils.Asset2Asset2(testQuoteAsset) | ||
order, e := manageOffer2Order(k.op, baseAsset, quoteAsset, k.oc) | ||
if !assert.NoError(t, e) { | ||
return | ||
} | ||
|
||
assert.Equal(t, k.wantAction, order.OrderAction, fmt.Sprintf("expected '%s' but got '%s'", k.wantAction.String(), order.OrderAction.String())) | ||
assert.Equal(t, k.wantPrice, order.Price.AsFloat()) | ||
assert.Equal(t, k.wantAmount, order.Volume.AsFloat()) | ||
} | ||
} |