Skip to content

mm: Multi-hop Arbs #3267

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

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

mm: Multi-hop Arbs #3267

wants to merge 9 commits into from

Conversation

martonp
Copy link
Collaborator

@martonp martonp commented May 7, 2025

libxc: Support Market Trades and Inverse VWAP

Adds features required for multi-hop arbs.

- Market Trades are now supported.
- Inverse VWAP, the same as VWAP but using the quote asset, is now
  supported.
- A ValidateTrade function is also added, to be able to determine prior
  to placing an order if the order parameters are valid.
- The Binance NOTIONAL and MIN_NOTIONAL filters are taken into account
  when determining the validity of trade parameters.
mm: Update exchange adaptor to support market trades
mm: Add multi-hop strategy to arb market maker

Adds the ability to perform multi-hop arbitrage trades using the
arb market maker bot. If the exact market that exist on the DEX
does not exist on the CEX, but there exist two markets each
involving the base and quote assets of the DEX market and sharing
the same third asset, then the bot will perform arbitrage trades
by using both of these markets.

For example, if there is a DCR-BTC market on the DEX, the bot can
be configured to do multi-hop arbs on DCR-USDT and a BTC-USDT markets.
Then if a sell order is matched on a DEX, the bot will sell BTC on the
BTC-USDT market and buy DCR on the DCR-USDT market, and vice-versa for
buys.

Since two arb trades are being done, the chance of unfilled arb trades
becomes higher. In order to avoid the possibility of funds being stuck
in the intermediate asset, market trades are used rather than limit
trades.
ui: Support configuring multi-hop arbs

Closes #3120

@JoeGruffins
Copy link
Member

Has conflicts now.

@martonp martonp force-pushed the multiHopArb branch 2 times, most recently from aa2155b to 113613b Compare June 1, 2025 18:09
Copy link
Member

@JoeGruffins JoeGruffins left a comment

Choose a reason for hiding this comment

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

First pass. Will take a few passes to understand. Unsure how well I can test but will try.

Comment on lines 24 to 63
ob.update([]*obEntry{
{qty: 30, rate: 4000},
{qty: 30, rate: 5000},
{qty: 80, rate: 400},
{qty: 10, rate: 3000},
}, []*obEntry{
{qty: 30, rate: 4000},
{qty: 30, rate: 5000},
{qty: 80, rate: 400},
{qty: 10, rate: 3000},
})
bids := []*obEntry{
{qty: 30, rate: 4000e8},
{qty: 30, rate: 5000e8},
{qty: 80, rate: 400e8},
{qty: 10, rate: 3000e8},
}
asks := []*obEntry{
{qty: 30, rate: 4000e8},
{qty: 30, rate: 5000e8},
{qty: 80, rate: 400e8},
{qty: 10, rate: 3000e8},
}
Copy link
Member

Choose a reason for hiding this comment

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

Were all the quantities zero for quote? I think it's more natural to increase the base qty, as they would be atoms. The rates weren't that far off from what you might have, but are now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point, I've changed it.

} else if sell {
baseQtyStr, err = getBaseQtyStr()
} else {
quoteQtyStr, err = getQuoteQtyStr()
Copy link
Member

Choose a reason for hiding this comment

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

For this case, qty is already quote asset, correct?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, for market buys you pass the quote qty.

@@ -1018,7 +1094,26 @@ func (c *coinbase) VWAP(baseID, quoteID uint32, sell bool, qty uint64) (vwap, ex
return 0, 0, false, fmt.Errorf("no book found for %s", productID)
}

return book.vwap(sell, qty)
return book.vwap(!sell, qty)
Copy link
Member

Choose a reason for hiding this comment

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

Was this wrong? The arg is bids so to get sells then you want asks, I guess... This was a bug then?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah this was a bug.

}
}

// multiHopRate returns the aggregate rate that can be achieved by completing
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// multiHopRate returns the aggregate rate that can be achieved by completing
// multiHopRateAndTrades returns the aggregate rate that can be achieved by completing

martonp added 9 commits June 10, 2025 07:57
Adds features required for multi-hop arbs.

- Market Trades are now supported.
- Inverse VWAP, the same as VWAP but using the quote asset, is now
  supported.
- A ValidateTrade function is also added, to be able to determine prior
  to placing an order if the order parameters are valid.
- The Binance NOTIONAL and MIN_NOTIONAL filters are taken into account
  when determining the validity of trade parameters.
Adds the ability to perform multi-hop arbitrage trades using the
arb market maker bot. If the exact market that exist on the DEX
does not exist on the CEX, but there exist two markets each
involving the base and quote assets of the DEX market and sharing
the same third asset, then the bot will perform arbitrage trades
by using both of these markets.

For example, if there is a DCR-BTC market on the DEX, the bot can
be configured to do multi-hop arbs on DCR-USDT and a BTC-USDT markets.
Then if a sell order is matched on a DEX, the bot will sell BTC on the
BTC-USDT market and buy DCR on the DCR-USDT market, and vice-versa for
buys.

Since two arb trades are being done, the chance of unfilled arb trades
becomes higher. In order to avoid the possibility of funds being stuck
in the intermediate asset, market trades are used rather than limit
trades.
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.

mm: add local cross market arb strategy
2 participants