Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BEP67 Price-based Order Expiration #704

Merged
merged 1 commit into from
Apr 22, 2020
Merged

BEP67 Price-based Order Expiration #704

merged 1 commit into from
Apr 22, 2020

Conversation

EnderCrypto
Copy link
Contributor

@EnderCrypto EnderCrypto commented Mar 9, 2020

Description

expiration time unchanged (3 days), but keep orders in the best 500 price levels on both ask and bid for at most 1 month.

Rationale

tell us why we need these changes...

Some users want to keep their open orders more than 3 days.
add a way user can extend the order life to stay longer than 72 hours

add an example CLI or API response...

Changes

Notable changes:

  • Add RemoveOrdersBiasedly in Orderbook for the new expire order approach

Preflight checks

  • build passed (make build)
  • tests passed (make test)
  • integration tests passed (make integration_test)
  • manual transaction test passed (cli invoke)

Already reviewed by

...

Related issues

... reference related issue #'s here ...

@EnderCrypto EnderCrypto changed the base branch from master to develop March 9, 2020 15:44
@@ -433,3 +433,51 @@ func (ull *ULList) UpdateForEach(updater LevelIter) {
b = oldNext
}
}

func (ull *ULList) UpdateForEachBiasedly(preferenceSize int, preferenceUpdater LevelIter, updater LevelIter) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we reuse the original UpdateForEach, I think we can change the updater function itself.

@@ -190,7 +190,7 @@ func (overlapped *OverLappedLevel) HasSellTaker() bool {
return overlapped.SellTakerStartIdx < len(overlapped.SellOrders)
}

type LevelIter func(*PriceLevel)
type LevelIter func(priceLevel *PriceLevel, currentLevel int)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest renaming the currentLevel to levelIndex

return nil
}

func (ob *OrderBookOnULList) UpdateForEachPriceLevel(side int8, updater func(priceLevel *PriceLevel, currentLevel int)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just use LevelIter as the updater's type

@@ -831,6 +832,17 @@ func (kp *Keeper) expireOrders(ctx sdk.Context, blockTime time.Time) []chan Tran
return nil
}

var forceExpireHeight int64
var err2 error
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

err2 is not a good name, actually you can just reuse the err

numPricesStored = 2000
pricesStoreEvery = 1000
minimalNumPrices = 500
bep2PreferencePriceLevel = 500
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why add a bep2 prefix

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mini-token may have less price levels for orders living longer than 3 days

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove bep2 prefix first. You can change that when you really need it in mini token PR

@@ -20,7 +20,8 @@ type OrderBookInterface interface {
GetOrder(id string, side int8, price int64) (OrderPart, error)
RemoveOrder(id string, side int8, price int64) (OrderPart, error)
RemoveOrders(beforeTime int64, side int8, cb func(OrderPart)) error
UpdateForEachPriceLevel(side int8, updater func(*PriceLevel))
RemoveOrdersBiasedly(beforeTime int64, forceTime int64, preferenceSize int, side int8, removeCallback func(ord OrderPart)) error
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the method name is confusing, so are the parameter names.

@@ -8,6 +8,7 @@ var Mgr = sdk.UpgradeMgr
// bugfix: fix
// improvement: (maybe bep ?)
const (
BEPX = "BEPX" //placeholder for expire order extension
Copy link
Contributor

@rickyyangz rickyyangz Apr 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since we do not have a corresponding BEP, just give it a meaningful name.
Also, you need to register the upgrade with an upgrade height

app/app.go Outdated
@@ -253,6 +253,7 @@ func NewBinanceChain(logger log.Logger, db dbm.DB, traceStore io.Writer, baseApp
// setUpgradeConfig will overwrite default upgrade config
func SetUpgradeConfig(upgradeConfig *config.UpgradeConfig) {
// register upgrade height
upgrade.Mgr.AddUpgradeHeight(upgrade.BEP67, upgradeConfig.BEP6Height)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

put the upgrade config in the right order.

@@ -47,6 +47,8 @@ orderKeeperConcurrency = {{ .BaseConfig.OrderKeeperConcurrency }}
breatheBlockDaysCountBack = {{ .BaseConfig.BreatheBlockDaysCountBack }}

[upgrade]
# Block height of BEP67 upgrade
BEP67Height = {{ .UpgradeConfig.BEP67Height }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

const forceExpireDays = 30
forceExpireHeight, err = kp.GetBreatheBlockHeight(ctx, blockTime, forceExpireDays)
if err != nil {
kp.logger.Info(err.Error())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's use kp.logger.Error. Also for the #831

kp.logger.Info(err.Error())
forceExpireHeight = -1
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's better to extract a method get the expireHeight and forceExpireHeight.
e.g. func getExpireHeight(...) (expireHeight, forceExpireHeight int64)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ForceExpireHeight is only needed after BEP67

@@ -395,6 +395,7 @@ func (ull *ULList) GetPriceLevel(p int64) *PriceLevel {
func (ull *ULList) UpdateForEach(updater LevelIter) {
b := ull.begin
var last *bucket
iteratedCount := 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

levelIndex may be better

@@ -190,7 +190,7 @@ func (overlapped *OverLappedLevel) HasSellTaker() bool {
return overlapped.SellTakerStartIdx < len(overlapped.SellOrders)
}

type LevelIter func(*PriceLevel)
type LevelIter func(priceLevel *PriceLevel, levelIndex int)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the type of levelIndex should be int64.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Max level Index is int
func (ob *OrderBookOnULList) ShowDepth(maxLevels int, iterBuy LevelIter, iterSell LevelIter) {
ob.buyQueue.Iterate(maxLevels, iterBuy)
ob.sellQueue.Iterate(maxLevels, iterSell)
}

@EnderCrypto EnderCrypto force-pushed the expire_order_opt branch 3 times, most recently from 2435876 to 8f86d0e Compare April 21, 2020 14:08
fix & test

format

extract preference size as param

format:

refactor updator

fix format

rename arg

refactor
@EnderCrypto EnderCrypto merged commit 4ab7320 into develop Apr 22, 2020
@EnderCrypto EnderCrypto changed the title Expire order opt BEP67 Price-based Order Expiration Jun 2, 2020
@EnderCrypto EnderCrypto mentioned this pull request Jun 2, 2020
@unclezoro unclezoro deleted the expire_order_opt branch May 10, 2022 06:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants