|
using TradeWithNarnia.Trading;
namespace TradeWithNarnia.Parsers.LineParser
{
/// <summary>
/// Processes statements, populates Alias cache, Commodity cache
/// </summary>
public class ParsedStatement : ParsedBase, IParsedLine
{
public string Process()
{
var result = string.Empty;
if(IsAliasStatement)
{
ProcessAliasStatement();
}
else if(IsCommodityStatement)
{
ProcessCommodityStatement();
}
else
{
// Unable to process as a statement, Redirect to Error highlighting
result = new ParsedError().Process();
}
return result.Trim();
}
private void ProcessCommodityStatement()
{
string commodityName = GetCommodityName(ParsedWords.TrimmedLeftHalfWords);
var lhsQuantity = GetQuantity(ParsedWords.GetAliases(ParsedWords.TrimmedLeftHalfWords));
var totalCost = GetTotalCost(ParsedWords.TrimmedRightHalfWords);
// Populate commodity cache
CommodityMgr[commodityName] = new Commodity(commodityName, (decimal) totalCost/(decimal) lhsQuantity);
}
private void ProcessAliasStatement()
{
var alias = ParsedWords.GetSingleUnknownWord(ParsedWords.TrimmedLeftHalfWords);
var romanSymbol = ParsedWords.GetSingleUnknownWord(ParsedWords.TrimmedRightHalfWords);
// Populate Alias Cache
AliasMgr.Add(alias.ToLower(), romanSymbol);
}
private bool IsAliasStatement
{
get
{
bool isAliasStatement = ParsedWords.HasSingleUnknownWord(ParsedWords.TrimmedLeftHalfWords)
&& !ParsedWords.HasAliases(ParsedWords.TrimmedLeftHalfWords);
return isAliasStatement;
}
}
private bool IsCommodityStatement
{
get
{
bool isCommodityStatement = ParsedWords.HasSingleUnknownWord(ParsedWords.TrimmedLeftHalfWords)
&& ParsedWords.HasAliases(ParsedWords.TrimmedLeftHalfWords);
return isCommodityStatement;
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I am Gaurav Chhatbar. I have got a total IT experience of 10 years that involves developing, leading, managing and delivering IT solutions for business.
My core expertise lies around Dot Net as well as Java technologies. In the past, I have developed / owned applications, primarily for:
Front Office Trading – Equities, Fixed Income as well as Structured Products
Private Wealth Management – Trading and CRM
For most of my career, I have worked for Morgan Stanley, Mumbai, India.
Gaurav Chhatbar
chhatbar@gmail.com