base pos tests
This commit is contained in:
1 parent
74f2e2ac50
commit
1090422fa2
1 file changed
+42
@@ -258,7 +258,49 @@ TEST_CASE("base_position", "[position_internal]"){
|
||||
REQUIRE(pu!=nullptr);
|
||||
compare_pos(pu->sod(),5000,0.05,0,0);
|
||||
compare_pos(pu->day(),0,0,0,0);
|
||||
}
|
||||
SECTION("base+sod+day"){
|
||||
// fills on either side of SOD, then a base position
|
||||
// comes in and overrides the SOD
|
||||
timeval sod = SODPosition::now();
|
||||
PositionMap pmap (sod);
|
||||
timeval pre_sod = sod, post_sod = sod;
|
||||
pre_sod.tv_sec = pre_sod.tv_sec - 60*60;
|
||||
post_sod.tv_sec = post_sod.tv_sec + 60*60;
|
||||
// presod fill
|
||||
Fill presod_f = create_fill(1, 1, 10, 50, api::Side::SIDE_BUY, Fill::FILL_KIND_STANDARD);
|
||||
presod_f.mutable_timestamp()->CopyFrom(SODPosition::to_timestamp(pre_sod));
|
||||
pmap.on_fill(presod_f,true);
|
||||
presod_f = create_fill(1, 2, 30, 50, api::Side::SIDE_BUY, Fill::FILL_KIND_STANDARD);
|
||||
presod_f.mutable_timestamp()->CopyFrom(SODPosition::to_timestamp(pre_sod));
|
||||
pmap.on_fill(presod_f,true);
|
||||
// postsod fill
|
||||
Fill postsod_f = create_fill(1, 1, 20, 100, api::Side::SIDE_BUY, Fill::FILL_KIND_STANDARD);
|
||||
postsod_f.mutable_timestamp()->CopyFrom(SODPosition::to_timestamp(post_sod));
|
||||
pmap.on_fill(postsod_f,true);
|
||||
|
||||
PositionUnit const* pu = pmap.test_only_pos(1,1);
|
||||
REQUIRE(pu!=nullptr);
|
||||
compare_pos(pu->sod(),50,10,0,0);
|
||||
compare_pos(pu->day(),100,20,0,0);
|
||||
pu = pmap.test_only_pos(1,2);
|
||||
compare_pos(pu->sod(),50,30,0,0);
|
||||
compare_pos(pu->day(),0,0,0,0);
|
||||
// now enter a base position, it should override the SOD
|
||||
BasePositionBatch bp_batch;
|
||||
bp_batch.add_positions()->CopyFrom(create_base_pos(1,1,11,51,api::Side::SIDE_SELL));
|
||||
bp_batch.mutable_current_as_of()->CopyFrom(SODPosition::to_timestamp(sod));
|
||||
pmap.set_base_position(bp_batch);
|
||||
|
||||
pu = pmap.test_only_pos(1,1);
|
||||
REQUIRE(pu!=nullptr);
|
||||
compare_pos(pu->sod(),0,0,51,11); // sod is overriden by bp
|
||||
compare_pos(pu->day(),100,20,0,0); // day remains the same
|
||||
// sec 2 gets wiped out
|
||||
pu = pmap.test_only_pos(1,2);
|
||||
REQUIRE(pu!=nullptr);
|
||||
compare_pos(pu->sod(),0,0,0,0); // sod is overriden by bp
|
||||
compare_pos(pu->day(),0,0,0,0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user