-
Notifications
You must be signed in to change notification settings - Fork 43
Pipes - Rebecca - Ada Trader #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
…ng and triggering events on bus through quote view and open order list view
Ada TraderWhat We're Looking For
|
|
|
||
| let openOrders = this.model.where({symbol: quote.get('symbol')}); | ||
| if (openOrders.length >= 1) { | ||
| openOrders.forEach((openOrder) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to wrap the call to forEach with a check that length >= 1. If the list has zero elements, then the loop body will execute zero times.
| this.listenTo(this.bus, 'current_quote_list', this.getQuoteList); | ||
| }, | ||
| getQuoteList(quoteList) { | ||
| this.quoteList = quoteList; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of using an event on the bus to get the quoteList, why not pass it in as an extra parameter when instantiating the OpenOrderListView? Building an event for it is overkill.
| }, | ||
| checkOpenOrders(quote) { | ||
|
|
||
| let openOrders = this.model.where({symbol: quote.get('symbol')}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently, the workflow for executing an open order looks like this:
- Quote price changes
quote_changeevent on the bus- Handled here by
OpenOrderListView.checkOpenOrders() - Find
OpenOrders matching the quote - For each one, determine if it needs to be sold
But we can simplify this! The key observation is that each OpenOrder already knows which Quote it's for - we need this information to validate the OpenOrder. Instead of working through the intermediaries of the bus and the OpenOrderListView, each OpenOrder could listen directly to its Quote for price changes. Then the workflow would look like:
- Quote price changes
- Event on the quote
- Handler in
OpenOrder - Determine if the order needs to be sold
This eliminates dependencies on the bus and the OpenOrderListView. It also simplifies the code, since we don't need to work with a list of OpenOrders. If there are multiple OpenOrders corresponding to the same quote each will have a separate handler registered, and each will run when the event occurs (steps 3-4).
Ada Trader
Congratulations! You're submitting your assignment!
Comprehension Questions