This repository has been archived by the owner on Feb 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
6,526 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Redux inspired reducer, reduces an event into a gekko state. | ||
// NOTE: this does mutate. | ||
// NOTE2: this is used by the backend as well as the frontend. | ||
|
||
const moment = require('moment'); | ||
|
||
const skipInitialEvents = ['marketUpdate']; | ||
const skipLatestEvents = ['marketStart']; | ||
const trackAllEvents = ['tradeCompleted', 'advice', 'roundtrip']; | ||
|
||
const reduce = (state, event) => { | ||
const type = event.type; | ||
const payload = event.payload; | ||
|
||
state.latestUpdate = moment(); | ||
|
||
if(trackAllEvents.includes(type)) { | ||
if(!state.events[type]) | ||
state.events[type] = []; | ||
|
||
state.events[type].push(payload); | ||
} | ||
|
||
if(!state.events.initial[type] && !skipInitialEvents.includes(type)) { | ||
state.events.initial[type] = payload; | ||
} | ||
|
||
if(!skipLatestEvents.includes(type)) { | ||
state.events.latest[type] = payload; | ||
} | ||
|
||
return state; | ||
} | ||
|
||
module.exports = reduce; |
Oops, something went wrong.