first commit

This commit is contained in:
Francois Klieber committed 2021-06-06 20:25:14 +02:00
commit aa7869eb33
386 files changed
+69375

No files matched your search

+67
View File
@@ -0,0 +1,67 @@
// Redux/vuex inspired reducer, reduces an event into a gekko state.
// NOTE: this is used by the backend as well as the frontend.
const skipInitialEvents = ['marketUpdate'];
const skipLatestEvents = ['marketStart', 'stratWarmupCompleted'];
const trackAllEvents = ['tradeCompleted', 'advice', 'roundtrip'];
const reduce = (state, event) => {
const type = event.type;
const payload = event.payload;
state = {
...state,
latestUpdate: new Date()
}
if(trackAllEvents.includes(type)) {
if(!state.events[type]) {
state = {
...state,
events: {
...state.events,
[type]: [ payload ]
}
}
} else {
state = {
...state,
events: {
...state.events,
[type]: [ ...state.events[type], payload ]
}
}
}
}
if(!state.events.initial[type] && !skipInitialEvents.includes(type)) {
state = {
...state,
events: {
...state.events,
initial: {
...state.events.initial,
[type]: payload
}
}
}
}
if(!skipLatestEvents.includes(type)) {
state = {
...state,
events: {
...state.events,
latest: {
...state.events.latest,
[type]: payload
}
}
}
}
return state;
}
// export default reduce;
module.exports = reduce;