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

Maker only mode #101

Merged
merged 30 commits into from
Feb 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
2a9f13e
1 - added support for submit mode
nikhilsaraf Jan 16, 2019
ce30d6b
2 - framework support for submit filters
nikhilsaraf Jan 16, 2019
14b4390
t - started implementing sdex filter
nikhilsaraf Jan 17, 2019
68efa68
A - started actual logic of maker mode
nikhilsaraf Jan 18, 2019
51535dc
B
nikhilsaraf Jan 19, 2019
9e53a0c
C
nikhilsaraf Jan 19, 2019
246c9b5
D - untested impl. of shouldKeepOfferMakerMode using topBid/topAsk pr…
nikhilsaraf Jan 23, 2019
f71861d
E - temp refactored to accommodate for transformOfferTakerMode
nikhilsaraf Jan 23, 2019
d4e4666
F only do maker_only mode for now
nikhilsaraf Jan 24, 2019
d87971b
G - convert ops to dropped state (modify to delete op etc.)
nikhilsaraf Jan 24, 2019
cda3a26
H - fix keep logic to count dropped correctly, actually return filter…
nikhilsaraf Jan 24, 2019
6d99478
fix usage of deleteAllOffersAndExit in trade.go
nikhilsaraf Jan 31, 2019
bd79d18
TODO testing
nikhilsaraf Jan 24, 2019
fd90938
fix TODO price when logging
nikhilsaraf Jan 31, 2019
8b73354
incorporate get orderbook call into submitMode's sdexMaker filter
nikhilsaraf Jan 31, 2019
5bbd9ee
default submitMode to empty string
nikhilsaraf Jan 31, 2019
72b2db5
remove numDropped var
nikhilsaraf Jan 31, 2019
6da6162
Revert "remove numDropped var"
nikhilsaraf Jan 31, 2019
7b38d7a
count numTransformed ops, including in list of ops to be submitted
nikhilsaraf Jan 31, 2019
5c96250
log num kept ops
nikhilsaraf Jan 31, 2019
f451ca5
1
nikhilsaraf Jan 31, 2019
cf5262f
2
nikhilsaraf Jan 31, 2019
0694fbd
3 - remove redundant trading account
nikhilsaraf Feb 1, 2019
ecf92e3
4 - untested logic for getting top price excluding trader's offers
nikhilsaraf Feb 1, 2019
2382ac3
5 - log keep value
nikhilsaraf Feb 2, 2019
9cc1a87
6 cleanup
nikhilsaraf Feb 2, 2019
c372fca
7 - cleanup logging of sdexMakerFilter
nikhilsaraf Feb 2, 2019
556c158
8 - new files
nikhilsaraf Feb 2, 2019
6c41262
9 remove TODOs
nikhilsaraf Feb 2, 2019
9c3dade
10 resolve compile errors after moving to api/plugins
nikhilsaraf Feb 2, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions api/submitMode.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package api

import (
"fmt"
)

// SubmitMode is the type of mode to be used when submitting orders to the trader bot
type SubmitMode uint8

// constants for the SubmitMode
const (
SubmitModeMakerOnly SubmitMode = iota
SubmitModeBoth
)

// ParseSubmitMode converts a string to the SubmitMode constant
func ParseSubmitMode(submitMode string) (SubmitMode, error) {
if submitMode == "maker_only" {
return SubmitModeMakerOnly, nil
} else if submitMode == "both" || submitMode == "" {
return SubmitModeBoth, nil
}

return SubmitModeBoth, fmt.Errorf("unable to parse submit mode: %s", submitMode)
}

func (s *SubmitMode) String() string {
if *s == SubmitModeMakerOnly {
return "maker_only"
}

return "both"
}
10 changes: 10 additions & 0 deletions cmd/trade.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strings"
"time"

"github.com/interstellar/kelp/api"
"github.com/interstellar/kelp/model"
"github.com/interstellar/kelp/plugins"
"github.com/interstellar/kelp/support/logger"
Expand Down Expand Up @@ -181,6 +182,13 @@ func init() {
deleteAllOffersAndExit(l, botConfig, client, sdex)
}

submitMode, e := api.ParseSubmitMode(botConfig.SubmitMode)
if e != nil {
log.Println()
log.Println(e)
// we want to delete all the offers and exit here since there is something wrong with our setup
deleteAllOffersAndExit(l, botConfig, client, sdex)
}
timeController := plugins.MakeIntervalTimeController(
time.Duration(botConfig.TickIntervalSeconds)*time.Second,
botConfig.MaxTickDelayMillis,
Expand All @@ -189,11 +197,13 @@ func init() {
client,
botConfig.AssetBase(),
botConfig.AssetQuote(),
tradingPair,
botConfig.TradingAccount(),
sdex,
strat,
timeController,
botConfig.DeleteCyclesThreshold,
submitMode,
threadTracker,
fixedIterations,
dataKey,
Expand Down
3 changes: 3 additions & 0 deletions examples/configs/trader/sample_trader.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ TICK_INTERVAL_SECONDS=300
# randomized interval delay in millis
MAX_TICK_DELAY_MILLIS=0

# the mode to use when submitting - maker_only, both (default)
SUBMIT_MODE="both"

# how many continuous errors in each update cycle can the bot accept before it will delete all offers to protect its exposure.
# this number has to be exceeded for all the offers to be deleted and any error will be counted only once per update cycle.
# any time the bot completes a full run successfully this counter will be reset.
Expand Down
16 changes: 16 additions & 0 deletions model/orderbook.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,22 @@ func (o OrderBook) Bids() []Order {
return o.bids
}

// TopAsk returns the best ask in an orderbook
func (o OrderBook) TopAsk() *Order {
if len(o.Asks()) > 0 {
return &o.Asks()[0]
}
return nil
}

// TopBid returns the best bid in an orderbook
func (o OrderBook) TopBid() *Order {
if len(o.Bids()) > 0 {
return &o.Bids()[0]
}
return nil
}

// MakeOrderBook creates a new OrderBook from the asks and the bids
func MakeOrderBook(pair *TradingPair, asks []Order, bids []Order) *OrderBook {
return &OrderBook{
Expand Down
9 changes: 5 additions & 4 deletions plugins/sdex.go
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,8 @@ func (sdex *SDEX) _liabilities(asset horizon.Asset, otherAsset horizon.Asset) (*
return &liabilities, &pairLiabilities, nil
}

func (sdex *SDEX) pair2Assets() (baseAsset horizon.Asset, quoteAsset horizon.Asset, e error) {
// Assets returns the base and quote asset used by sdex
func (sdex *SDEX) Assets() (baseAsset horizon.Asset, quoteAsset horizon.Asset, e error) {
var ok bool
baseAsset, ok = sdex.assetMap[sdex.pair.Base]
if !ok {
Expand All @@ -652,7 +653,7 @@ func (sdex *SDEX) GetTradeHistory(pair model.TradingPair, maybeCursorStart inter
return nil, fmt.Errorf("passed in pair (%s) did not match sdex.pair (%s)", pair.String(), sdex.pair.String())
}

baseAsset, quoteAsset, e := sdex.pair2Assets()
baseAsset, quoteAsset, e := sdex.Assets()
if e != nil {
return nil, fmt.Errorf("error while converting pair to base and quote asset: %s", e)
}
Expand Down Expand Up @@ -796,7 +797,7 @@ func (sdex *SDEX) tradesPage2TradeHistoryResult(baseAsset horizon.Asset, quoteAs

// GetLatestTradeCursor impl.
func (sdex *SDEX) GetLatestTradeCursor() (interface{}, error) {
baseAsset, quoteAsset, e := sdex.pair2Assets()
baseAsset, quoteAsset, e := sdex.Assets()
if e != nil {
return nil, fmt.Errorf("error while convertig pair to base and quote asset: %s", e)
}
Expand All @@ -821,7 +822,7 @@ func (sdex *SDEX) GetOrderBook(pair *model.TradingPair, maxCount int32) (*model.
return nil, fmt.Errorf("unregistered trading pair (%s) cannot be converted to horizon.Assets, instance's pair: %s", pair.String(), sdex.pair.String())
}

baseAsset, quoteAsset, e := sdex.pair2Assets()
baseAsset, quoteAsset, e := sdex.Assets()
if e != nil {
return nil, fmt.Errorf("cannot get SDEX orderbook: %s", e)
}
Expand Down
Loading