Skip to content

Commit

Permalink
Merge pull request #321 from northwesternfintech/fmt
Browse files Browse the repository at this point in the history
Fix formatting and format exchange repository
  • Loading branch information
stevenewald authored Oct 28, 2024
2 parents ee77287 + 0cba082 commit 9a42562
Show file tree
Hide file tree
Showing 23 changed files with 122 additions and 148 deletions.
2 changes: 1 addition & 1 deletion exchange/cmake/lint.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ foreach(file IN LISTS files)
if(NOT result EQUAL "0")
message(FATAL_ERROR "'${file}': formatter returned with ${result}")
endif()
if(NOT FIX AND output MATCHES "incomplete_format='true'")
if(NOT FIX AND output MATCHES "\n<replacement offset")
string(SUBSTRING "${file}" "${path_prefix_length}" -1 relative_file)
list(APPEND badly_formatted "${relative_file}")
endif()
Expand Down
4 changes: 2 additions & 2 deletions exchange/src/exchange/algos/normal_mode/normal_mode.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "normal_mode.hpp"

#include "common/logging/logging.hpp"
#include "common/util.hpp"
#include "exchange/curl/curl.hpp"
#include "common/logging/logging.hpp"
#include "exchange/traders/trader_types/algo_trader.hpp"
#include "exchange/wrappers/creation/rmq_wrapper_init.hpp"

Expand Down Expand Up @@ -40,7 +40,7 @@ NormalModeAlgoInitializer::initialize_trader_container(
std::string algo_id = user["latestAlgoId"].get<std::string>();

try {
// TODO: add back
// TODO: add back
// traders.add_trader<AlgoTrader>(common::RemoteAlgorithm{}, start_capital);
log_i(main, "Created user");
} catch (const std::runtime_error& err) {
Expand Down
3 changes: 2 additions & 1 deletion exchange/src/exchange/bots/bot_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ BotContainer::generate_orders(

for (const auto& bot : bots_) {
cumulative_interest_limit += bot->get_portfolio().get_initial_capital();
cumulative_quantity_held += bot->get_portfolio().get_holdings(bot->get_ticker());
cumulative_quantity_held +=
bot->get_portfolio().get_holdings(bot->get_ticker());
}

return generate_orders(
Expand Down
6 changes: 4 additions & 2 deletions exchange/src/exchange/matching/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,12 @@ attempt_match_(OrderPairT& orders, common::decimal_price order_fee)
GenericTrader* buyer = buy_order.trader;
GenericTrader* seller = sell_order.trader;

if (!buyer->can_leverage() && buyer->get_portfolio().get_capital() < total_price) [[unlikely]]
if (!buyer->can_leverage() && buyer->get_portfolio().get_capital() < total_price)
[[unlikely]]
return glz::unexpected(MatchFailure::buyer_failure);
if (!seller->can_leverage()
&& seller->get_portfolio().get_holdings(buy_order.ticker) < match_quantity) [[unlikely]]
&& seller->get_portfolio().get_holdings(buy_order.ticker) < match_quantity)
[[unlikely]]
return glz::unexpected(MatchFailure::seller_failure);
if (buyer == seller) [[unlikely]] {
return glz::unexpected(MatchFailure::buyer_failure);
Expand Down
2 changes: 1 addition & 1 deletion exchange/src/exchange/theo/brownian.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class BrownianMotion {
generate_norm_(double mean, double stdev, Signedness sign = Signedness::Either);
double generate_uniform_(double low, double high);
bool generate_bool_(double probability_of_true);
bool market_event_ongoing_() const;
bool market_event_ongoing_() const;

double
generate_brownian_motion_(double mean, Signedness direction = Signedness::Either);
Expand Down
2 changes: 1 addition & 1 deletion exchange/src/exchange/wrappers/messaging/pipe_reader.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "pipe_reader.hpp"

#include "async_pipe_runner.hpp"
#include "common/messages_wrapper_to_exchange.hpp"
#include "common/logging/logging.hpp"
#include "common/messages_wrapper_to_exchange.hpp"

#include <boost/asio.hpp>
#include <glaze/glaze.hpp>
Expand Down
2 changes: 1 addition & 1 deletion exchange/src/linter/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

// Common headers

#include "linter/config.h"
#include "common/logging/logging.hpp"
#include "linter/config.h"

#include <cassert>
#include <cinttypes>
Expand Down
2 changes: 1 addition & 1 deletion exchange/src/linter/runtime/runtime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@ class Runtime {
{}
};

} // namespace nutc::lint
} // namespace nutc::linter
2 changes: 1 addition & 1 deletion exchange/src/wrapper/messaging/exchange_communicator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ExchangeCommunicator {

algorithm_content consume_algorithm();

common::tick_update consume_tick_update();
common::tick_update consume_tick_update();

static void publish_message(const std::string& message);

Expand Down
25 changes: 11 additions & 14 deletions exchange/test/src/integration/test_algos/cpp/buy_eth.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <string>

enum class Side { buy = 0, sell = 1 };
enum class Ticker: std::uint8_t { ETH = 0, BTC = 1, LTC = 2 }; // NOLINT
enum class Ticker : std::uint8_t { ETH = 0, BTC = 1, LTC = 2 }; // NOLINT

/**
* Place a market order
Expand All @@ -18,8 +18,7 @@ enum class Ticker: std::uint8_t { ETH = 0, BTC = 1, LTC = 2 }; // NOLINT
*
* @return true if order succeeded, false if order failed due to rate limiting
*/
bool
place_market_order(Side side, Ticker ticker, float quantity);
bool place_market_order(Side side, Ticker ticker, float quantity);

/**
* Place a limit order
Expand All @@ -37,8 +36,7 @@ place_market_order(Side side, Ticker ticker, float quantity);
* @return true if order succeeded, false if order failed due to rate limiting
*/
std::int64_t place_limit_order(
Side side, Ticker ticker, float quantity, float price,
bool ioc = false
Side side, Ticker ticker, float quantity, float price, bool ioc = false
);

bool cancel_order(Ticker ticker, std::int64_t order_id);
Expand All @@ -51,8 +49,8 @@ class Strategy {
* Called whenever two orders match. Could be one of your orders, or two other
* people's orders.
*
* @param ticker Ticker of the orders that were matched (Ticker::ETH, Ticker::BTC, or
* "LTC)
* @param ticker Ticker of the orders that were matched (Ticker::ETH, Ticker::BTC,
* or "LTC)
* @param side Side of the orders that were matched (Side::buy or Side::sell)
* @param price Price that trade was executed at
* @quantity quantity Volume traded
Expand All @@ -65,29 +63,28 @@ class Strategy {
* Called whenever the orderbook changes. This could be because of a trade, or
* because of a new order, or both.
*
* @param ticker Ticker that has an orderbook update (Ticker::ETH, Ticker::BTC, or "LTC")
* @param ticker Ticker that has an orderbook update (Ticker::ETH, Ticker::BTC, or
* "LTC")
* @param side Which orderbook as updated (Side::buy or Side::sell)
* @param price Price of orderbook that has an update
* @param quantity Volume placed into orderbook
*/
void
on_orderbook_update(
Ticker ticker, Side side, float quantity, float price
)
on_orderbook_update(Ticker ticker, Side side, float quantity, float price)
{}

/**
* Called whenever one of your orders is filled.
*
* @param ticker Ticker of order that was fulfilled (Ticker::ETH, Ticker::BTC, or "LTC")
* @param ticker Ticker of order that was fulfilled (Ticker::ETH, Ticker::BTC, or
* "LTC")
* @param side Side of order that was fulfilled (Side::buy or Side::sell)
* @param price Price that order was fulfilled at
* @param quantity Amount of capital after fulfilling order
*/
void
on_account_update(
Ticker ticker, Side side, float price, float quantity,
float capital_remaining
Ticker ticker, Side side, float price, float quantity, float capital_remaining
)
{}
};
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ class Strategy {
*/
void
on_account_update(
Ticker ticker, Side side, float price, float quantity,
float capital_remaining
Ticker ticker, Side side, float price, float quantity, float capital_remaining
)
{}
};
25 changes: 11 additions & 14 deletions exchange/test/src/integration/test_algos/cpp/buy_tsla_at_100.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <string>

enum class Side { buy = 0, sell = 1 };
enum class Ticker: std::uint8_t { ETH = 0, BTC = 1, LTC = 2 }; // NOLINT
enum class Ticker : std::uint8_t { ETH = 0, BTC = 1, LTC = 2 }; // NOLINT

/**
* Place a market order
Expand All @@ -18,8 +18,7 @@ enum class Ticker: std::uint8_t { ETH = 0, BTC = 1, LTC = 2 }; // NOLINT
*
* @return true if order succeeded, false if order failed due to rate limiting
*/
bool
place_market_order(Side side, Ticker ticker, float quantity);
bool place_market_order(Side side, Ticker ticker, float quantity);

/**
* Place a limit order
Expand All @@ -37,8 +36,7 @@ place_market_order(Side side, Ticker ticker, float quantity);
* @return true if order succeeded, false if order failed due to rate limiting
*/
std::int64_t place_limit_order(
Side side, Ticker ticker, float quantity, float price,
bool ioc = false
Side side, Ticker ticker, float quantity, float price, bool ioc = false
);

bool cancel_order(Ticker ticker, std::int64_t order_id);
Expand All @@ -51,8 +49,8 @@ class Strategy {
* Called whenever two orders match. Could be one of your orders, or two other
* people's orders.
*
* @param ticker Ticker of the orders that were matched (Ticker::ETH, Ticker::BTC, or
* "LTC)
* @param ticker Ticker of the orders that were matched (Ticker::ETH, Ticker::BTC,
* or "LTC)
* @param side Side of the orders that were matched (Side::buy or Side::sell)
* @param price Price that trade was executed at
* @quantity quantity Volume traded
Expand All @@ -65,15 +63,14 @@ class Strategy {
* Called whenever the orderbook changes. This could be because of a trade, or
* because of a new order, or both.
*
* @param ticker Ticker that has an orderbook update (Ticker::ETH, Ticker::BTC, or "LTC")
* @param ticker Ticker that has an orderbook update (Ticker::ETH, Ticker::BTC, or
* "LTC")
* @param side Which orderbook as updated (Side::buy or Side::sell)
* @param price Price of orderbook that has an update
* @param quantity Volume placed into orderbook
*/
void
on_orderbook_update(
Ticker ticker, Side side, float quantity, float price
)
on_orderbook_update(Ticker ticker, Side side, float quantity, float price)
{
if (ticker == Ticker::ETH && quantity < 101 && quantity > 99) {
place_limit_order(Side::buy, Ticker::ETH, 100, 10);
Expand All @@ -83,15 +80,15 @@ class Strategy {
/**
* Called whenever one of your orders is filled.
*
* @param ticker Ticker of order that was fulfilled (Ticker::ETH, Ticker::BTC, or "LTC")
* @param ticker Ticker of order that was fulfilled (Ticker::ETH, Ticker::BTC, or
* "LTC")
* @param side Side of order that was fulfilled (Side::buy or Side::sell)
* @param price Price that order was fulfilled at
* @param quantity Amount of capital after fulfilling order
*/
void
on_account_update(
Ticker ticker, Side side, float price, float quantity,
float capital_remaining
Ticker ticker, Side side, float price, float quantity, float capital_remaining
)
{}
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <string>

enum class Side { buy = 0, sell = 1 };
enum class Ticker: std::uint8_t { ETH = 0, BTC = 1, LTC = 2 }; // NOLINT
enum class Ticker : std::uint8_t { ETH = 0, BTC = 1, LTC = 2 }; // NOLINT

/**
* Place a market order
Expand All @@ -18,8 +18,7 @@ enum class Ticker: std::uint8_t { ETH = 0, BTC = 1, LTC = 2 }; // NOLINT
*
* @return true if order succeeded, false if order failed due to rate limiting
*/
bool
place_market_order(Side side, Ticker ticker, float quantity);
bool place_market_order(Side side, Ticker ticker, float quantity);

/**
* Place a limit order
Expand All @@ -37,8 +36,7 @@ place_market_order(Side side, Ticker ticker, float quantity);
* @return true if order succeeded, false if order failed due to rate limiting
*/
std::int64_t place_limit_order(
Side side, Ticker ticker, float quantity, float price,
bool ioc = false
Side side, Ticker ticker, float quantity, float price, bool ioc = false
);

bool cancel_order(Ticker ticker, std::int64_t order_id);
Expand All @@ -51,8 +49,8 @@ class Strategy {
* Called whenever two orders match. Could be one of your orders, or two other
* people's orders.
*
* @param ticker Ticker of the orders that were matched (Ticker::ETH, Ticker::BTC, or
* "LTC)
* @param ticker Ticker of the orders that were matched (Ticker::ETH, Ticker::BTC,
* or "LTC)
* @param side Side of the orders that were matched (Side::buy or Side::sell)
* @param price Price that trade was executed at
* @quantity quantity Volume traded
Expand All @@ -65,29 +63,28 @@ class Strategy {
* Called whenever the orderbook changes. This could be because of a trade, or
* because of a new order, or both.
*
* @param ticker Ticker that has an orderbook update (Ticker::ETH, Ticker::BTC, or "LTC")
* @param ticker Ticker that has an orderbook update (Ticker::ETH, Ticker::BTC, or
* "LTC")
* @param side Which orderbook as updated (Side::buy or Side::sell)
* @param price Price of orderbook that has an update
* @param quantity Volume placed into orderbook
*/
void
on_orderbook_update(
Ticker ticker, Side side, float quantity, float price
)
on_orderbook_update(Ticker ticker, Side side, float quantity, float price)
{}

/**
* Called whenever one of your orders is filled.
*
* @param ticker Ticker of order that was fulfilled (Ticker::ETH, Ticker::BTC, or "LTC")
* @param ticker Ticker of order that was fulfilled (Ticker::ETH, Ticker::BTC, or
* "LTC")
* @param side Side of order that was fulfilled (Side::buy or Side::sell)
* @param price Price that order was fulfilled at
* @param quantity Amount of capital after fulfilling order
*/
void
on_account_update(
Ticker ticker, Side side, float price, float quantity,
float capital_remaining
Ticker ticker, Side side, float price, float quantity, float capital_remaining
)
{
if (ticker == Ticker::ETH && quantity >= 10)
Expand Down
Loading

0 comments on commit 9a42562

Please sign in to comment.