forked from stellar-deprecated/kelp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuyTwapStrategy.go
78 lines (70 loc) · 1.94 KB
/
buyTwapStrategy.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
77
78
package plugins
import (
"fmt"
"time"
hProtocol "github.com/stellar/go/protocols/horizon"
"github.com/stellar/kelp/api"
"github.com/stellar/kelp/model"
)
// makeBuyTwapStrategy is a factory method for BuyTwapStrategy
func makeBuyTwapStrategy(
sdex *SDEX,
pair *model.TradingPair,
ieif *IEIF,
assetBase *hProtocol.Asset,
assetQuote *hProtocol.Asset,
filterFactory *FilterFactory,
config *sellTwapConfig,
) (api.Strategy, error) {
startPf, e := MakePriceFeed(config.StartAskFeedType, config.StartAskFeedURL)
if e != nil {
return nil, fmt.Errorf("error when making the start priceFeed: %s", e)
}
orderConstraints := sdex.GetOrderConstraints(pair)
offset := rateOffset{
percent: config.RateOffsetPercent,
absolute: config.RateOffset,
percentFirst: config.RateOffsetPercentFirst,
}
dowFilter, e := makeDowFilter(filterFactory, config.DayOfWeekDailyCap)
if e != nil {
return nil, fmt.Errorf("error when making dowFilter: %s", e)
}
levelProvider, e := makeSellTwapLevelProvider(
startPf,
offset,
orderConstraints,
dowFilter,
config.NumHoursToSell,
config.ParentBucketSizeSeconds,
config.DistributeSurplusOverRemainingIntervalsPercentCeiling,
config.ExponentialSmoothingFactor,
config.MinChildOrderSizePercentOfParent,
time.Now().UnixNano(),
true,
)
if e != nil {
return nil, fmt.Errorf("error when making a sellTwapLevelProvider: %s", e)
}
// switch sides of base/quote here for buy side
buySideStrategy := makeSellSideStrategy(
sdex,
orderConstraints,
ieif,
assetQuote,
assetBase,
levelProvider,
config.PriceTolerance,
config.AmountTolerance,
true,
)
// use assetBase as param to assetBase argument, since the delete strategy is
// on the sell side. so the params should line up correctly with the arguments
deleteSideStrategy := makeDeleteSideStrategy(sdex, assetBase, assetQuote)
return makeComposeStrategy(
assetBase,
assetQuote,
buySideStrategy,
deleteSideStrategy,
), nil
}