forked from AdaGold/ada-trader
-
Notifications
You must be signed in to change notification settings - Fork 43
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
Bianca Fernandez | Pipes | Ada Trader #24
Open
biciclista22
wants to merge
8
commits into
Ada-C8:master
Choose a base branch
from
biciclista22:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ebc8ec1
custom function method-- buy and sell
biciclista22 7d7efcb
Create quote view and start to flesh out
biciclista22 03e981c
event handling logic
biciclista22 ac7ab04
Fix reference errors in app.js and added notes to get wave 1 working
biciclista22 19d9555
complete trade history view and passing in data - wave 2
biciclista22 a2667b6
Begin Wave 3 and refactoring tradehistoryview view function
biciclista22 233e55f
Working cancel button and now can create a sell order
biciclista22 14b01fd
Buggy but working code for open orders wave 3
biciclista22 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import Backbone from 'backbone'; | ||
import Order from '../models/order'; | ||
|
||
const OrderList = Backbone.Collection.extend({ | ||
model: Order, | ||
}); | ||
|
||
export default OrderList; |
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,13 @@ | ||
import Backbone from 'backbone'; | ||
|
||
|
||
const Order = Backbone.Model.extend({ | ||
defaults: { | ||
symbol: 'UNDEF', | ||
targetPrice: 0.00, | ||
buy: true, | ||
}, | ||
|
||
}); | ||
|
||
export default Order; |
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,52 @@ | ||
import Backbone from 'backbone'; | ||
import Order from '../models/order'; | ||
import OpenOrderView from './open_order_view'; | ||
import Quote from '../models/quote'; | ||
// import QuoteView from '../views/quote_view'; | ||
import QuoteList from '../collections/quote_list'; | ||
import $ from 'jquery'; | ||
|
||
const OpenOrderListView = Backbone.View.extend({ | ||
initialize(params) { // params is a hash -- only a hash because we passed it in as such | ||
this.template = params.template; | ||
this.model = params.model; | ||
|
||
this.listenTo(this.model, 'update', this.render); | ||
// this.listenTo(this.quotes, 'change', this.checkOrder); | ||
}, | ||
// checkOrder(event) { | ||
// if (this.model.length > 0) { | ||
// console.log(this.quotes); | ||
// console.log(this.model.price); | ||
// } | ||
|
||
// TODO way to check to see if current quote symbol is the same and if so, does the price logic match | ||
// if yes, then call completeOrder method | ||
// }, | ||
// completeOrder(event) { | ||
// | ||
// }, | ||
// events: { | ||
// | ||
// }, | ||
render() { | ||
console.log('you are in the open order list view'); | ||
this.$('#orders').empty(); | ||
console.log('in the render in open order list view'); | ||
console.log(this.model); | ||
|
||
this.model.each((order) => { | ||
const openOrderView = new OpenOrderView({ | ||
model: order, | ||
template: this.template, | ||
tagName: 'li', | ||
className: 'orders', | ||
}); | ||
|
||
this.$('#orders').append(openOrderView.render().$el); | ||
}); | ||
return this; | ||
} | ||
}); | ||
|
||
export default OpenOrderListView; |
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,51 @@ | ||
import Backbone from 'backbone'; | ||
import Quote from '../models/quote'; | ||
import Order from '../models/order'; | ||
import OrderList from '../collections/order_list'; | ||
import $ from 'jquery'; | ||
|
||
const OpenOrderView = Backbone.View.extend({ | ||
initialize(params) { | ||
this.template = params.template; | ||
// this.quotes = params.quotes; | ||
this.model = params.model; | ||
this.listenTo(this.model, 'change', this.render); | ||
this.listenTo(this.model.get('quote'), 'change', this.completeOrder); | ||
|
||
}, | ||
completeOrder() { | ||
console.log('the complete order method is being called'); | ||
let quote = this.model.get('quote'); | ||
|
||
if (this.model.get('buy')) { | ||
if (this.model.get('targetPrice') >= quote.get('price')) { | ||
quote.buy(); | ||
this.model.destroy(); | ||
this.remove(); | ||
} | ||
} else { | ||
if (this.model.get('targetPrice') <= quote.get('price')) { | ||
quote.sell(); | ||
this.model.destroy(); | ||
this.remove(); | ||
} | ||
} | ||
}, | ||
render() { | ||
const compiledTemplate = this.template(this.model.toJSON()); | ||
|
||
this.$el.html(compiledTemplate); | ||
|
||
return this; | ||
}, | ||
events: { | ||
'click button.btn-cancel': 'cancel', | ||
}, | ||
cancel(event) { | ||
if (confirm("Are you sure?") === true){ | ||
this.model.destroy(); | ||
} | ||
}, | ||
}); | ||
|
||
export default OpenOrderView; |
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,62 @@ | ||
import Backbone from 'backbone'; | ||
import Quote from '../models/quote'; | ||
import Order from '../models/order'; | ||
import OrderList from '../collections/order_list'; | ||
import $ from 'jquery'; | ||
|
||
const OrderFormView = Backbone.View.extend({ | ||
initialize(params) { | ||
this.orderList = params.orderList; | ||
this.quoteList = params.quoteList; | ||
console.log(params); | ||
}, | ||
render() { | ||
console.log('you are in the order form view render'); | ||
// console.log(this.quotelist) | ||
|
||
this.quoteList.each((quote)=> { | ||
console.log(quote.get('symbol')); | ||
this.$('#select').append($(`<option> ${quote.get('symbol')}</option>`)); | ||
}); | ||
return this; | ||
}, | ||
events: { | ||
'click button.btn-buy': 'buy', | ||
'click button.btn-sell': 'sell', | ||
}, | ||
buy(event) { | ||
console.log(event); | ||
event.isBuy = true; | ||
this.addNewOrder(event); | ||
}, | ||
sell(event) { | ||
console.log(event); | ||
event.isBuy = false; | ||
this.addNewOrder(event); | ||
|
||
}, | ||
addNewOrder(event) { | ||
console.log('in the add new order'); | ||
event.preventDefault(); | ||
const orderData = {}; | ||
orderData['symbol'] = $('select[name=symbol]').val(); | ||
orderData['targetPrice'] = parseFloat($('input[name=price-target]').val()); | ||
orderData['quote'] = this.quoteList.findWhere({symbol: orderData['symbol']}); | ||
|
||
orderData['buy'] = event.isBuy; | ||
|
||
console.log(orderData); | ||
|
||
const newOrder = new Order(orderData); | ||
|
||
// if (newOrder.isValid()) { | ||
this.orderList.push(newOrder); | ||
console.log(this.orderList); | ||
// } | ||
|
||
this.$('select[name=symbol]').val(''); | ||
this.$('input[name=price-target]').val(''); | ||
}, | ||
}); | ||
|
||
export default OrderFormView; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We also need to call
this.remove()
here, as we do incompleteOrder()
.What's currently happening is that we destroy the
Order
model, which triggersupdate
on theOrderList
collection it was in, and that results inOpenOrderListView
calling itsrender()
function, which creates newOpenOrderView
instances for each order remaining in the collection. However, it does not get rid of the old view instances.As a result, when we cancel an order it is no longer listed in the open orders list but the view does stick around in memory -- and it's still listening to the
Quote
model for any updates. Thus, the cancelled order could still execute after it is no longer displayed. You can repro this by creating an order and clicking cancel immediately, then waiting until the relevant quote's price shifts enough that the cancelled order would have executed. You can see in the trade history that in fact the quote does get executed even after being cancelled.