private static async Task PutOnATrade() { WriteNewLine($"Checking to see if {INSTRUMENT} is open for trading ..."); // first, check the market status for the INSTRUMENT // if it is tradeable, we'll try to make some money :) if (!await _ETrade10.IsMarketHalted(new[] { INSTRUMENT })) { WriteNewLine($"{INSTRUMENT} is open and rockin', so let's start trading!"); long?tradeID = await PlaceMarketOrder(); if (tradeID.HasValue) { // we have an open trade. // give it some time to make money :) await Task.Delay(10000); WriteNewLine("Okay, we've waited 10 seconds. Closing trade now ..."); // now, let' close the trade and collect our profits! .. hopefully //TradeCloseResponse closeResponse = null; //try //{ // var parameters = new TradeCloseParameters() { units = "ALL" }; // closeResponse = await Rest20.PutTradeCloseAsync(AccountID, tradeID.Value, parameters); //} //catch //{ // WriteNewLine("Oops. The trade can't be closed. Something went wrong. :("); //} //if (closeResponse != null) //{ // WriteNewLine("Nice! The trade is closed."); // var profit = closeResponse.orderFillTransaction.pl; // WriteNewLine($"Our profit was USD {profit}"); // if (profit > 0) // WriteNewLine($"Nice work! You are an awesome trader."); // else // { // WriteNewLine($"Looks like you need to learn some money-making strategies. :("); // WriteNewLine($"Keep studying, learning, but most of all .. keep trading!!"); // } //} } else { WriteNewLine($"Looks like something went awry with the trade. you need to learn some money-making strategies. :("); } } else { WriteNewLine("Sorry, Oanda markets are closed or Euro market is not tradeable."); WriteNewLine("Try again another time."); } }
/// <param name="symbol"></param> /// <returns></returns> private static async Task Market_GetMarketStatus() { var symbols0 = new[] { m_Security }; var symbols1 = new[] { m_Security, "CDW", "ONCE", "BAC", "KEYS", "ALL", "HON", "VUG", "ALV", "UL", "GS", "JPM", "ROKU", "MGM", "OXY", "CNC", "ULTA", "XLF", "CEC", "VOO", "BSX", "FB", "X", "SNAP", "KKR", "GLD", "PVH", "USO", "MASI", "GPN", "CHW", "IBM", "CVX", "TRP", "JNJ", "DDS", "MSI", "GOOG", "CAT", "SQ", "ADSK", "TXG", "AMN", "MHK", "CLF", "PEP", "PM", "BR", "BYND", "BMA", "RIO", "CB", "WMT", "AVLR", "GE", "CDNS", "LRCK", "AAPL", "AMD", "C", "CRM", "DIS", "F", "ROK", "FDX", "MSFT", "ZOOM", "KLAC", "NFLX", "UPS", "WFC" }; bool marketIsHalted = await m_ETrade10.IsMarketHalted(new[] { m_Security }); m_Results.Verify("00.0", marketIsHalted, "Market is halted."); //if (marketIsHalted) // throw new MarketHaltedException($"Unable to continue tests. Test security {m_Security} is halted!"); }