Ejemplo n.º 1
0
        static private async Task PutOnATrade()
        {
            WriteNewLine("Checking to see if EUR_USD is open for trading ...");

            // first, check the market status for EUR_USD
            // if it is tradeable, we'll try to make some money :)
            if (!(await Utilities.IsMarketHalted(INSTRUMENT)))
            {
                WriteNewLine("EUR_USD 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.");
            }
        }