Skip to content

Commit 3228f7f

Browse files
committed
fix some errors
1 parent 78177cd commit 3228f7f

File tree

8 files changed

+41
-34
lines changed

8 files changed

+41
-34
lines changed

CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1+
cmake_minimum_required(VERSION 3.10)
12
project(stock_emu CXX)
2-
set(CMAKE_CXX_STANDARD 20)
3-
43
add_subdirectory(stock_emu_lib)
54
add_subdirectory(test)
65
add_subdirectory(preview)

stock_emu_lib/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ add_library(stock_emu_lib STATIC
99
target_include_directories(stock_emu_lib PRIVATE ../)
1010

1111
target_compile_options(stock_emu_lib PRIVATE
12-
-Wall -O0 -g
13-
)
12+
-Wall -O0 -g -Weverything
13+
-Wno-c++98-compat -Wno-padded -Wno-exit-time-destructors -Wno-global-constructors
14+
)
1415

stock_emu_lib/Stock.hpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#pragma once
2+
#include <cstddef>
23
#ifndef INCLUDE_STOCK_HPP_
34
#define INCLUDE_STOCK_HPP_
45
#include <format>
@@ -7,23 +8,26 @@
78
#include <type_traits>
89

910
struct StockCount;
10-
using StockId = int;
11+
using StockId = size_t;
1112
using StockCount_data_t = int;
1213

1314
class StockPrice {
1415
public:
15-
constexpr StockPrice(Price price) : price(price) {}
16+
constexpr StockPrice(Price price_) : price(price_) {}
1617

1718
constexpr StockPrice() : price(0) {}
1819

19-
constexpr Price operator*(int amount) const noexcept {
20-
return price * amount;
21-
}
20+
constexpr StockPrice(const StockPrice& p) : price(p.price) {}
2221

23-
constexpr Price operator*(double amount) const noexcept {
22+
constexpr Price operator*(int amount) const noexcept {
2423
return price * amount;
2524
}
2625

26+
/*
27+
constexpr Price operator*(double amount) const noexcept {
28+
return {price * amount};
29+
}
30+
*/
2731
constexpr auto operator<=>(const StockPrice& rhs) const {
2832
return this->price <=> rhs.price;
2933
}
@@ -91,7 +95,7 @@ class StockHoldingCount {
9195

9296
constexpr StockCount to_StockCount() const {
9397
return StockCount(value);
94-
};
98+
}
9599

96100
constexpr StockCount_data_t getValue() const {
97101
return value;

stock_emu_lib/bot/trader/Trader.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace bot::trader {
1010
namespace {
1111
std::random_device seed_gen;
1212
// std::default_random_engine engine(seed_gen());
13-
std::default_random_engine engine(64);
13+
std::default_random_engine engine{64};
1414
std::uniform_int_distribution<> action_dist(0, 2);
1515
std::uniform_real_distribution<> amount_dist(0.0, 1.0);
1616

@@ -50,7 +50,7 @@ constexpr Money_data_t default_price_value = 100000;
5050
} // namespace
5151

5252
void Random::Trade(Trader &trader, StockMarketRef market) {
53-
std::uniform_int_distribution<> stock_select(0, market->count() - 1);
53+
std::uniform_int_distribution<StockId> stock_select(0, market->count() - 1);
5454
StockId stock = stock_select(engine);
5555
auto action = action_dist(engine);
5656
// auto amount = 0.05 / (amount_dist(engine) + 0.2);
@@ -77,12 +77,15 @@ void Random::Trade(Trader &trader, StockMarketRef market) {
7777
// std::cout << "ignore \n" << std::endl;
7878
break;
7979
}
80+
default: {
81+
// unreachable
82+
}
8083
}
8184
}
8285

8386
void Fundamental::Trade(Trader &trader, StockMarketRef market) {
84-
std::discrete_distribution stock_select(market->get_value_dondake_hanareteru().begin(),
85-
market->get_value_dondake_hanareteru().end());
87+
std::discrete_distribution<StockId> stock_select(market->get_value_dondake_hanareteru().begin(),
88+
market->get_value_dondake_hanareteru().end());
8689
StockId stock = stock_select(engine);
8790
auto board = market->get(stock);
8891

stock_emu_lib/money.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class Money {
3333
public:
3434
constexpr Money(Money_data_t value_) : value(value_) {}
3535

36-
constexpr Money() : value(0) {};
36+
constexpr Money() : value(0) {}
3737

3838
// moveする場合、全部受け渡し先に移動
3939
constexpr Money(Money&& other) : value(0) {
@@ -89,7 +89,7 @@ class Money {
8989
};
9090

9191
public:
92-
money_move_helper move(Price price) {
92+
constexpr money_move_helper move(Price price) {
9393
return {price, *this};
9494
}
9595
};

stock_emu_lib/trade/Trade.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
#include <cstdlib>
66
#include <stock_emu_lib/Stock.hpp>
77

8-
void Trader::sell(StockPrice price, StockCount amount, StockId id, StockMarketRef ref) {
9-
(*ref)[id]->LimitOrder_Sell(price, amount, *this);
8+
void Trader::sell(StockPrice price, StockCount amount, StockId stock_id, StockMarketRef ref) {
9+
(*ref)[stock_id]->LimitOrder_Sell(price, amount, *this);
1010
}
1111

12-
void Trader::buy(StockPrice price, StockCount amount, StockId id, StockMarketRef ref) {
13-
(*ref)[id]->LimitOrder_Buy(price, amount, *this);
12+
void Trader::buy(StockPrice price, StockCount amount, StockId stock_id, StockMarketRef ref) {
13+
(*ref)[stock_id]->LimitOrder_Buy(price, amount, *this);
1414
}
1515

1616
bool TradeBoard::LimitOrder_Sell(StockPrice price, StockCount count, Trader& trader) {
@@ -125,7 +125,7 @@ void TradeBoard::tick() noexcept {
125125
limit.update_PriceLimit(latest_tick.end);
126126
}
127127

128-
sell.limit_queue.destruct(id);
128+
sell.limit_queue.destruct();
129129
buy.limit_queue.destruct();
130130
if (auto l = getCurrentPrice().lower; l) {
131131
history.update_current_low(*l, *this);
@@ -145,7 +145,7 @@ void StockMarket::updatePricePerValue(const TradeBoard& ref) {
145145
std::abs(ref.getHistory().getCurrentPrice().latest.getValue() - ref.StockValue().getValue());
146146
}
147147

148-
void TradeBoard::sell_limit_destruct::run(std::deque<SellTradeRequest>& q, StockId id) {
148+
void TradeBoard::sell_limit_destruct::run(std::deque<SellTradeRequest>& q) {
149149
for (auto& i : q) {
150150
i.reject();
151151
}

stock_emu_lib/trade/Trade.hpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ struct BuyTradeRequest {
7575
Money money;
7676
BuyTradeRequest** refer = nullptr;
7777

78-
BuyTradeRequest(StockCount amount_, Trader& trader_, Money&& money)
79-
: amount(amount_), trader(trader_), money(std::move(money)) {}
78+
BuyTradeRequest(StockCount amount_, Trader& trader_, Money&& money_)
79+
: amount(amount_), trader(trader_), money(std::move(money_)) {}
8080

8181
void reject() {
8282
money.move(money.as_Price()).to(trader.money);
@@ -150,31 +150,31 @@ struct TradeBoard {
150150
}
151151
}
152152

153-
const auto& getBuyBoard() const {
153+
constexpr const auto& getBuyBoard() const {
154154
return buy;
155155
}
156156

157-
const auto& getSellBoard() const {
157+
constexpr const auto& getSellBoard() const {
158158
return sell;
159159
}
160160

161-
const auto& StockValue() const {
161+
constexpr const auto& StockValue() const {
162162
return stock_value;
163163
}
164164

165165
void updateStockValue(StockPrice price, StockMarketRef market);
166166

167167
void tick() noexcept;
168168

169-
const auto& getHistory() const noexcept {
169+
constexpr const auto& getHistory() const noexcept {
170170
return history;
171171
}
172172

173-
const auto& getPriceLimit() const noexcept {
173+
constexpr const auto& getPriceLimit() const noexcept {
174174
return limit;
175175
}
176176

177-
const auto& getCurrentPrice() const noexcept {
177+
constexpr const auto& getCurrentPrice() const noexcept {
178178
return history.getCurrentPrice();
179179
}
180180

@@ -199,7 +199,7 @@ struct TradeBoard {
199199
util::RingQueue<std::deque<Request_t>, 24, limit_destructor_t> limit_queue;
200200

201201
template<class... Args>
202-
void add(int expire, StockPrice price, Args&&... arg) {
202+
void add(size_t expire, StockPrice price, Args&&... arg) {
203203
limit_queue.get(expire).emplace_back(std::forward<Args>(arg)...);
204204
auto* elem = &limit_queue.get(expire).back();
205205

@@ -228,7 +228,7 @@ struct TradeBoard {
228228
};
229229

230230
struct sell_limit_destruct {
231-
static void run(std::deque<SellTradeRequest>&, StockId);
231+
static void run(std::deque<SellTradeRequest>&);
232232
};
233233

234234
TradeRequestBoard<BuyTradeRequest, buy_limit_destruct> buy;

stock_emu_lib/trade/TradeHistory.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ struct TradeBoard;
2929
*/
3030
class TradeBoardHistory {
3131
public:
32-
const auto& getCurrentPrice() const noexcept {
32+
constexpr const auto& getCurrentPrice() const noexcept {
3333
return CurrentStockPrice;
3434
}
3535

0 commit comments

Comments
 (0)