Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion features/support/FIX50SP1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5958,6 +5958,7 @@
<value enum="0" description="COVERED"/>
<value enum="1" description="UNCOVERED"/>
</field>
<field number='205' name='MaturityDay' type='DAYOFMONTH' />
<field number="206" name="OptAttribute" type="CHAR"/>
<field number="207" name="SecurityExchange" type="EXCHANGE"/>
<field number="208" name="NotifyBrokerOfCredit" type="BOOLEAN">
Expand Down Expand Up @@ -9416,4 +9417,4 @@
<value enum="2" description="HEARTBEAT_MESSAGE_INDICATING_THAT_APPLICATION_IDENTIFIED_BY_REFAPPLID_FOR_THE_APPLICATION_SEQUENCE_NUMBER_OF_THE_PREVIOUS_MESSAGE_"/>
</field>
</fields>
</fix>
</fix>
26 changes: 17 additions & 9 deletions lib/fix_spec/support/fix_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,25 @@ def add_field msgPart, fieldName, fieldValue
end

case FIXSpec::data_dictionary.get_field_type(tag).name
when "INT","DAYOFMONTH" then
when "DAYOFMONTH" then
msgPart.setInt(tag, fieldValue.to_i)
when "PRICE","FLOAT","QTY" then
msgPart.setDouble(tag, fieldValue.to_f)
when "BOOLEAN" then
msgPart.setBoolean(tag, fieldValue == "true")
when "INT" then
if FIXSpec::data_dictionary.reverse_lookup[tag].empty? # not enum
msgPart.setInt(tag, fieldValue.to_i)
when "PRICE","FLOAT","QTY" then
msgPart.setDouble(tag, fieldValue.to_f)
when "BOOLEAN" then
msgPart.setBoolean(tag, fieldValue == "true")
else
#enum description => enum value
#e.g. tag 54 "BUY"=>"1"
fieldValue = FIXSpec::data_dictionary.get_reverse_value_name(tag, fieldValue)
else # enum
msgPart.setString(tag, FIXSpec::data_dictionary.get_reverse_value_name(tag, fieldValue))
end
else
if FIXSpec::data_dictionary.reverse_lookup[tag].empty? # not enum
msgPart.setString(tag, fieldValue)
else # enum
fieldValue = FIXSpec::data_dictionary.get_reverse_value_name(tag, fieldValue)
msgPart.setString(tag, FIXSpec::data_dictionary.get_reverse_value_name(tag, fieldValue))
end
end
else
tag = fieldName.to_i
Expand Down
95 changes: 95 additions & 0 deletions spec/fix_spec/support/fix_helpers_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
require 'spec_helper'

describe 'support/fix_helpers mixin' do
require 'fix_spec/support/fix_helpers'

let(:app_dict) {FIXSpec::DataDictionary.new "features/support/FIX50SP1.xml" }
let(:session_dict) {FIXSpec::DataDictionary.new "features/support/FIXT11.xml" }

describe 'add_field' do
before(:each) do
FIXSpec::session_data_dictionary = session_dict
FIXSpec::application_data_dictionary = app_dict
@msgPart = new_message('News', 'FIXT.1.1') # msgtype doesn't matter for this test
end

it 'INT (not an enum)' do
add_field(@msgPart,'TotNoOrders','123')
@msgPart.to_s.should include('68=123')
end

it 'DAYOFMONTH' do
add_field(@msgPart,'MaturityDay','15')
@msgPart.to_s.should include('205=15')
end

it 'PRICE' do
add_field(@msgPart,'StrikePrice','3.50')
@msgPart.to_s.should include('202=3.5')
end

it 'FLOAT' do
add_field(@msgPart,'PegOffsetValue','9.25')
@msgPart.to_s.should include('211=9.25')
end

it 'QTY' do
add_field(@msgPart,'CumQty','9.87')
@msgPart.to_s.should include('14=9.87')
end

describe 'BOOLEAN' do
it '"Y" if "true"' do
add_field(@msgPart,'ForexReq','true')
@msgPart.to_s.should include('121=Y')
end
it '"N" if anything but "true"' do
add_field(@msgPart,'LocateReqd','swiss cake roll')
@msgPart.to_s.should include('114=N')
end
end

it 'STRING' do
add_field(@msgPart,'Text','foobar')
@msgPart.to_s.should include('58=foobar')
end

it 'CHAR (not an enum)' do
add_field(@msgPart,'OptAttribute','h')
@msgPart.to_s.should include('206=h')
end

describe 'enum-INT' do
it 'convert if found' do
add_field(@msgPart,'TradeRequestType','MATCHED_TRADES_MATCHING_CRITERIA_PROVIDED_ON_REQUEST')
@msgPart.to_s.should include('569=1')
end
it 'use as-is if not found' do
add_field(@msgPart,'TradeRequestType','JUDAS PRIEST')
@msgPart.to_s.should include('569=JUDAS PRIEST')
end
end

describe 'enum-CHAR' do
it 'convert if found' do
add_field(@msgPart,'SettlInstSource','INVESTOR')
@msgPart.to_s.should include('165=3')
end
it 'use as-is if not found' do
add_field(@msgPart,'SettlInstSource','BAD BUNNY')
@msgPart.to_s.should include('165=BAD BUNNY')
end
end

describe 'enum-STRING' do
it 'convert if found' do
add_field(@msgPart,'MatchType','ACT_M6_MATCH')
@msgPart.to_s.should include('574=M6')
end
it 'use as-is if not found' do
add_field(@msgPart,'MatchType',"green tea oh wait that's match-AH")
@msgPart.to_s.should include("574=green tea oh wait that's match-AH")
end
end
end
end