public void 最大の取得件数を指定して注文を取得する()
        {
            var oandaApi     = new OandaApi(_client, _server.DefaultAccountId);
            var actualOrders = oandaApi.GetOrders(count: 2).Result;

            Assert.AreEqual(2, actualOrders.Length);
        }
        public void 通貨ペアを指定して注文を取得する()
        {
            var oandaApi     = new OandaApi(_client, _server.DefaultAccountId);
            var actualOrders = oandaApi.GetOrders(instrument: "USD_JPY").Result;

            Assert.AreEqual(2, actualOrders.Length);
        }
示例#3
0
        public void 全銘柄を取得する()
        {
            var oandaApi          = new OandaApi(_client, _server.DefaultAccountId);
            var actualInstruments = oandaApi.GetInstruments().Result;

            Assert.AreEqual(_server.Context.Instruments.Count, actualInstruments.Length);
        }
        public void 必須項目を指定して成行注文を出す()
        {
            var now = _server.Context.CurrentTime;

            var oandaApi      = new OandaApi(_client, _server.DefaultAccountId);
            var instrument    = "USD_JPY";
            var units         = 100;
            var side          = OrderSide.Buy;
            var orderResponse = oandaApi.PostMarketOrder(instrument, units, side).Result;

            Assert.AreEqual(instrument, orderResponse.Instrument);
            Assert.AreEqual(now, orderResponse.Time);
            Assert.AreEqual(units, orderResponse.TradeOpened.Units);
            Assert.AreEqual(side, orderResponse.TradeOpened.Side);
            Assert.AreEqual(0, orderResponse.TradeOpened.TakeProfit);
            Assert.AreEqual(0, orderResponse.TradeOpened.StopLoss);
            Assert.AreEqual(0, orderResponse.TradeOpened.TrailingStop);

            var context = _server.Context;
            var actual  = context.Accounts[_server.DefaultAccountId].Trades[orderResponse.TradeOpened.Id];

            Assert.AreEqual(actual.Instrument, orderResponse.Instrument);
            Assert.AreEqual(actual.Units, orderResponse.TradeOpened.Units);
            Assert.AreEqual(actual.Side.ToString().ToUpper(), orderResponse.TradeOpened.Side.ToString().ToUpper());
            Assert.AreEqual(actual.Time, orderResponse.Time);
            Assert.AreEqual(actual.Price, orderResponse.Price);
            Assert.AreEqual(actual.TakeProfit ?? 0, orderResponse.TradeOpened.TakeProfit);
            Assert.AreEqual(actual.StopLoss ?? 0, orderResponse.TradeOpened.StopLoss);
            Assert.AreEqual(actual.TrailingStop ?? 0, orderResponse.TradeOpened.TrailingStop);
        }
        public void 最大のIDを指定して注文を取得する()
        {
            var maxId        = _server.Context.DefaultAccount.Orders.Values.OrderBy(o => o.Id).Skip(2).First().Id;
            var oandaApi     = new OandaApi(_client, _server.DefaultAccountId);
            var actualOrders = oandaApi.GetOrders(maxId: maxId).Result;

            Assert.AreEqual(3, actualOrders.Length);
        }
        public void 銘柄の過去データの取得()
        {
            var oandaApi = new OandaApi(_client, _server.DefaultAccountId);

            var candles = oandaApi.GetMidpointCandles("USD_JPY", count: 10).Result;

            Assert.AreEqual(10, candles.Length);
        }
        public void 複数のIDを指定して注文を取得する()
        {
            var expectedOrders = _server.Context.DefaultAccount.Orders.Values.Take(2);
            var oandaApi       = new OandaApi(_client, _server.DefaultAccountId);
            var actualOrders   = oandaApi.GetOrders(expectedOrders.Select(o => o.Id).ToArray()).Result;

            CollectionAssert.AreEqual(expectedOrders.Select(o => o.Id).ToArray(),
                                      actualOrders.Select(o => o.Id).ToArray());
        }
示例#8
0
        public void 複数のレートを取得する()
        {
            var expectedPrices = _server.Context.Prices.Where(p => p.Key == "USD_JPY" || p.Key == "EUR_USD").ToArray();

            Assert.IsTrue(expectedPrices.Length == 2);

            var oandaApi = new OandaApi(_client, _server.DefaultAccountId);

            var actualPrices = oandaApi.GetPrices("USD_JPY", "EUR_USD").Result;

            Assert.AreEqual(expectedPrices.Length, actualPrices.Length);
            CollectionAssert.AreEqual(expectedPrices.Select(p => p.Key).ToArray(),
                                      actualPrices.Select(p => p.Instrument).ToArray());
        }
示例#9
0
        public void 現在のレートを取得する()
        {
            var price = _server.Context.Prices.Find("USD_JPY");

            var oandaApi = new OandaApi(_client, _server.DefaultAccountId);

            var prices = oandaApi.GetPrices("USD_JPY").Result;

            Assert.AreEqual(1, prices.Length);

            var actualPrice = prices.First();

            Assert.AreEqual("USD_JPY", actualPrice.Instrument);
            Assert.AreEqual(price.Time, actualPrice.Time);
            Assert.AreEqual(price.Ask, actualPrice.Ask);
            Assert.AreEqual(price.Bid, actualPrice.Bid);
        }
示例#10
0
        public void アカウントの詳細を取得する()
        {
            var account = _server.Context.DefaultAccount;

            var oandaApi = new OandaApi(_client, _server.DefaultAccountId);
            var obj      = oandaApi.GetAccount().Result;

            Assert.AreEqual(account.AccountId, obj.AccountId);
            Assert.AreEqual(account.AccountName, obj.AccountName);
            Assert.AreEqual(account.Balance, obj.Balance);
            Assert.AreEqual(account.UnrealizedProfitLoss, obj.UnrealizedPl);
            Assert.AreEqual(account.RealizedProfitLoss, obj.RealizedPl);
            Assert.AreEqual(account.MarginUsed, obj.MarginUsed);
            Assert.AreEqual(account.MarginAvail, obj.MarginAvail);
            Assert.AreEqual(account.OpenTrades, obj.OpenTrades);
            Assert.AreEqual(account.OpenOrders, obj.OpenOrders);
            Assert.AreEqual(account.MarginRate, obj.MarginRate);
            Assert.AreEqual(account.AccountCurrency, obj.AccountCurrency);
        }
        public void 特定IDを指定して注文を取得する()
        {
            var expected = _server.Context.DefaultAccount.Orders.Values.Skip(1).First();
            var oandaApi = new OandaApi(_client, _server.DefaultAccountId);
            var actual   = oandaApi.GetOrder(expected.Id).Result;

            Assert.AreEqual(expected.Id, actual.Id);
            Assert.AreEqual(expected.Instrument, actual.Instrument);
            Assert.AreEqual(expected.Units, actual.Units);
            Assert.AreEqual(expected.Side.ToString().ToUpper(), actual.Side.ToString().ToUpper());
            Assert.AreEqual(expected.Type.ToString().ToUpper(), actual.Type.ToString().ToUpper());
            Assert.AreEqual(expected.Time, actual.Time);
            Assert.AreEqual(expected.Price, actual.Price);
            Assert.AreEqual(expected.TakeProfit, actual.TakeProfit);
            Assert.AreEqual(expected.StopLoss, actual.StopLoss);
            Assert.AreEqual(expected.Expiry, actual.Expiry);
            Assert.AreEqual(expected.UpperBound, actual.UpperBound);
            Assert.AreEqual(expected.LowerBound, actual.LowerBound);
            Assert.AreEqual(expected.TrailingStop, actual.TrailingStop);
        }
        public void 必須項目を指定して逆指値注文を出す()
        {
            var now = _server.Context.CurrentTime;

            var oandaApi      = new OandaApi(_client, _server.DefaultAccountId);
            var instrument    = "USD_JPY";
            var units         = 100;
            var side          = OrderSide.Buy;
            var type          = OrderType.Stop;
            var expiry        = now.AddDays(10);
            var price         = 120.05m;
            var orderResponse = oandaApi.PostOrder(instrument, units, side, type, expiry, price).Result;

            Assert.AreEqual(instrument, orderResponse.Instrument);
            Assert.AreEqual(now, orderResponse.Time);
            Assert.AreEqual(price, orderResponse.Price);
            Assert.AreEqual(units, orderResponse.OrderOpened.Units);
            Assert.AreEqual(side, orderResponse.OrderOpened.Side);
            Assert.AreEqual(0, orderResponse.OrderOpened.TakeProfit);
            Assert.AreEqual(0, orderResponse.OrderOpened.StopLoss);
            Assert.AreEqual(expiry, orderResponse.OrderOpened.Expiry);
            Assert.AreEqual(0, orderResponse.OrderOpened.UpperBound);
            Assert.AreEqual(0, orderResponse.OrderOpened.LowerBound);
            Assert.AreEqual(0, orderResponse.OrderOpened.TrailingStop);

            var context = _server.Context;
            var actual  = context.Accounts[_server.DefaultAccountId].Orders.Find(orderResponse.OrderOpened.Id);

            Assert.AreEqual(actual.Instrument, orderResponse.Instrument);
            Assert.AreEqual(actual.Units, orderResponse.OrderOpened.Units);
            Assert.AreEqual(actual.Side.ToString().ToUpper(), orderResponse.OrderOpened.Side.ToString().ToUpper());
            Assert.AreEqual(actual.Type.ToString().ToUpper(), OrderType.Stop.ToString().ToUpper());
            Assert.AreEqual(actual.Time, orderResponse.Time);
            Assert.AreEqual(actual.Price, orderResponse.Price);
            Assert.AreEqual(actual.TakeProfit ?? 0, orderResponse.OrderOpened.TakeProfit);
            Assert.AreEqual(actual.StopLoss ?? 0, orderResponse.OrderOpened.StopLoss);
            Assert.AreEqual(actual.Expiry, orderResponse.OrderOpened.Expiry);
            Assert.AreEqual(actual.UpperBound ?? 0, orderResponse.OrderOpened.UpperBound);
            Assert.AreEqual(actual.LowerBound ?? 0, orderResponse.OrderOpened.LowerBound);
            Assert.AreEqual(actual.TrailingStop ?? 0, orderResponse.OrderOpened.TrailingStop);
        }
示例#13
0
        public void 銘柄を取得する()
        {
            var instrument = _server.Context.Instruments.Find("USD_JPY");

            var oandaApi = new OandaApi(_client, _server.DefaultAccountId);

            var prices = oandaApi.GetInstruments("USD_JPY").Result;

            Assert.AreEqual(1, prices.Length);

            var actualPrice = prices.First();

            Assert.AreEqual("USD_JPY", actualPrice.Instrument);
            Assert.AreEqual(instrument.DisplayName, actualPrice.DisplayName);
            Assert.AreEqual(instrument.Pip, actualPrice.Pip);
            Assert.AreEqual(instrument.MaxTradeUnits, actualPrice.MaxTradeUnits);
            Assert.AreEqual(instrument.Precision, actualPrice.Precision);
            Assert.AreEqual(instrument.MaxTrailingStop, actualPrice.MaxTrailingStop);
            Assert.AreEqual(instrument.MinTrailingStop, actualPrice.MinTrailingStop);
            Assert.AreEqual(instrument.MarginRate, actualPrice.MarginRate);
            Assert.AreEqual(instrument.Halted, actualPrice.Halted);
        }