Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DO NOT MERGE] Post-competition changes #318

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
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
125 changes: 42 additions & 83 deletions docker/dev/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,55 @@

version: '3'
services:
sandbox:
sandbox1:
image: nutc-exchange
build:
context: ../..
dockerfile: exchange/docker/sandbox/Dockerfile
args:
firebase_emulator: "false"
restart: unless-stopped
environment:
- NUTC_EXPOSE_METRICS=1
command: ["--sandbox"]
- NUTC_ALGO_ENDPOINT=http://webserver:16124/algorithms/HFT
- NUTC_ID=0
depends_on:
- webserver
# sandbox2:
# image: nutc-exchange
# build:
# context: ../..
# dockerfile: exchange/docker/sandbox/Dockerfile
# restart: unless-stopped
# environment:
# - NUTC_EXPOSE_METRICS=1
# - NUTC_ALGO_ENDPOINT=http://webserver:16124/algorithms/HFT
# - NUTC_ID=1
# depends_on:
# - webserver
# sandbox3:
# image: nutc-exchange
# build:
# context: ../..
# dockerfile: exchange/docker/sandbox/Dockerfile
# restart: unless-stopped
# environment:
# - NUTC_EXPOSE_METRICS=1
# - NUTC_ALGO_ENDPOINT=http://webserver:16124/algorithms/HFT
# - NUTC_ID=2
# depends_on:
# - webserver
sandbox4:
image: nutc-exchange
build:
context: ../..
dockerfile: exchange/docker/sandbox/Dockerfile
restart: unless-stopped
environment:
- NUTC_EXPOSE_METRICS=1
- NUTC_ALGO_ENDPOINT=http://webserver:16124/algorithms/HFT
- NUTC_ID=3
depends_on:
- webserver
# command: ["--sandbox"]

#port: 16124
webserver:
Expand All @@ -23,15 +61,6 @@ services:
dockerfile: webserver/Dockerfile
restart: unless-stopped

linter:
image: nutc-linter
restart: unless-stopped
build:
context: ../..
dockerfile: exchange/docker/linter/Dockerfile
args:
firebase_emulator: "false"

# Exposed on port 9000
prometheus:
image: prom/prometheus
Expand All @@ -42,16 +71,6 @@ services:
- '--storage.tsdb.retention.time=12h'
restart: unless-stopped

reverse-proxy:
image: nginx:latest
ports:
- "26389:80"
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
restart: unless-stopped
depends_on:
- webserver
- grafana

grafana:
image: grafana/grafana
Expand All @@ -68,63 +87,3 @@ services:
- ../../exchange/docker/dev/grafana_data:/var/lib/grafana
# - /var/lib/grafana/grafana.db
# - /var/lib/grafana/alerting

web:
image: node:latest
restart: unless-stopped
working_dir: /app
environment:
- PORT=3001
volumes:
- ../../web:/app
command: ["npm", "run", "dev",]
ports:
- "3001:3001"
depends_on:
- postgres

localstack:
image: localstack/localstack
restart: unless-stopped
ports:
- "4566:4566"
- "4571:4571"
- "8080:8080"
environment:
- SERVICES=s3
- DEFAULT_REGION=us-east-1
- DATA_DIR=/var/lib/localstack/data
- AWS_ACCESS_KEY_ID=test
- AWS_SECRET_ACCESS_KEY=test
- S3_FORCE_PATH_STYLE=true
volumes:
- localstack:/var/lib/localstack

awscli:
image: amazon/aws-cli
environment:
AWS_ACCESS_KEY_ID: test
AWS_SECRET_ACCESS_KEY: test
AWS_DEFAULT_REGION: us-east-1
depends_on:
- localstack
volumes:
- ../../web/dev/local-dev-setup.sh:/home/init.sh
- ../../web/dev/cors.json:/home/cors.json
entrypoint: /home/init.sh

postgres:
image: postgres:13
restart: always
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: nutc
ports:
- "5432:5432"
volumes:
- postgres_data:/var/lib/postgresql/data

volumes:
postgres_data:
localstack:
1 change: 1 addition & 0 deletions exchange/benchmark/src/orderbook.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "common/util.hpp"
#include "exchange/orders/orderbook/limit_orderbook.hpp"
#include "helpers/benchmark_trader.hpp"

Expand Down
Binary file modified exchange/docker/dev/grafana_data/grafana.db
Binary file not shown.
2 changes: 1 addition & 1 deletion exchange/docker/sandbox/prometheus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ global:
scrape_configs:
- job_name: 'exchange-sandbox'
static_configs:
- targets: ['sandbox:4152']
- targets: ['sandbox1:4152', 'sandbox2:4152', 'sandbox3:4152', 'sandbox4:4152']
5 changes: 3 additions & 2 deletions exchange/src/common/compilation/compile_cpp.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "compile_cpp.hpp"

#include "common/file_operations/file_operations.hpp"
#include "common/util.hpp"

#include <optional>
Expand Down Expand Up @@ -43,8 +44,8 @@ compile_cpp(const std::filesystem::path& filepath)

if (result) {
throw std::runtime_error(fmt::format(
"Compilation of {} failed. Compiler output below:\n {}", filepath.string(),
result.value()
"Compilation of {} failed. Compiler output below:\n {}\n Code: {}",
filepath.string(), result.value(), read_file_content(filepath.string())
));
}
return binary_output;
Expand Down
36 changes: 20 additions & 16 deletions exchange/src/common/messages_wrapper_to_exchange.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ struct init_message {
struct cancel_order {
Ticker ticker;
order_id_t order_id;
std::uint64_t timestamp = get_time();
std::uint64_t timestamp;

cancel_order(Ticker ticker, order_id_t order_id, std::uint64_t timestamp) :
ticker(ticker), order_id(order_id), timestamp(timestamp)
{}

cancel_order() = default;

bool
operator==(const cancel_order& other) const
Expand All @@ -31,12 +37,13 @@ struct market_order {
Ticker ticker;
Side side;
decimal_quantity quantity;
std::uint64_t timestamp = get_time();
std::uint64_t timestamp;

constexpr market_order() = default;

market_order(Ticker ticker, Side side, decimal_quantity quantity) :
ticker(ticker), side(side), quantity(quantity)
market_order(
Ticker ticker, Side side, decimal_quantity quantity, std::uint64_t timestamp
) : ticker(ticker), side(side), quantity(quantity), timestamp(timestamp)
{}

bool
Expand All @@ -50,7 +57,7 @@ struct market_order {
struct limit_order : market_order {
decimal_price price;
bool ioc{false};
order_id_t order_id = generate_order_id();
order_id_t order_id;

// TODO: fix tests and remove
bool
Expand All @@ -61,16 +68,12 @@ struct limit_order : market_order {
&& ioc == other.ioc;
}

limit_order(
std::string_view ticker, Side side, decimal_quantity quantity,
decimal_price price, bool ioc = false
) : market_order{force_to_ticker(ticker), side, quantity}, price{price}, ioc{ioc}
{}

limit_order(
Ticker ticker, Side side, decimal_quantity quantity, decimal_price price,
bool ioc = false
) : market_order{ticker, side, quantity}, price{price}, ioc{ioc}
bool ioc, std::uint64_t timestamp, order_id_t order_id
) :
market_order{ticker, side, quantity, timestamp}, price{price}, ioc{ioc},
order_id{order_id}
{}

limit_order() = default;
Expand All @@ -85,15 +88,16 @@ using IncomingMessageVariant =
template <>
struct glz::meta<nutc::common::cancel_order> {
using t = nutc::common::cancel_order;
static constexpr auto value = object("cancel", &t::ticker, &t::order_id);
static constexpr auto value =
object("cancel", &t::ticker, &t::order_id, &t::timestamp);
};

/// \cond
template <>
struct glz::meta<nutc::common::limit_order> {
using t = nutc::common::limit_order;
static constexpr auto value = object(
"limit", &t::timestamp, &t::ticker, &t::side, &t::quantity, &t::price, &t::ioc,
"limit", &t::ticker, &t::side, &t::quantity, &t::timestamp, &t::price, &t::ioc,
&t::order_id
);
};
Expand All @@ -103,7 +107,7 @@ template <>
struct glz::meta<nutc::common::market_order> {
using t = nutc::common::market_order;
static constexpr auto value =
object("market", &t::timestamp, &t::ticker, &t::side, &t::quantity);
object("market", &t::ticker, &t::side, &t::quantity, &t::timestamp);
};

/// \cond
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
#include <sched.h>
#include <cstdint>

#ifdef __linux__
Expand Down Expand Up @@ -26,6 +27,19 @@ set_memory_limit(std::size_t limit_in_mb)
}
return true;
}

inline bool
set_cpu_affinity(int cpu)
{
cpu_set_t mask;
CPU_ZERO(&mask);
CPU_SET(cpu, &mask);

if (sched_setaffinity(0, sizeof(mask), &mask) == -1) {
return false;
}
return true;
}
} // namespace nutc::wrapper
#else
namespace nutc::wrapper {
Expand Down
8 changes: 6 additions & 2 deletions exchange/src/common/types/algorithm/remote_algorithm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ namespace nutc::common {
class RemoteAlgorithm : public BaseAlgorithm {
std::string id_;
std::string algo_data_;
std::string display_name_;

public:
RemoteAlgorithm(AlgoLanguage language, std::string algo_id, std::string algo_data) :
RemoteAlgorithm(
AlgoLanguage language, std::string algo_id, std::string algo_data,
std::string display_name
) :
BaseAlgorithm{language}, id_{std::move(algo_id)},
algo_data_{std::move(algo_data)}
algo_data_{std::move(algo_data)}, display_name_{std::move(display_name)}
{}

std::string
Expand Down
10 changes: 6 additions & 4 deletions exchange/src/common/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <fmt/format.h>
#include <x86intrin.h>

#include <random>
#include <atomic>

namespace nutc::common {
namespace bi = boost::archive::iterators;
Expand Down Expand Up @@ -52,9 +52,11 @@ find_project_file(const std::string& file_name)
order_id_t
generate_order_id()
{
static std::mt19937_64 gen{std::random_device{}()};
static std::uniform_int_distribution<order_id_t> dis;
return dis(gen);
// static constexpr auto MAX_PID_BITS = 22;
static auto pid = static_cast<std::int64_t>(getpid());
// static std::atomic<std::int64_t> start_order_id{(pid << 46)};
static std::int64_t start_order_id{(pid<<46)};
return ++start_order_id;
}

uint64_t
Expand Down
Loading
Loading