Sha256: 4467992e65959ffc4e6e931e37eab1b12107533cccafe3c2eae9632c76fb21d8
Contents?: true
Size: 1.77 KB
Versions: 2
Compression:
Stored size: 1.77 KB
Contents
require 'spec_helper' require 'support/client_helper' describe "OandaAPI::Resource::Trade" do let(:account) { ClientHelper.account } it "gets a list of trades", :vcr do VCR.use_cassette("trades.get") do ClientHelper.create_trade trades = account.trades.get expect(trades.first).to be_an OandaAPI::Resource::Trade end end it "gets a filtered list of trades", :vcr do VCR.use_cassette("trades(filter).get") do ClientHelper.create_trade(instrument: "USD_JPY") trades = account.trades(instrument: "USD_JPY").get expect(trades.first).to be_an OandaAPI::Resource::Trade end end it "gets information on a specific trade", :vcr do VCR.use_cassette("trade(id).get") do trade_id = ClientHelper.create_trade.trade_opened.id trade = account.trade(trade_id).get expect(trade).to be_an OandaAPI::Resource::Trade end end it "modifies an open trade " do VCR.use_cassette("trade(options).modify") do order = ClientHelper.create_trade modified_order = account.trade(id: order.trade_opened.id, take_profit: order.price + 2.0) .update expect(modified_order).to be_an OandaAPI::Resource::Trade end end it "closes an open trade" do VCR.use_cassette("trade(id).close") do ClientHelper.create_trade(instrument: "USD_JPY").trade_opened.id # Get the oldest open trade for USD_JPY, so we can close that trade. oldest_trade = account.trades(instrument: "USD_JPY") .get .min_by(&:id) closed_trade = account.trade(oldest_trade.id).close expect(closed_trade).to be_an OandaAPI::Resource::Trade open_trades = account.trades.get expect(open_trades.map(&:id)).to_not include oldest_trade.id end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
oanda_api-0.9.6 | spec/oanda_api/examples/trades_spec.rb |
oanda_api-0.9.5 | spec/oanda_api/examples/trades_spec.rb |