forked from stellar-deprecated/kelp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsellStrategy.go
76 lines (68 loc) · 2.29 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
66
67
68
69
70
71
72
73
74
75
76
package plugins
import (
"fmt"
"github.com/stellar/kelp/model"
"github.com/stellar/go/clients/horizon"
"github.com/stellar/kelp/api"
"github.com/stellar/kelp/support/utils"
)
// sellConfig contains the configuration params for this Strategy
type sellConfig struct {
DataTypeA string `valid:"-" toml:"DATA_TYPE_A"`
DataFeedAURL string `valid:"-" toml:"DATA_FEED_A_URL"`
DataTypeB string `valid:"-" toml:"DATA_TYPE_B"`
DataFeedBURL string `valid:"-" toml:"DATA_FEED_B_URL"`
PriceTolerance float64 `valid:"-" toml:"PRICE_TOLERANCE"`
AmountTolerance float64 `valid:"-" toml:"AMOUNT_TOLERANCE"`
AmountOfABase float64 `valid:"-" toml:"AMOUNT_OF_A_BASE"` // the size of order
RateOffsetPercent float64 `valid:"-" toml:"RATE_OFFSET_PERCENT"`
RateOffset float64 `valid:"-" toml:"RATE_OFFSET"`
RateOffsetPercentFirst bool `valid:"-" toml:"RATE_OFFSET_PERCENT_FIRST"`
Levels []staticLevel `valid:"-" toml:"LEVELS"`
}
// String impl.
func (c sellConfig) String() string {
return utils.StructString(c, nil)
}
// makeSellStrategy is a factory method for SellStrategy
func makeSellStrategy(
sdex *SDEX,
pair *model.TradingPair,
assetBase *horizon.Asset,
assetQuote *horizon.Asset,
config *sellConfig,
) (api.Strategy, error) {
pf, e := MakeFeedPair(
config.DataTypeA,
config.DataFeedAURL,
config.DataTypeB,
config.DataFeedBURL,
)
if e != nil {
return nil, fmt.Errorf("cannot make the sell strategy because we could not make the feed pair: %s", e)
}
orderConstraints := sdex.GetOrderConstraints(pair)
offset := rateOffset{
percent: config.RateOffsetPercent,
absolute: config.RateOffset,
percentFirst: config.RateOffsetPercentFirst,
}
sellSideStrategy := makeSellSideStrategy(
sdex,
orderConstraints,
assetBase,
assetQuote,
makeStaticSpreadLevelProvider(config.Levels, config.AmountOfABase, offset, pf, orderConstraints),
config.PriceTolerance,
config.AmountTolerance,
false,
)
// switch sides of base/quote here for the delete side
deleteSideStrategy := makeDeleteSideStrategy(sdex, assetQuote, assetBase)
return makeComposeStrategy(
assetBase,
assetQuote,
deleteSideStrategy,
sellSideStrategy,
), nil
}