Slick Trader
0.11.0
Multi-broker algorithmic trading engine with plugin strategies and a live web dashboard
Loading...
Searching...
No Matches
workspace_store.hpp
Go to the documentation of this file.
1
#pragma once
2
3
#include <nlohmann/json.hpp>
4
#include <string>
5
#include <string_view>
6
7
namespace
slick::trader
{
8
9
// The dashboard's workspaces: each a named set of tool windows, where each sat and what it showed,
10
// kept in one JSON file as {"last":<name>,"workspaces":{<name>:{"windows":[...]}}}. "Default" is
11
// always there and can't be removed. `last` is the one the main window opens as it starts.
12
// Single-threaded: the WebServer's event loop owns it.
13
class
WorkspaceStore
{
14
public
:
15
static
constexpr
std::string_view
DEFAULT
=
"Default"
;
16
17
// 200, or the HTTP status a change is refused with and why.
18
struct
Result
{
19
int
status
{200};
20
std::string
error
;
21
bool
ok
()
const
{
return
status
== 200; }
22
};
23
24
// Reads `path`, where every change is written. A file missing, or unreadable (with a warning),
25
// leaves Default alone. An empty path keeps the workspaces in memory only.
26
void
load
(std::string path);
27
28
const
nlohmann::json&
doc
()
const
{
return
doc_; }
29
30
// Keeps `windows` as workspace `name`, which becomes the last used.
31
Result
save
(std::string_view name,
const
nlohmann::json& windows);
32
Result
remove
(std::string_view name);
33
// Marks `name` the last used.
34
Result
use
(std::string_view name);
35
36
private
:
37
// Writes doc_ to path_ by a temp file renamed over it. On failure doc_ goes back to `before`.
38
Result commit(nlohmann::json before);
39
40
std::string path_;
41
nlohmann::json doc_;
42
};
43
44
}
// namespace slick::trader
slick::trader::WorkspaceStore
Definition
workspace_store.hpp:13
slick::trader::WorkspaceStore::doc
const nlohmann::json & doc() const
Definition
workspace_store.hpp:28
slick::trader::WorkspaceStore::DEFAULT
static constexpr std::string_view DEFAULT
Definition
workspace_store.hpp:15
slick::trader::WorkspaceStore::save
Result save(std::string_view name, const nlohmann::json &windows)
Definition
workspace_store.cpp:144
slick::trader::WorkspaceStore::remove
Result remove(std::string_view name)
Definition
workspace_store.cpp:161
slick::trader::WorkspaceStore::use
Result use(std::string_view name)
Definition
workspace_store.cpp:178
slick::trader::WorkspaceStore::load
void load(std::string path)
Definition
workspace_store.cpp:106
slick::trader
Definition
coinbase_broker.hpp:11
slick::trader::WorkspaceStore::Result
Definition
workspace_store.hpp:18
slick::trader::WorkspaceStore::Result::error
std::string error
Definition
workspace_store.hpp:20
slick::trader::WorkspaceStore::Result::ok
bool ok() const
Definition
workspace_store.hpp:21
slick::trader::WorkspaceStore::Result::status
int status
Definition
workspace_store.hpp:19
slick-trader
web
workspace_store.hpp
Generated by
1.15.0