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

mm: Handle market params update #2846

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

martonp
Copy link
Contributor

@martonp martonp commented Jun 26, 2024

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 additional overrideLotSizeChange parameter is added to StartBot, 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.

client/mm/mm_arb_market_maker.go Show resolved Hide resolved
client/mm/mm_basic.go Show resolved Hide resolved
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.
Comment on lines 112 to 120
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
}
}
Copy link
Member

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.

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.

3 participants