-
Notifications
You must be signed in to change notification settings - Fork 100
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
mm: Handle market params update #2846
base: master
Are you sure you want to change the base?
Conversation
421d331
to
0863701
Compare
This diff updates the market maker to listen for updates to the server config. If the lot size of a market that a bot is currently trading on is updated, the number of placements that the bot makes is updated so that the bot places as many lots as possible without exceeding the amount that was placed before the lot size update.
0863701
to
3e8478c
Compare
client/mm/mm_arb_market_maker.go
Outdated
func (c *ArbMarketMakerConfig) updateLotSize(originalLotSize, newLotSize uint64) { | ||
for _, p := range c.SellPlacements { | ||
p.Lots = (p.Lots * originalLotSize) / newLotSize | ||
} | ||
|
||
for _, p := range c.BuyPlacements { | ||
p.Lots = (p.Lots * originalLotSize) / newLotSize | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's say we have 4 sell placements of 1 lot each. If we double the lot size, this will result in 4 placements of 0 lots. Instead, I think we should focus on preserving total quantity and prioritizing higher-priority placements, so that we end up with 2 placements of 1 lot instead.
func (c *ArbMarketMakerConfig) updateLotSize(originalLotSize, newLotSize uint64) error {
updatedPlacements := func(oldPlacements []*ArbMarketMakingPlacement) (newPlacements []*ArbMarketMakingPlacement) {
var qtyCounter uint64
for _, p := range oldPlacements {
qtyCounter += p.Lots * originalLotSize
}
newPlacements = make([]*ArbMarketMakingPlacement, 0, len(oldPlacements))
for _, p := range oldPlacements {
lots := utils.Max((p.Lots*originalLotSize)/newLotSize, 1) // might want to round instead of truncate
qty := lots * newLotSize
if qty > qtyCounter {
return
}
qtyCounter -= qty
newPlacements = append(newPlacements, &ArbMarketMakingPlacement{
Lots: lots,
Multiplier: p.Multiplier,
})
}
return
}
if len(c.SellPlacements) > 0 {
c.SellPlacements = updatedPlacements(c.SellPlacements)
if len(c.SellPlacements) == 0 {
return errors.New("no sell placements possible with new lot size")
}
}
if len(c.BuyPlacements) > 0 {
c.BuyPlacements = updatedPlacements(c.BuyPlacements)
if len(c.BuyPlacements) == 0 {
return errors.New("no buy placements possible with new lot size")
}
}
return nil
}
Either way, we need to validate the resulting placements to ensure there are none with zero lots, especially since ArbMarketMakerConfig
doesn't have a Validate
method.
This diff updates the market maker to listen for updates to the server config. If the lot size of a market that a bot is currently trading on is updated, the number of placements that the bot makes is updated so that the bot places as many lots as possible without exceeding the amount that was placed before the lot size update.
Additionally, the lot size is now saved with the
BotConfig
. An additionaloverrideLotSizeChange
parameter is added toStartBot
, which if false, will return an error if the lot size has changed since the bot was configured. This will allow the UI to prompt the user to either update their configuration, or continue with the old one even though the lot size has changed.