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

Commit

Permalink
add FILL_TRACKER_LAST_TRADE_CURSOR_OVERRIDE config
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilsaraf committed Jan 18, 2020
1 parent db4531d commit 4c19915
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
9 changes: 8 additions & 1 deletion cmd/trade.go
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,14 @@ func startFillTracking(
}

if botConfig.FillTrackerSleepMillis != 0 {
fillTracker := plugins.MakeFillTracker(tradingPair, threadTracker, exchangeShim, botConfig.FillTrackerSleepMillis, botConfig.FillTrackerDeleteCyclesThreshold)
var lastTradeCursorOverride interface{}
if botConfig.FillTrackerLastTradeCursorOverride == "" {
lastTradeCursorOverride = nil
} else {
lastTradeCursorOverride = botConfig.FillTrackerLastTradeCursorOverride
}

fillTracker := plugins.MakeFillTracker(tradingPair, threadTracker, exchangeShim, botConfig.FillTrackerSleepMillis, botConfig.FillTrackerDeleteCyclesThreshold, lastTradeCursorOverride)
fillLogger := plugins.MakeFillLogger()
fillTracker.RegisterHandler(fillLogger)
if db != nil {
Expand Down
2 changes: 2 additions & 0 deletions examples/configs/trader/sample_trader.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ FILL_TRACKER_SLEEP_MILLIS=0
# example: use 0 if you want to delete all offers on any error.
# example: use 2 if you want to tolerate 2 continuous cycles with errors, i.e. 3 continuous cycles with errors will delete all offers.
FILL_TRACKER_DELETE_CYCLES_THRESHOLD=0
# uncomment if we want to override what is used as the last trade cursor when loading filled trades
#FILL_TRACKER_LAST_TRADE_CURSOR_OVERRIDE="1570415431000"
# the url for your horizon instance. If this url contains the string "test" then the bot assumes it is using the test network.
HORIZON_URL="https://horizon-testnet.stellar.org"

Expand Down
15 changes: 11 additions & 4 deletions plugins/fillTracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type FillTracker struct {
fillTrackable api.FillTrackable
fillTrackerSleepMillis uint32
fillTrackerDeleteCyclesThreshold int64
lastTradeCursorOverride interface{}

// initialized runtime vars
fillTrackerDeleteCycles int64
Expand All @@ -36,13 +37,15 @@ func MakeFillTracker(
fillTrackable api.FillTrackable,
fillTrackerSleepMillis uint32,
fillTrackerDeleteCyclesThreshold int64,
lastTradeCursorOverride interface{},
) api.FillTracker {
return &FillTracker{
pair: pair,
threadTracker: threadTracker,
fillTrackable: fillTrackable,
fillTrackerSleepMillis: fillTrackerSleepMillis,
fillTrackerDeleteCyclesThreshold: fillTrackerDeleteCyclesThreshold,
lastTradeCursorOverride: lastTradeCursorOverride,
// initialized runtime vars
fillTrackerDeleteCycles: 0,
}
Expand Down Expand Up @@ -72,10 +75,14 @@ func (f *FillTracker) countError() bool {

// TrackFills impl
func (f *FillTracker) TrackFills() error {
// get the last cursor so we only start querying from the current position
lastCursor, e := f.fillTrackable.GetLatestTradeCursor()
if e != nil {
return fmt.Errorf("error while getting last trade: %s", e)
lastCursor := f.lastTradeCursorOverride
if lastCursor == nil {
// get the last cursor so we only start querying from the current position
var e error
lastCursor, e = f.fillTrackable.GetLatestTradeCursor()
if e != nil {
return fmt.Errorf("error while getting last trade: %s", e)
}
}
log.Printf("got latest trade cursor from where to start tracking fills: %v\n", lastCursor)

Expand Down
1 change: 1 addition & 0 deletions trader/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type BotConfig struct {
SubmitMode string `valid:"-" toml:"SUBMIT_MODE" json:"submit_mode"`
FillTrackerSleepMillis uint32 `valid:"-" toml:"FILL_TRACKER_SLEEP_MILLIS" json:"fill_tracker_sleep_millis"`
FillTrackerDeleteCyclesThreshold int64 `valid:"-" toml:"FILL_TRACKER_DELETE_CYCLES_THRESHOLD" json:"fill_tracker_delete_cycles_threshold"`
FillTrackerLastTradeCursorOverride string `valid:"-" toml:"FILL_TRACKER_LAST_TRADE_CURSOR_OVERRIDE"`
HorizonURL string `valid:"-" toml:"HORIZON_URL" json:"horizon_url"`
CcxtRestURL *string `valid:"-" toml:"CCXT_REST_URL" json:"ccxt_rest_url"`
Fee *FeeConfig `valid:"-" toml:"FEE" json:"fee"`
Expand Down

0 comments on commit 4c19915

Please sign in to comment.