From 23c799ac3ac23b3c7d8fcbb51cc2d7f5bae09990 Mon Sep 17 00:00:00 2001 From: Eric Harding Date: Wed, 22 Aug 2018 11:08:40 -0400 Subject: [PATCH] SPARK-1570 round_to_quote_price WIP --- src/client/spark_core/TestRunner/ConsoleEx.cs | 15 +++++ src/lib/domain_model/Security.h | 2 +- src/lib/domain_model/tests/domain_tests.cpp | 57 +++++++++++++++++++ 3 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 src/lib/domain_model/tests/domain_tests.cpp diff --git a/src/client/spark_core/TestRunner/ConsoleEx.cs b/src/client/spark_core/TestRunner/ConsoleEx.cs index 9e789c179..0e3391e15 100644 --- a/src/client/spark_core/TestRunner/ConsoleEx.cs +++ b/src/client/spark_core/TestRunner/ConsoleEx.cs @@ -20,5 +20,20 @@ namespace bts.test { } } + public static T prompt(string prompt, params T[] options) { + Console.WriteLine(prompt); + for (int x = 1; x <= options.Length; ++x) { + Write($"{x}. ", ConsoleColor.Yellow); + WriteLine(options[x].ToString()); + } + int response; + do { + Int32.TryParse(Console.ReadKey().ToString(), out response); + if (response > options.Length) response = 0; + } while (response == 0); + return options[response]; + } + + } } \ No newline at end of file diff --git a/src/lib/domain_model/Security.h b/src/lib/domain_model/Security.h index 95559a207..f88a63be4 100644 --- a/src/lib/domain_model/Security.h +++ b/src/lib/domain_model/Security.h @@ -32,7 +32,7 @@ inline Price encode_exchange_price(api::Security const&sec, Price in) { inline double raw_round_to_quote_price (double raw_price, double tick_size, api::Side side) { - double factor = 1000000; + double factor = 1000000000; auto i_price = llround (factor * raw_price); auto i_tick_size = llround (tick_size * factor); diff --git a/src/lib/domain_model/tests/domain_tests.cpp b/src/lib/domain_model/tests/domain_tests.cpp new file mode 100644 index 000000000..bba06ac39 --- /dev/null +++ b/src/lib/domain_model/tests/domain_tests.cpp @@ -0,0 +1,57 @@ + +#include "catch/catch.hpp" +#include "../Security.h" + +namespace bts { +namespace test { + +TEST_CASE("rounding_tests", "[md]") { + SECTION("test_price_size") { + + const double tick_sizes[] { + // Dan's production system + // ./sparkd configcheck Symbols | grep future | sed -e 's/.*future: \"\(.*\)\"/\1/' | xargs -I{} sh -c "./sparkd md dump {} future glbx" | grep -o low_tick': [0-9.]\+ + 0.0078125, + 0.015625, + 0.03125, + 0.1, + 0.25, + 1, + // From Kevin's ramblings + // 2.5/320, + // 31./32, + // 10./32, + // 10.25/32, + // 10.375/32, + // 10.125/32, + // 10.25/32, + // .0025, + // .0000001, + // 1./32, + // 0.5/32, + // 0.25/32, + // 0.125/32, + // 0.01, + // 0.005, + // 1./100000, + // 1./16, + }; + + for (double tick : tick_sizes) { + // For valid prices from -101 to 101 + std::vector prices; + for (double price = 0; price < 101; price += tick) { + // Since all prices are valid ticks rounding should not change them + const double epsilon = 1e-9; + for (api::Side side : { api::Side::SIDE_BUY, api::Side::SIDE_SELL }) { + double rounded = securities::raw_round_to_quote_price(price, tick, side); + REQUIRE(std::abs(price-rounded) <= epsilon); + } + } + } + } +} + + + +}} \ No newline at end of file