forked from stellar-deprecated/kelp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sellStrategy.go
65 lines (60 loc) · 1.82 KB
/
sellStrategy.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
package plugins
import (
"github.com/lightyeario/kelp/api"
"github.com/lightyeario/kelp/support/utils"
"github.com/stellar/go/clients/horizon"
)
// sellConfig contains the configuration params for this Strategy
type sellConfig struct {
DATA_TYPE_A string `valid:"-"`
DATA_FEED_A_URL string `valid:"-"`
DATA_TYPE_B string `valid:"-"`
DATA_FEED_B_URL string `valid:"-"`
PRICE_TOLERANCE float64 `valid:"-"`
AMOUNT_TOLERANCE float64 `valid:"-"`
AMOUNT_OF_A_BASE float64 `valid:"-"` // the size of order
RATE_OFFSET_PERCENT float64 `valid:"-"`
RATE_OFFSET float64 `valid:"-"`
RATE_OFFSET_PERCENT_FIRST bool `valid:"-"`
LEVELS []staticLevel `valid:"-"`
}
// String impl.
func (c sellConfig) String() string {
return utils.StructString(c, nil)
}
// makeSellStrategy is a factory method for SellStrategy
func makeSellStrategy(
sdex *SDEX,
assetBase *horizon.Asset,
assetQuote *horizon.Asset,
config *sellConfig,
) api.Strategy {
pf := MakeFeedPair(
config.DATA_TYPE_A,
config.DATA_FEED_A_URL,
config.DATA_TYPE_B,
config.DATA_FEED_B_URL,
)
offset := rateOffset{
percent: config.RATE_OFFSET_PERCENT,
absolute: config.RATE_OFFSET,
percentFirst: config.RATE_OFFSET_PERCENT_FIRST,
}
sellSideStrategy := makeSellSideStrategy(
sdex,
assetBase,
assetQuote,
makeStaticSpreadLevelProvider(config.LEVELS, config.AMOUNT_OF_A_BASE, offset, pf),
config.PRICE_TOLERANCE,
config.AMOUNT_TOLERANCE,
false,
)
// switch sides of base/quote here for the delete side
deleteSideStrategy := makeDeleteSideStrategy(sdex, assetQuote, assetBase)
return makeComposeStrategy(
assetBase,
assetQuote,
deleteSideStrategy,
sellSideStrategy,
)
}