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
Carets - Maria - ada-trader #38
Open
ghost
wants to merge
7
commits into
Ada-C8:master
Choose a base branch
from
unknown repository
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
7 commits
Select commit
Hold shift + click to select a range
eb3c03b
added views for user to see list of quotes in the quotes section
mariamcgrew 348d941
added tagName and className to the list view to fix styling
mariamcgrew edd6b07
tests passing for buy and sell functions in quote.js
mariamcgrew b4e8555
buy method and click event working for quote
mariamcgrew ecf884b
sell method and click event working for quote
mariamcgrew 288ec95
added underscore template for tradesList, added listTrades event in q…
mariamcgrew f784af4
order buy sell button not responding
mariamcgrew 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,21 @@ import 'foundation-sites/dist/foundation.css'; | |
import 'css/app.css'; | ||
|
||
import $ from 'jquery'; | ||
import _ from 'underscore'; | ||
|
||
import Simulator from 'models/simulator'; | ||
import QuoteList from 'collections/quote_list'; | ||
|
||
import Quote from './models/quote'; | ||
import QuoteList from './collections/quote_list'; | ||
|
||
import QuoteView from './views/quote_view'; | ||
import QuoteListView from './views/quote_list_view'; | ||
|
||
import Order from './models/order'; | ||
import OrderList from './collections/order_list'; | ||
|
||
import OrderView from './views/order_view'; | ||
import OrderListView from './views/order_list_view'; | ||
|
||
const quoteData = [ | ||
{ | ||
|
@@ -25,11 +37,30 @@ const quoteData = [ | |
}, | ||
]; | ||
|
||
|
||
$(document).ready(function() { | ||
const quotes = new QuoteList(quoteData); | ||
const orders = new OrderList(); | ||
const simulator = new Simulator({ | ||
quotes: quotes, | ||
}); | ||
|
||
const quoteListView = new QuoteListView({ | ||
model: quotes, | ||
template: _.template($('#quote-template').html()), | ||
tradesTemplate: _.template($('#trade-template').html()), | ||
el: 'main' | ||
}); | ||
|
||
const orderListView = new OrderListView({ | ||
model: orders, | ||
template: _.template($('#order-template').html()), | ||
el: 'main' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also note that both views represent the SAME element in the DOM, this means it's possible they could interfere with each other. Instead I would suggest making the |
||
}); | ||
|
||
quoteListView.render(); | ||
orderListView.render(); | ||
|
||
simulator.start(); | ||
|
||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import Backbone from 'backbone'; | ||
|
||
const Order = Backbone.Model.extend({ | ||
defaults: { | ||
symbol: 'UNDEF', | ||
targetPrice: 0.00 | ||
}, | ||
|
||
buyOrder(){ | ||
this.set('buy', true); | ||
}, | ||
sellOrder() { | ||
this.set('buy', false); | ||
}, | ||
}); | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import Backbone from 'backbone'; | ||
import _ from 'underscore'; | ||
import OrderView from '../views/order_view'; | ||
import Order from '../models/order'; | ||
|
||
const OrderListView = Backbone.View.extend({ | ||
initialize(params) { | ||
this.template = params.template; | ||
this.listenTo(this.model, 'update', this.render); | ||
}, | ||
render() { | ||
this.$('#orders').empty(); | ||
this.model.each((order) => { | ||
const orderView = new OrderView({ | ||
model: order, | ||
template: this.template, | ||
tagName: 'li', | ||
className: 'order' | ||
}); | ||
|
||
this.$('#orders').append(orderView.render().$el); | ||
}); | ||
return this; | ||
}, // end of render | ||
listOrders(orderView){ | ||
const compiledOrdersTemplate = orderView.template(orderView.model.toJSON()); | ||
this.$('#orders').prepend(compiledOrdersTemplate); | ||
} | ||
}); | ||
|
||
export default OrderListView; |
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 @@ | ||
import Backbone from 'backbone'; | ||
import Order from '../models/order'; | ||
|
||
const OrderView = Backbone.View.extend({ | ||
initialize(params) { | ||
this.template = params.template; | ||
this.orderTemplate = params.orderTemplate; | ||
this.listenTo(this.model, "update", this.render); | ||
}, | ||
render() { | ||
const compiledTemplate = this.template(this.model.toJSON()); | ||
this.$el.html(compiledTemplate); | ||
|
||
return this; | ||
}, //end of render | ||
events: { | ||
'click button.alert': 'addOrderBuy', | ||
'click button.success': 'addOrderSell', | ||
}, | ||
addOrderSell(event) { | ||
event.preventDefault(); | ||
const orderData = {}; | ||
['symbol', 'price-target'].forEach( (field) => { | ||
const val = this.$(`#add-order-form input[name=${field}]`).val(); | ||
if (val != '') { | ||
orderData[field] = val; | ||
} | ||
}); | ||
const newOrder = new Order(orderData); | ||
this.model.add(newOrder); | ||
this.trigger('listOrders', this); | ||
}, | ||
}); // end of OrderView | ||
|
||
export default OrderView; |
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 @@ | ||
import Backbone from 'backbone'; | ||
import _ from 'underscore'; | ||
import QuoteView from '../views/quote_view'; | ||
import Quote from '../models/quote'; | ||
|
||
const QuoteListView = Backbone.View.extend({ | ||
initialize(params) { | ||
this.template = params.template; | ||
this.tradesTemplate = params.tradesTemplate; | ||
this.listenTo(this.model, 'update', this.render); | ||
}, | ||
render() { | ||
this.$('#quotes').empty(); | ||
this.model.each((quote) => { | ||
const quoteView = new QuoteView({ | ||
model: quote, | ||
template: this.template, | ||
tradesTemplate: this.tradesTemplate, | ||
tagName: 'li', | ||
className: 'quote' | ||
}); | ||
|
||
this.listenTo(quoteView, 'listTrades', this.listTrades) | ||
this.$('#quotes').append(quoteView.render().$el); | ||
}); | ||
return this; | ||
}, // end of render | ||
listTrades(quoteView){ | ||
const compiledTradesTemplate = quoteView.tradesTemplate(quoteView.model.toJSON()); | ||
this.$('#trades').prepend(compiledTradesTemplate); | ||
} | ||
|
||
}); //end of QuoteListView | ||
|
||
export default QuoteListView |
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,30 @@ | ||
import Backbone from 'backbone'; | ||
import Quote from '../models/quote'; | ||
|
||
const QuoteView = Backbone.View.extend({ | ||
initialize(params) { | ||
this.template = params.template; | ||
this.tradesTemplate = params.tradesTemplate; | ||
this.listenTo(this.model, "change", this.render); | ||
}, | ||
render() { | ||
const compiledTemplate = this.template(this.model.toJSON()); | ||
this.$el.html(compiledTemplate); | ||
|
||
return this; | ||
}, //end of render | ||
events: { | ||
'click button.alert': 'buyStock', | ||
'click button.success': 'sellStock', | ||
}, | ||
buyStock: function(e) { | ||
this.model.buy(); | ||
this.trigger('listTrades', this); | ||
}, | ||
sellStock: function(e) { | ||
this.model.sell(); | ||
this.trigger('listTrades', this); | ||
} | ||
}); // end of QuoteView | ||
|
||
export default QuoteView; |
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.
I would suggest passing
quotes
in to theOrderListView
and then the view can listen for changes in quotes and check to see if it's time to execute an order.