forked from stellar-deprecated/kelp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuysellStrategy.go
94 lines (88 loc) · 2.32 KB
/
buysellStrategy.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package plugins
import (
"github.com/lightyeario/kelp/api"
"github.com/lightyeario/kelp/support/utils"
"github.com/stellar/go/clients/horizon"
)
// buySellConfig contains the configuration params for this strategy
type buySellConfig struct {
PRICE_TOLERANCE float64 `valid:"-"`
AMOUNT_TOLERANCE float64 `valid:"-"`
RATE_OFFSET_PERCENT float64 `valid:"-"`
RATE_OFFSET float64 `valid:"-"`
RATE_OFFSET_PERCENT_FIRST bool `valid:"-"`
AMOUNT_OF_A_BASE float64 `valid:"-"` // the size of order to keep on either side
DATA_TYPE_A string `valid:"-"`
DATA_FEED_A_URL string `valid:"-"`
DATA_TYPE_B string `valid:"-"`
DATA_FEED_B_URL string `valid:"-"`
LEVELS []staticLevel `valid:"-"`
}
// String impl.
func (c buySellConfig) String() string {
return utils.StructString(c, nil)
}
// makeBuySellStrategy is a factory method
func makeBuySellStrategy(
sdex *SDEX,
assetBase *horizon.Asset,
assetQuote *horizon.Asset,
config *buySellConfig,
) api.Strategy {
offsetSell := 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,
offsetSell,
MakeFeedPair(
config.DATA_TYPE_A,
config.DATA_FEED_A_URL,
config.DATA_TYPE_B,
config.DATA_FEED_B_URL,
),
),
config.PRICE_TOLERANCE,
config.AMOUNT_TOLERANCE,
false,
)
offsetBuy := rateOffset{
percent: config.RATE_OFFSET_PERCENT,
absolute: config.RATE_OFFSET,
percentFirst: config.RATE_OFFSET_PERCENT_FIRST,
invert: true,
}
// switch sides of base/quote here for buy side
buySideStrategy := makeSellSideStrategy(
sdex,
assetQuote,
assetBase,
makeStaticSpreadLevelProvider(
config.LEVELS,
config.AMOUNT_OF_A_BASE,
offsetBuy,
MakeFeedPair(
config.DATA_TYPE_B,
config.DATA_FEED_B_URL,
config.DATA_TYPE_A,
config.DATA_FEED_A_URL,
),
),
config.PRICE_TOLERANCE,
config.AMOUNT_TOLERANCE,
true,
)
return makeComposeStrategy(
assetBase,
assetQuote,
buySideStrategy,
sellSideStrategy,
)
}