Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
volumeFilter should be configurable to include "exact" amounts (closes
Browse files Browse the repository at this point in the history
…#327) (#328)

* 1 - add exact and ignore params to the volume filter in sample_trader.cfg

* 2 - read in exact/ignore mode to volume filter config

* 3 - implement exact mode in volumeFilter

* 4 - update filterOps to correctly count kept vs. transformed operations with the newly added capability in volumeFilter

* 5 - separate out handling for non-offer-ops which makes things a little simpler with typing

* 6 - remove TODO about this issue form volumeFilter

* 7 - fix big bug which resulted in submission failures (non-increment of index)

* 8 - update comment

* 9 - add comment to filterOps about "no update operations problem"

* 10 - refactor filterOps: add "ignored" field to filterCounter for buy/sell offers

* 11 - refactor filterOps: fold original amount and price into originalMSO variable

* 12 - refactor filterOps: extract out selectBuySellList and selectOpOrOffer

* 13 - refactor filterOps: extract out logic that handles calling and result of the filterFn for reuse

* 14 - fix bug with originalMSO getting modified along with newOp

* 15 - refactor filterOps: add fix to handle remainingOffers correctly with common function for buy/sell sides

includes logic to ignore offers in ignore list

* 16 - moved exchange constraints filter to be last
  • Loading branch information
nikhilsaraf authored Jan 2, 2020
1 parent 116f7d1 commit 66ea610
Show file tree
Hide file tree
Showing 5 changed files with 327 additions and 128 deletions.
9 changes: 6 additions & 3 deletions cmd/trade.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,7 @@ func makeBot(
}

// start make filters
submitFilters := []plugins.SubmitFilter{
plugins.MakeFilterOrderConstraints(exchangeShim.GetOrderConstraints(tradingPair), assetBase, assetQuote),
}
submitFilters := []plugins.SubmitFilter{}
if submitMode == api.SubmitModeMakerOnly {
submitFilters = append(submitFilters,
plugins.MakeFilterMakerMode(exchangeShim, sdex, tradingPair),
Expand Down Expand Up @@ -389,6 +387,11 @@ func makeBot(
}
submitFilters = append(submitFilters, filter)
}
// exchange constraints filter is last so we catch any modifications made by previous filters. this ensures that the exchange is
// less likely to reject our updates
submitFilters = append(submitFilters,
plugins.MakeFilterOrderConstraints(exchangeShim.GetOrderConstraints(tradingPair), assetBase, assetQuote),
)
// end make filters

return trader.MakeTrader(
Expand Down
18 changes: 16 additions & 2 deletions examples/configs/trader/sample_trader.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,24 @@ HORIZON_URL="https://horizon-testnet.stellar.org"
# the best way to use these filters is to uncomment the one you want to use and update the price (last param) accordingly.
#FILTERS = [
# # limit the amount of the base asset that is sold every day, denominated in units of the base asset (needs POSTGRES_DB)
# "volume/sell/base/3500.0",
# # The fifth param can be either "exact" or "ignore" ("exact" is recommended):
# # - "exact" indicates that the volume filter should modify the amount of the offer that will cause the capacity limit
# # to be exceeded (when daily sold amounts are close to the limit). This will result in the exact number of units of
# # the asset to be sold for the given day.
# # - "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",
#
# # limit the amount of the base asset that is sold every day, denominated in units of the quote asset (needs POSTGRES_DB)
# "volume/sell/quote/1000.0",
# # The fifth param can be either "exact" or "ignore" ("exact" is recommended):
# # - "exact" indicates that the volume filter should modify the amount of the offer that will cause the capacity limit
# # to be exceeded (when daily sold amounts are close to the limit). This will result in the exact number of units of
# # the asset to be sold for the given day.
# # - "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",
#
# # limit offers based on a minimim price requirement
# "price/min/0.04",
Expand Down
10 changes: 7 additions & 3 deletions plugins/filterFactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,15 @@ func (f *FilterFactory) MakeFilter(configInput string) (SubmitFilter, error) {

func filterVolume(f *FilterFactory, configInput string) (SubmitFilter, error) {
parts := strings.Split(configInput, "/")
if len(parts) != 4 {
return nil, fmt.Errorf("invalid input (%s), needs 4 parts separated by the delimiter (/)", configInput)
if len(parts) != 5 {
return nil, fmt.Errorf("invalid input (%s), needs 5 parts separated by the delimiter (/)", configInput)
}

config := &VolumeFilterConfig{}
mode, e := parseVolumeFilterMode(parts[4])
if e != nil {
return nil, fmt.Errorf("could not parse volume filter mode from input (%s): %s", configInput, e)
}
config := &VolumeFilterConfig{mode: mode}
if parts[1] != "sell" {
return nil, fmt.Errorf("invalid input (%s), the second part needs to be \"sell\"", configInput)
}
Expand Down
Loading

0 comments on commit 66ea610

Please sign in to comment.