// Calculate arb needed for a trade based on existing positions func calcNeededArb(buyExg, sellExg exchange.Interface) float64 { // Middle between min and max center := (cfg.Sec.MaxArb + cfg.Sec.MinArb) / 2 // Half distance from center to min and max halfDist := (cfg.Sec.MaxArb - center) / 2 // If taking currency risk, add required premium if buyExg.CurrencyCode() != sellExg.CurrencyCode() { center += cfg.Sec.FXPremium } // Percent of max buyExgPct := buyExg.Position() / buyExg.MaxPos() sellExgPct := sellExg.Position() / sellExg.MaxPos() // Return required arb return center + buyExgPct*halfDist - sellExgPct*halfDist }