From 9062d7d01904990ff8690932f3702023b27e491e Mon Sep 17 00:00:00 2001 From: Nikhil Saraf <1028334+nikhilsaraf@users.noreply.github.com> Date: Fri, 10 Jan 2020 23:39:01 +0530 Subject: [PATCH] add "daily" param in the volume filter string to allow future improvments with the same interface --- examples/configs/trader/sample_trader.cfg | 4 ++-- plugins/filterFactory.go | 15 +++++++++------ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/examples/configs/trader/sample_trader.cfg b/examples/configs/trader/sample_trader.cfg index 82d561744..df6a58455 100644 --- a/examples/configs/trader/sample_trader.cfg +++ b/examples/configs/trader/sample_trader.cfg @@ -103,7 +103,7 @@ HORIZON_URL="https://horizon-testnet.stellar.org" # # - "ignore" indicates that the volume filter should not modify the values of any offer and the offer which will cause # # the capacity limit to be exceeded should be dropped or ignored. This will result in a less than or equal amount # # of the asset to be sold for the given day. -# "volume/sell/base/3500.0/exact", +# "volume/daily/sell/base/3500.0/exact", # # # limit the amount of the base asset that is sold every day, denominated in units of the quote asset (needs POSTGRES_DB) # # The fifth param can be either "exact" or "ignore" ("exact" is recommended): @@ -113,7 +113,7 @@ HORIZON_URL="https://horizon-testnet.stellar.org" # # - "ignore" indicates that the volume filter should not modify the values of any offer and the offer which will cause # # the capacity limit to be exceeded should be dropped or ignored. This will result in a less than or equal amount # # of the asset to be sold for the given day. -# "volume/sell/quote/1000.0/ignore", +# "volume/daily/sell/quote/1000.0/ignore", # # # limit offers based on a minimim price requirement # "price/min/0.04", diff --git a/plugins/filterFactory.go b/plugins/filterFactory.go index c42c26a2e..aefb250c1 100644 --- a/plugins/filterFactory.go +++ b/plugins/filterFactory.go @@ -44,11 +44,11 @@ func (f *FilterFactory) MakeFilter(configInput string) (SubmitFilter, error) { func filterVolume(f *FilterFactory, configInput string) (SubmitFilter, error) { parts := strings.Split(configInput, "/") - if len(parts) != 5 { - return nil, fmt.Errorf("invalid input (%s), needs 5 parts separated by the delimiter (/)", configInput) + if len(parts) != 6 { + return nil, fmt.Errorf("invalid input (%s), needs 6 parts separated by the delimiter (/)", configInput) } - mode, e := parseVolumeFilterMode(parts[4]) + mode, e := parseVolumeFilterMode(parts[5]) if e != nil { return nil, fmt.Errorf("could not parse volume filter mode from input (%s): %s", configInput, e) } @@ -56,13 +56,16 @@ func filterVolume(f *FilterFactory, configInput string) (SubmitFilter, error) { if parts[1] != "sell" { return nil, fmt.Errorf("invalid input (%s), the second part needs to be \"sell\"", configInput) } - limit, e := strconv.ParseFloat(parts[3], 64) + if parts[2] != "daily" { + return nil, fmt.Errorf("invalid input (%s), the third part needs to be \"daily\"", configInput) + } + limit, e := strconv.ParseFloat(parts[4], 64) if e != nil { return nil, fmt.Errorf("could not parse the fourth part as a float value from config value (%s): %s", configInput, e) } - if parts[2] == "base" { + if parts[3] == "base" { config.SellBaseAssetCapInBaseUnits = &limit - } else if parts[2] == "quote" { + } else if parts[3] == "quote" { config.SellBaseAssetCapInQuoteUnits = &limit } else { return nil, fmt.Errorf("invalid input (%s), the third part needs to be \"base\" or \"quote\"", configInput)