static async Task <long?> PlaceMarketOrder(string side = "buy") { WriteNewLine("Creating a EUR_USD market BUY order ..."); var parameters = new AccountInstrumentsParameters() { instruments = new List <string>() { INSTRUMENT } }; var oandaInstrument = (await Rest20.GetAccountInstrumentsAsync(AccountID, parameters)).First(); decimal orderUnits = side == "buy" ? 10 : -10; var request = new MarketOrderRequest(oandaInstrument) { units = orderUnits }; PostOrderResponse response = null; try { response = await Rest20.PostOrderAsync(AccountID, request); WriteNewLine("Congrats! You've put on a trade! Let it run! :)"); } catch (Exception ex) { var errorResponse = ErrorResponseFactory.Create(ex.Message); WriteNewLine("Oops. Order creation failed."); WriteNewLine($"The failure message is: {errorResponse.errorMessage}."); WriteNewLine("Try again later."); } return(response?.orderFillTransaction?.tradeOpened?.tradeID); }
/// <summary> /// Get the list of tradeable instruments for the given Account. The list of tradeable instruments is dependent /// on the regulatory division that the Account is located in, thus should be the same for all Accounts owned by /// a single user. /// http://developer.oanda.com/rest-live-v20/account-ep/#_collapse_endpoint_5 /// </summary> /// <param name="accountID">details will be retrieved for this account id</param> /// <param name="parameters">the parameters for the request</param> /// <returns>a List of the tradeable instruments specified. If none are specified, all tradeable instruments for /// the account are returned.</returns> public static async Task <List <Instrument.Instrument> > GetAccountInstrumentsAsync(string accountID, AccountInstrumentsParameters parameters = null) { string uri = ServerUri(EServer.Account) + "accounts/" + accountID + "/instruments"; if (parameters != null && parameters.instruments != null && parameters.instruments.Count > 0) { string commaSeparatedInstruments = GetCommaSeparatedString(parameters.instruments); uri += "?instruments=" + Uri.EscapeDataString(commaSeparatedInstruments); } var response = await MakeRequestAsync <AccountInstrumentsResponse, AccountInstrumentsErrorResponse>(uri); return(response.instruments); }