Ejemplo n.º 1
0
        public void GetPrices()
        {
            GetPricingRequest request = new GetPricingRequest
            {
                AcceptDateTimeFormat = AcceptDateTimeFormat.RFC3339,
                AccountId            = this.AccountId,
                Instruments          = new List <InstrumentName>()
                {
                    new InstrumentName
                    {
                        BaseCurrency  = Currency.EUR,
                        QuoteCurrency = Currency.USD
                    },
                    new InstrumentName
                    {
                        BaseCurrency  = Currency.USD,
                        QuoteCurrency = Currency.CAD
                    }
                },
                IncludeHomeConversions = true,
                Since = System.DateTime.Now.AddDays(-7)
            };

            PricingApi         api      = new PricingApi(this.Client);
            GetPricingResponse response = api.Execute <GetPricingResponse>(request);

            Assert.AreEqual(response?.Prices?.Count, 2);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// OandaApiConnection constuctor
        /// Sets up the configuration and the datetime format
        /// </summary>
        /// <param name="connectionType">Type of the connection</param>
        /// <param name="accessToken">Access token for the connection</param>
        /// <param name="dateTimeFormat">Date time format to use for the connection</param>
        public OandaApiConnection(OandaConnectionType connectionType, string accessToken, DateTimeFormat dateTimeFormat = DateTimeFormat.RFC3339)
        {
            // Init configuration
            Configuration = new Configuration()
            {
                UserAgent   = $"OandaDotnetSdk/{Assembly.GetExecutingAssembly().GetName().Version}",
                BasePath    = connectionType.ToBasePath(),
                AccessToken = accessToken
            };

            // Init date time format
            DateTimeFormat = dateTimeFormat;

            // Init actual Oanda API connections from the GeriRemenyi.Oanda.V20.Client
            AccountApi     = new AccountApi(Configuration);
            InstrumentApi  = new InstrumentApi(Configuration);
            OrderApi       = new OrderApi(Configuration);
            TradeApi       = new TradeApi(Configuration);
            PositionApi    = new PositionApi(Configuration);
            TransactionApi = new TransactionApi(Configuration);
            PricingApi     = new PricingApi(Configuration);

            // Init object caches
            _accountsCache   = new Dictionary <string, IAccount>();
            _instrumentCache = new Dictionary <InstrumentName, IInstrument>();

            // Fire a really small request synchronously to check that the inited connection is OK
            // Also fill the available accounts based on this
            try
            {
                Accounts = AccountApi.GetAccounts().Accounts;
            }
            catch
            {
                throw new ConnectionInitializationException($"Unable to connect to {Configuration.BasePath} with the given token");
            }
        }
 public PricingApiTests()
 {
     instance = new PricingApi();
 }
Ejemplo n.º 4
0
 public void GetPrices()
 {
     PricingApi api = new PricingApi(this.Client);
     GetPricingResponse response = api.GetPricing(this.AccountId, new List<InstrumentName>() { "EUR_USD", "USD_CAD" }, DateTime.Now.AddMonths(-1), true);
     Assert.AreEqual(response?.Prices?.Count, 2);
 }