public override List <MemoryItem> GetMemoryItems() { List <MemoryItem> memoryItemList = new List <MemoryItem>(); //get latest input (MemoryItem) from ListenerProcess, which should be the quantity given MemoryItem latestListenerItem = ownerAgent.WorkingMemory.GetLastItemByTag(MemoryItemTags.ListenerProcess); string quantityString = latestListenerItem.Content.ToLower(); int quantity = int.Parse(quantityString); //Get the portfolio brain process to check if sufficient funds available BrainProcess portfolioProcess = ownerAgent.BrainProcessList.Find(x => x.Name == "Portfolio"); if (((PortfolioProcess)portfolioProcess).IsTradeSuccessful(quantity, 1)) { } /* * MemoryItem outputItem = new MemoryItem(); * outputItem.CreationDateTime = DateTime.Now; * outputItem.Tag = MemoryItemTags.InternetDataAcquisitionProcess; * outputItem.Content = "requestSearch*" + tickerToQuery; * memoryItemList.Add(outputItem);*/ memoryItemList.Reverse(); // Doesn't matter really, but looks more elegant in the display: // Displayed as action first, then deactivation, then activation (on top). return(memoryItemList); }
public List <MemoryItem> CheckPortfolioNotEmpty(out string targetDialogueItemName) { targetDialogueItemName = ""; List <MemoryItem> memoryItemList = null; bool setLimitIsSuccessful = false; string setLimitIsSuccessfulString = "failure"; /* * Maybe should've followed the event pipeline structure below instead of searching up the portfolio process * but this is much simpler and short of time. */ //Get the portfolio brain process BrainProcess portfolioProcess = ownerAgent.BrainProcessList.Find(x => x.Name == "Portfolio"); //success if portfolio not empty, else failure. A portfolio can only be modified if non-empty setLimitIsSuccessful = ((PortfolioProcess)portfolioProcess).StockList.Count > 0; setLimitIsSuccessfulString = setLimitIsSuccessful ? "success" : "failure"; foreach (DialogueAction action in actionList) { Boolean matching = action.CheckMatch(setLimitIsSuccessfulString); if (matching) { memoryItemList = action.GetMemoryItems(); targetDialogueItemName = action.TargetDialogueItemName; } } return(memoryItemList); }
public List <MemoryItem> TryExecuteTrade(string inputString, out string targetDialogueItemName) { targetDialogueItemName = ""; List <MemoryItem> memoryItemList = null; bool tradeIsSuccessful = false; bool validInput = true; int size = int.Parse(inputString); string tradeIsSuccessfulString = "failure"; validInput = size > 0; /* * Maybe should've followed the event pipeline structure below instead of searching up the portfolio process * but this is much simpler and short of time. */ //Get the portfolio brain process BrainProcess portfolioProcess = ownerAgent.BrainProcessList.Find(x => x.Name == "Portfolio"); //Only try to execute trade if a valid input size if (validInput) { //Let the portfolio brain process try to execute the trade lastOrderSuccessful = tradeIsSuccessful = ((PortfolioProcess)portfolioProcess).IsTradeSuccessful(size, direction); tradeIsSuccessfulString = tradeIsSuccessful ? "success" : "failure"; } foreach (DialogueAction action in actionList) { if (action is MarketExecutionAction) { MarketExecutionAction marketExecutionAction = (MarketExecutionAction)action; //Get the Dialogue action representing trade execution success/failure Boolean matching = marketExecutionAction.CheckMatch(tradeIsSuccessfulString); if (matching) { marketExecutionAction.Stock = ((PortfolioProcess)portfolioProcess).StockInFocus; marketExecutionAction.Quantity = size * direction; marketExecutionAction.FillPrice = ((PortfolioProcess)portfolioProcess).StockInFocusLastPrice; memoryItemList = marketExecutionAction.GetMemoryItems(); targetDialogueItemName = marketExecutionAction.TargetDialogueItemName; } } else //Most likely ResponseAction { Boolean matching = action.CheckMatch(tradeIsSuccessfulString); if (matching) { memoryItemList = action.GetMemoryItems(); targetDialogueItemName = action.TargetDialogueItemName; } } } return(memoryItemList); }
public List <MemoryItem> TrySetLimit(string inputString, out string targetDialogueItemName) { targetDialogueItemName = ""; List <MemoryItem> memoryItemList = null; bool setLimitIsSuccessful = false; bool validInput = true; double limit = double.Parse(inputString); string setLimitIsSuccessfulString = "failure"; /* * Maybe should've followed the event pipeline structure below instead of searching up the portfolio process * but this is much simpler and short of time. */ //Get the portfolio brain process BrainProcess portfolioProcess = ownerAgent.BrainProcessList.Find(x => x.Name == "Portfolio"); //Only try to execute trade if a valid input if (validInput) { //Let the portfolio brain process try to execute the trade lastOrderSuccessful = setLimitIsSuccessful = ((PortfolioProcess)portfolioProcess).IsSetLimitSuccessful(limit, limitOrderType, direction); setLimitIsSuccessfulString = setLimitIsSuccessful ? "success" : "failure"; } foreach (DialogueAction action in actionList) { if (action is LimitExecutionAction) { LimitExecutionAction limitExecutionAction = (LimitExecutionAction)action; //Get the Dialogue action representing trade execution success/failure Boolean matching = limitExecutionAction.CheckMatch(setLimitIsSuccessfulString); if (matching) { limitExecutionAction.Stock = ((PortfolioProcess)portfolioProcess).StockInFocus; limitExecutionAction.LimitLevel = limit; limitExecutionAction.LimitType = limitOrderType; memoryItemList = limitExecutionAction.GetMemoryItems(); targetDialogueItemName = limitExecutionAction.TargetDialogueItemName; } } else //Most likely ResponseAction { Boolean matching = action.CheckMatch(setLimitIsSuccessfulString); if (matching) { memoryItemList = action.GetMemoryItems(); targetDialogueItemName = action.TargetDialogueItemName; } } } return(memoryItemList); }
public List <MemoryItem> TryExitPosition(string inputString, out string targetDialogueItemName) { targetDialogueItemName = ""; List <MemoryItem> memoryItemList = null; bool exitPositionSuccessful = false; bool validInput = true; int id = int.Parse(inputString); string exitPositionSuccessfulString = "failure"; /* * Maybe should've followed the event pipeline structure below instead of searching up the portfolio process * but this is much simpler and short of time. */ //Get the portfolio brain process BrainProcess portfolioProcess = ownerAgent.BrainProcessList.Find(x => x.Name == "Portfolio"); //Only try to exit position if a valid input if (validInput) { //Let the portfolio brain process try to exit the position lastOrderSuccessful = exitPositionSuccessful = ((PortfolioProcess)portfolioProcess).TryExitPosition(id); exitPositionSuccessfulString = exitPositionSuccessful ? "success" : "failure"; } foreach (DialogueAction action in actionList) { Boolean matching = action.CheckMatch(exitPositionSuccessfulString); if (matching) { memoryItemList = action.GetMemoryItems(); targetDialogueItemName = action.TargetDialogueItemName; } } return(memoryItemList); }