Skip to content
This repository has been archived by the owner on Feb 16, 2020. It is now read-only.

[WIP] 0.6 new gekko events #1850

Merged
merged 58 commits into from
May 28, 2018
Merged

[WIP] 0.6 new gekko events #1850

merged 58 commits into from
May 28, 2018

Conversation

askmike
Copy link
Owner

@askmike askmike commented Feb 3, 2018

fixes #1814 <- read the context and problem this solves here.

Currently not finished: if you run this now the UI will not be able to track what is happening in live gekkos.

TODO:

  • add all events that the (new) UI relies on as native events.
    • candle event
    • market update event
    • stratWarmupCompleted event
    • stratUpdate event (needs to include indicator results)
      • native indicators
      • Tulip indicators
      • TA-lib indicators
    • advice event
    • market start event
    • paper trader
      • tradeInitiated event
      • tradeCompleted event
      • tradeAborted event
    • real trader
      • tradeInitiated event
      • tradeCompleted event
      • tradeAborted event
    • report event
    • roundtrip event
    • roundtripUpdate event
    • portfolioChange event
    • portfolioValueChange event
  • fully remove direct child process communication (cp.js).
  • add simple plugin that upstreams all events via child-process events.
  • add other simple plugins with log some trade data to csv for example.
  • integrate events with new gekko manager (for the ui server)

E2E flows:

  • working CLI backtester
  • working UI backtester
  • working CLI live trader
  • working UI live trader
  • working CLI importer
  • working UI importer


Note that all events from Gekko come from a plugin (with the exception of the `candle` event, which comes from the market), and no plugin is required for Gekko to run, this means it might be possible that some events are never broadcasted since their originating plugin is not active. If a plugin wants to listen to an event that will never be broadcasted (because of a lack of another plugin) this will be warned in the console like so:

(WARN): Paper Trader wanted to listen to the tradingAdvisor, however the tradingAdvisor is disabled.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the extra spaces here intended?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lol. Somehow I didn't think of the possibility that you wanted it to be a codeblock on purpose...

web/server.js Outdated
client => client.send(JSON.stringify(data))
client => {
try {
client.send(JSON.stringify(data);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm )

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's a fix for #1582, not the best please to put it I admit ;)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah you mean I forgot the ), good point, adding it back now!

@askmike
Copy link
Owner Author

askmike commented Feb 12, 2018

Current possible issue:

AFAIK events behave as a FIFO stack which means that the following situation poses a problem:

If there is a paper trader and a strat runner both subscribed to new candles to register current market start and for some reason (due to whichever order plugins are loaded) the strat runner is first to receive the new candle. In that case the plugins will execture in this order:

  1. strat runner received new candle.
  2. strat runner triggers advice based on new candle data (in case of no async indicators).
  3. paper trader receives the advice, while still relying on outdated market data (since the new candle is not received yet).
  4. paper trader receives new candle.

Current implemented workaround is that the advice payload is extended with a candle on which the advice is based. This works now since the current events are limited, but this solution does not scale, especially with the introduction of new events like portfolioValueChange.

The only solutions I see:

  • [ugly solution] inject event subscription in a specific place in the plugin pipeline, this breaks with circular event flows.
  • [better solution] introduce a fake "nextTick helper" that forces the "advice" event (in the example above) to run AFTER the candle event has finished propagating. Using a fake one means we can manually do it fully sync (in the same nodejs event tick) in backtest situations, tracking this manually.

Anyone has any other ideas? @werkkrew @cmroche @AidasK?

I won't work on this yet until I finished new event design (and basic implementation)

@cmroche
Copy link
Contributor

cmroche commented Feb 12, 2018

@askmike A bit to go through here, I'll take a look in the next day or so. :)

- [portfolioChange](#portfolioChange-event): Every time the content of the portfolio has changed.
- [portfolioTick](#portfolioTick-event): Every time the total worth of the portfolio has changed.
- [report](#report-event): Every time the profit report has updated.
- [roundtrip](#roundtrip-event): Every time a new roundtrip has been completed.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To consider for the future, events for adding/filling/canceling orders

@askmike askmike changed the title [WIP] Sync gekko events to ws events [WIP] 0.6 new gekko events Mar 26, 2018
@askmike askmike mentioned this pull request Apr 1, 2018
this.defferedEvents = [];
}

util.inherits(GekkoEventEmitter, NativeEventEmitter);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use ES6 extends here, it's reference in the official doc and available since node 4.9.1 https://node.green/

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point, will do!

@lutangar
Copy link
Contributor

Hey, don't want to bother, but I'd like know what's your take on modern Js synthax in general before commenting further. For example I saw a few usage of arrow functions here an there but it doesn't seem to be used everywhere it could.
So what's your minimum nodejs version target for the codebase in general?
Would you be interested in a review in that direction?

Cheers, keep up the good work :)

@askmike askmike mentioned this pull request May 14, 2018
@askmike
Copy link
Owner Author

askmike commented May 14, 2018

@lutangar the codebase is quite big but I I want to use modern ES6 for all new code hitting the repo (including classes where it makes sense - especially for syntactical sugar).

I am aiming to support the current LTS release which is node v8.11.1.

@lutangar
Copy link
Contributor

Alright, I'll try to make a review in that way then.

@askmike
Copy link
Owner Author

askmike commented May 14, 2018 via email

* Update performanceAnalyzer.js

* Update logger.js

* Update logger.js

* Update performanceAnalyzer.js
@askmike askmike changed the base branch from develop to pre-v0.6 May 28, 2018 16:04
@askmike askmike merged commit ea6df42 into pre-v0.6 May 28, 2018
@askmike askmike mentioned this pull request May 28, 2018
24 tasks
@askmike
Copy link
Owner Author

askmike commented May 28, 2018

See #2216 for follow up! Will clean up last things in there.

@askmike askmike deleted the feature/sync-gekko-events branch July 5, 2018 16:14
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants