FIX 4.0 Demo 1.0
Loading...
Searching...
No Matches
styles.hpp
Go to the documentation of this file.
1
6#pragma once
7
8#include <ftxui/dom/elements.hpp>
9
10namespace fix40::client::tui {
11
12using namespace ftxui;
13
14// 颜色定义
15inline Color colorPrimary() { return Color::Blue; }
16inline Color colorSuccess() { return Color::Green; }
17inline Color colorDanger() { return Color::Red; }
18inline Color colorWarning() { return Color::Yellow; }
19inline Color colorMuted() { return Color::GrayDark; }
20
21// 盈亏颜色
22inline Color profitColor(double value) {
23 if (value > 0) return Color::Green;
24 if (value < 0) return Color::Red;
25 return Color::White;
26}
27
28// 买卖颜色
29inline Color sideColor(const std::string& side) {
30 if (side == "BUY" || side == "1") return Color::Red; // 买入红色
31 if (side == "SELL" || side == "2") return Color::Green; // 卖出绿色
32 return Color::White;
33}
34
35// 边框样式
36inline Element styledBorder(Element inner, const std::string& title) {
37 return window(text(title) | bold, inner);
38}
39
40// 格式化数字
41inline std::string formatMoney(double value) {
42 char buf[32];
43 snprintf(buf, sizeof(buf), "%.2f", value);
44 return buf;
45}
46
47inline std::string formatPercent(double value) {
48 char buf[32];
49 snprintf(buf, sizeof(buf), "%.2f%%", value * 100);
50 return buf;
51}
52
53inline std::string formatQty(int64_t qty) {
54 return std::to_string(qty);
55}
56
57} // namespace fix40::client::tui
Definition app.cpp:15
Color sideColor(const std::string &side)
Definition styles.hpp:29
std::string formatPercent(double value)
Definition styles.hpp:47
Color colorSuccess()
Definition styles.hpp:16
std::string formatQty(int64_t qty)
Definition styles.hpp:53
Element styledBorder(Element inner, const std::string &title)
Definition styles.hpp:36
Color colorDanger()
Definition styles.hpp:17
Color colorPrimary()
Definition styles.hpp:15
std::string formatMoney(double value)
Definition styles.hpp:41
Color colorMuted()
Definition styles.hpp:19
Color colorWarning()
Definition styles.hpp:18
Color profitColor(double value)
Definition styles.hpp:22