Commit cbf56459 authored by Sergey Gernyak's avatar Sergey Gernyak

FEAT: completed placeOrders method

parent 759ffbb9
......@@ -59,6 +59,12 @@ module BetfairApiNgRails
autoload :PriceSize, 'betfair_api_ng_rails/api/data/price_size'
autoload :PriceProjection, 'betfair_api_ng_rails/api/data/price_projection'
autoload :ExBestOffersOverrides, 'betfair_api_ng_rails/api/data/ex_best_offers_overrides'
autoload :PlaceExecutionReport, 'betfair_api_ng_rails/api/data/place_execution_report'
autoload :PlaceInstructionReport,'betfair_api_ng_rails/api/data/place_instruction_report'
autoload :PlaceInstruction, 'betfair_api_ng_rails/api/data/place_instruction'
autoload :LimitOrder, 'betfair_api_ng_rails/api/data/limit_order'
autoload :LimitOnCloseOrder, 'betfair_api_ng_rails/api/data/limit_on_close_order'
autoload :MarketOnCloseOrder, 'betfair_api_ng_rails/api/data/market_on_close_order'
module Concerns
autoload :Hashable, 'betfair_api_ng_rails/api/data/concerns/hashable'
......@@ -116,6 +122,7 @@ module BetfairApiNgRails
autoload :ListMarketTypes, 'betfair_api_ng_rails/api/parsers/list_market_types'
autoload :ListMarketCatalogue, 'betfair_api_ng_rails/api/parsers/list_market_catalogue'
autoload :ListMarketBook, 'betfair_api_ng_rails/api/parsers/list_market_book'
autoload :PlaceOrders, 'betfair_api_ng_rails/api/parsers/place_orders'
end
module ConnectionExt
......
......@@ -4,7 +4,6 @@ module BetfairApiNgRails
module Api
module ConnectionExt
module Parsing
def self.included(base)
base.send :class_eval, <<-CODE
def request_with_parsing(method, params = {})
......@@ -16,13 +15,12 @@ module BetfairApiNgRails
CODE
end
private
private
def init_parser(method, responser)
"BetfairApiNgRails::Api::Parsers::#{method.camelize}".constantize.new responser
end
end
end
end
end
\ No newline at end of file
end
......@@ -27,7 +27,8 @@ module BetfairApiNgRails
"listMarketBook",
"listCurrentOrders",
"listClearedOrders",
"listMarketProfitAndLoss"
"listMarketProfitAndLoss",
"placeOrders"
]
ALLOWED_FORMATTING = [
......@@ -59,4 +60,4 @@ module BetfairApiNgRails
end
end
end
\ No newline at end of file
end
......@@ -3,7 +3,6 @@ module BetfairApiNgRails
module Data
module Concerns
module Attributable
DEFAULT_OPTIONS = { type: String, array: false }
def self.included(base)
......@@ -11,13 +10,12 @@ module BetfairApiNgRails
end
module ClassMethods
def attributes(attrs)
define_class_attrs attrs
define_attr_accessors
end
private
private
def define_class_attrs(attrs)
class << self; attr_accessor :class_attrs; end
......@@ -41,11 +39,9 @@ module BetfairApiNgRails
def fetch_attr_options(attrib)
attrib.is_a?(Hash) ? DEFAULT_OPTIONS.merge(attrib.values.first) : DEFAULT_OPTIONS
end
end
end
end
end
end
end
\ No newline at end of file
end
module BetfairApiNgRails
module Api
module Data
class PlaceExecutionReport < Api::Data::Base
include Api::Data::Concerns::Hashable
PLACE_EXECUTION_REPORT_ATTRS = [
:customer_ref,
:status,
:error_code,
:market_id,
{instruction_reports: {type: BetfairApiNgRails::PlaceInstructionReport, array: true}}
]
attributes PLACE_EXECUTION_REPORT_ATTRS
def self.to_hash_attrs
PLACE_EXECUTION_REPORT_ATTRS
end
end
end
end
end
......@@ -23,6 +23,3 @@ module BetfairApiNgRails
end
end
end
module BetfairApiNgRails
module Api
module Data
class PlaceInstructionReport < Api::Data::Base
include Api::Data::Concerns::Hashable
PLACE_INSTRUCTION_REPORT_ATTRS = [
:status,
:error_code,
{instruction: {type: BetfairApiNgRails::PlaceInstruction}},
:bet_id,
:placed_date,
:average_price_matched,
:size_matched
]
attributes PLACE_INSTRUCTION_REPORT_ATTRS
def self.to_hash_attrs
PLACE_INSTRUCTION_REPORT_ATTRS
end
end
end
end
end
module BetfairApiNgRails
module Api
module Parsers
class PlaceOrders < Api::Parsers::SingleBase
private
def data_class
Api::Data::PlaceExecutionReport
end
end
end
end
end
module BetfairApiNgRails
module Api
module Parsers
class SingleBase
class SingleBase < Api::Parsers::Base
def process
process_row fetch_result_json
end
......
......@@ -28,7 +28,7 @@ module BetfairApiNgRails
private
def run_request(method, params, data)
def run_request(method, params, data = {})
BetfairApiNgRails.connection.request build_request_type(method), params.merge(data)
end
......
require 'spec_helper'
require 'pry-nav'
describe "placeOrders request method" do
let(:method_name) { "place_orders" }
let(:result_class) { BetfairApiNgRails::PlaceExecutionReport }
let(:result_hash) do
<<-JSON
{"result":
{
"customerRef": "q2f3f",
"status": "SOME_STATUS",
"errorCode": "",
"marketId": "1.112312312",
"instructionReports":[
{}
]
}
}
JSON
end
let(:parameters) do
{ market_id: '1.111111', customer_ref: 'dqd23d23', instructions: [] }
end
let(:logger) { double(:logger) }
before(:each) do
BetfairApiNgRails.config.formatter = nil
BetfairApiNgRails.log = logger
allow(logger).to receive(:write)
end
context 'when no error occured' do
it_behaves_like 'request method' do
it { is_expected.not_to be_nil }
its(:customer_ref) { is_expected.to eq("q2f3f") }
its(:status) { is_expected.to eq("SOME_STATUS") }
its(:error_code) { is_expected.to eq("") }
its(:market_id) { is_expected.to eq("1.112312312") }
its(:instruction_reports) { is_expected.to_not be_empty }
end
end
context 'when api error occured' do
it_behaves_like 'request method' do
let(:result_hash) { "{\"error\":{\"code\":-32700,\"message\":\"DSC-3000\"}}" }
it "raise APINGException" do
expect{ subject }.to raise_error
end
end
end
end
shared_examples 'request method' do
let(:ssoid) { 'vnboeirubvyebvuekrybobvuiberlvbre' }
let(:connection) { BetfairApiNgRails::Api::Connection.new }
let(:http_response) { double(:http_response, code: '200', body: result_hash) }
......@@ -14,5 +13,4 @@ shared_examples 'request method' do
end
subject { TestModule.send(method_name, parameters) }
end
\ No newline at end of file
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment