saving in place
This commit is contained in:
@@ -3,6 +3,9 @@ package marketmanager
|
||||
import (
|
||||
"math/big"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
"github.com/fraktal/mev-beta/pkg/types"
|
||||
)
|
||||
|
||||
// ArbitrageDetector detects arbitrage opportunities between markets
|
||||
@@ -19,20 +22,16 @@ func NewArbitrageDetector(minProfitThreshold *big.Int, minROIPercentage float64)
|
||||
}
|
||||
}
|
||||
|
||||
// ArbitrageOpportunity represents a detected arbitrage opportunity
|
||||
type ArbitrageOpportunity struct {
|
||||
Market1 *Market
|
||||
Market2 *Market
|
||||
Path []string // Token path
|
||||
Profit *big.Int // Estimated profit in wei
|
||||
GasEstimate *big.Int // Estimated gas cost in wei
|
||||
ROI float64 // Return on investment percentage
|
||||
InputAmount *big.Int // Required input amount
|
||||
// MarketOpportunity represents market-specific arbitrage data (extends canonical ArbitrageOpportunity)
|
||||
type MarketOpportunity struct {
|
||||
*types.ArbitrageOpportunity
|
||||
Market1 *Market
|
||||
Market2 *Market
|
||||
}
|
||||
|
||||
// DetectArbitrageOpportunities detects arbitrage opportunities among markets with the same rawTicker
|
||||
func (ad *ArbitrageDetector) DetectArbitrageOpportunities(markets map[string]*Market) []*ArbitrageOpportunity {
|
||||
var opportunities []*ArbitrageOpportunity
|
||||
func (ad *ArbitrageDetector) DetectArbitrageOpportunities(markets map[string]*Market) []*types.ArbitrageOpportunity {
|
||||
var opportunities []*types.ArbitrageOpportunity
|
||||
|
||||
// Convert map to slice for sorting
|
||||
marketList := make([]*Market, 0, len(markets))
|
||||
@@ -65,7 +64,7 @@ func (ad *ArbitrageDetector) DetectArbitrageOpportunities(markets map[string]*Ma
|
||||
}
|
||||
|
||||
// checkArbitrageOpportunity checks if there's an arbitrage opportunity between two markets
|
||||
func (ad *ArbitrageDetector) checkArbitrageOpportunity(market1, market2 *Market) *ArbitrageOpportunity {
|
||||
func (ad *ArbitrageDetector) checkArbitrageOpportunity(market1, market2 *Market) *types.ArbitrageOpportunity {
|
||||
// Calculate price difference
|
||||
priceDiff := new(big.Float).Sub(market2.Price, market1.Price)
|
||||
if priceDiff.Sign() <= 0 {
|
||||
@@ -119,15 +118,24 @@ func (ad *ArbitrageDetector) checkArbitrageOpportunity(market1, market2 *Market)
|
||||
return nil // ROI too low
|
||||
}
|
||||
|
||||
// Create arbitrage opportunity
|
||||
return &ArbitrageOpportunity{
|
||||
Market1: market1,
|
||||
Market2: market2,
|
||||
Path: []string{market1.Token0.Hex(), market1.Token1.Hex()},
|
||||
Profit: netProfit,
|
||||
GasEstimate: gasCost,
|
||||
ROI: roi,
|
||||
InputAmount: optimalTradeSize,
|
||||
// Create canonical arbitrage opportunity
|
||||
return &types.ArbitrageOpportunity{
|
||||
Path: []string{market1.Token0.Hex(), market1.Token1.Hex()},
|
||||
Pools: []string{"market1-pool", "market2-pool"},
|
||||
AmountIn: optimalTradeSize,
|
||||
Profit: netProfit,
|
||||
NetProfit: netProfit,
|
||||
GasEstimate: gasCost,
|
||||
ROI: roi,
|
||||
Protocol: "market-arbitrage",
|
||||
ExecutionTime: 5000, // 5 seconds
|
||||
Confidence: 0.9, // High confidence for market data
|
||||
PriceImpact: 0.01, // 1% estimated
|
||||
MaxSlippage: 0.02, // 2% max slippage
|
||||
TokenIn: market1.Token0,
|
||||
TokenOut: market1.Token1,
|
||||
Timestamp: time.Now().Unix(),
|
||||
Risk: 0.1, // Low risk for market arbitrage
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user