private void OpenPosition(string currencyPair, double amount, double price, PositionDirection pd) { if (position_dic.ContainsKey(currencyPair)) { if (position_dic[currencyPair].Direction == PositionDirection.Long) { position_dic[currencyPair].LongNotional += amount; position_dic[currencyPair].NetNotional = position_dic[currencyPair].LongNotional; } else if (position_dic[currencyPair].Direction == PositionDirection.Short) { position_dic[currencyPair].ShortNotional += amount; position_dic[currencyPair].NetNotional = -position_dic[currencyPair].ShortNotional; } else { Position newPosition = new Position(pd, currencyPair, amount, price); position_dic[currencyPair] = newPosition; } position_dic[currencyPair].CostPrice = (position_dic[currencyPair].NetNotional * position_dic[currencyPair].CostPrice + amount * price) / (position_dic[currencyPair].NetNotional + amount); position_dic[currencyPair].CurrentPrice = price; } else { Position newPosition = new Position(pd, currencyPair, amount, price); position_dic.Add(currencyPair, newPosition); } }
public Portfolio(List<string> currencyPair_list) : base() { foreach (var currencyPair in currencyPair_list) { Position newPosition = new Position(currencyPair); position_dic.Add(currencyPair, newPosition); } }
public Portfolio(string currencyPair) : base() { Position newPosition = new Position(currencyPair); position_dic.Add(currencyPair, newPosition); }