Hi. First of all I don't know if this is possible.
I'm building a software to work with Betfair, a sports exchange.
I need help with the math on something I'm working on right now.

I don't know how to explain this perfectly so I think only people who are familiar with Betfair will fully understand what I'm asking: I need a formula to green out.
My software will work on tennis matches, so we have two selections, let's say player A and player B, and I want to green out based on profit or loss on each selection.
Greening out means that Profit/Loss A = Profit/Loss B.

The information we have to do that is 4 odd values and offcourse the current profit or loss. The odds are: Back price and lay price for player A and back price and lay price for player B.

Before I run into details let me explain how to green out a single bet - hope it will be easier for those unfamiliar with that.

Lets say I back player A with 100 and odd 1.50.
The profit or loss A will be = 100*(1.50-1) = 50
The profit or loss B will be = -100

The current lay odd is 1.55 and to green out I need to calc this:
Back Odd/current lay odd * amount bet
1.50/1.55*100 = 96.77

Then I'll place a lay bet with 96.77 at 1.55 and after that PLA will be -3,23 and PLB = -3,23. It's done.

The problem here is that I need to know the information about the bets in order to green out. I need to work out something that will do the same job without knowing that.

I began by defining Profit and Loss:

x - total size of back bets on A
c - average odd of back bets on A
v - total size of lay bets on A
b - average odd of lay bets on A
n - total size of back bets on back B
m - odd odd of back bets on B
a - total size of lay bets on B
s - average odd of lay bets on B

PLA - Profit or Loss on player A, PLB - Profit or Loss on player B

PLA = x(c - 1) - v(b - 1) - n + a
PLB = n(m - 1) - a(s - 1) - x + v

I think this is correct.

After this I don't know how to determine wich bets I need to place to green.
Let's say PLA = 100 and PLB -200
Back odd on A is now 1.45 and lay 1.44
Back odd on B is now 4 and lay 4.5

I don't now how to relate this values in order to make PLA = PLB.