Created
February 24, 2012 07:41
-
-
Save gregoryyoung/1898785 to your computer and use it in GitHub Desktop.
quick kata impl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class stoploss { | |
private Dictionary<Guid, decimal> fifteen = new Dictionary>Guid, decimal>() | |
private Dictionary<Guid, decimal> thirty = new Dictionary>Guid, decimal>();; | |
bool alive = true; | |
decimal price | |
Guid id; | |
public stoploss(PositionAcquiredMessage m) { | |
id = m.PositionId; | |
} | |
public void Consume(PriceChangeMessage m) { | |
fifteen.Add(m.Id, m.Price); | |
thirty.Add(m.Id, m.Price); | |
Raise(SendMeInNSeconds(new RemoveFromFifteen(m.Id), 15); | |
Raise(SendMeInNSeconds(new RemoveFromThirty(m.Id), 30); } | |
} | |
public void Consume(RemoveFromFifteen m) { | |
fifteen.Remove(m.Id); | |
CheckMove(); | |
} | |
public void Consume(RemoveFromThirty m) { | |
CheckSell(); | |
thtirty.Remove(m.Id); | |
} | |
void CheckMove() { | |
if(fifteen.Values.Where(x => x > target).Count != fiften.Values.Count) return; | |
price = fifteen.Values.Minimum(); | |
} | |
void CheckSell() { | |
if(!alive) return; | |
if(!thirty.Where(x.Value > price * .95).Count() == 0) return; | |
Raise(new SellPosition(this.Id)); | |
alive = false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment