Merge branch 'SPARK-1570' of bitbucket.org:bluetradesys/spark
This commit is contained in:
commit
e33642d325
3 files changed
+73
-1
No files matched your search
@@ -20,5 +20,20 @@ namespace bts.test {
|
||||
}
|
||||
}
|
||||
|
||||
public static T prompt<T>(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];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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<double> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}}
|
||||
Reference in new issue
Block a user