-
Notifications
You must be signed in to change notification settings - Fork 0
/
order.go
54 lines (49 loc) · 1.93 KB
/
order.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
package app
// This file includes clob helpers used in the end-to-end test suites. Functions here cannot live in
// protocol/testutil/clob because they depend on the TestApp struct, and would create an import cycle.
import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/furyanprotocol/v4-chain/protocol/app"
"github.com/furyanprotocol/v4-chain/protocol/lib"
clobtest "github.com/furyanprotocol/v4-chain/protocol/testutil/clob"
perptest "github.com/furyanprotocol/v4-chain/protocol/testutil/perpetuals"
pricestest "github.com/furyanprotocol/v4-chain/protocol/testutil/prices"
clobtypes "github.com/furyanprotocol/v4-chain/protocol/x/clob/types"
pricestypes "github.com/furyanprotocol/v4-chain/protocol/x/prices/types"
)
// Subsitute quantums and subticks with value converted from human readable price and amount.
func MustMakeOrderFromHumanInput(
ctx sdk.Context,
app *app.App,
order clobtypes.Order,
humanPrice string,
humanSize string,
) clobtypes.Order {
clobPair, exists := app.ClobKeeper.GetClobPair(ctx, clobtypes.ClobPairId(order.OrderId.ClobPairId))
if !exists {
panic(fmt.Sprintf("clobPair does not exist: %v", order.OrderId.ClobPairId))
}
perp, err := app.PerpetualsKeeper.GetPerpetual(ctx, clobtest.MustPerpetualId(clobPair))
if err != nil {
panic(err)
}
baseQuantums := perptest.MustHumanSizeToBaseQuantums(humanSize, perp.Params.AtomicResolution)
order.Quantums = baseQuantums
marketParams, exists := app.PricesKeeper.GetMarketParam(ctx, perp.Params.MarketId)
if !exists {
panic(fmt.Sprintf("marketParam does not exist: %v", perp.Params.MarketId))
}
marketPrice := pricestest.MustHumanPriceToMarketPrice(humanPrice, marketParams.Exponent)
subticks := clobtypes.PriceToSubticks(
pricestypes.MarketPrice{
Price: marketPrice,
Exponent: marketParams.Exponent,
},
clobPair,
perp.Params.AtomicResolution,
lib.QuoteCurrencyAtomicResolution,
)
order.Subticks = subticks.Num().Uint64()
return order
}