Skip to content
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

Gale Harrington - Carets #37

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Order being executed and displayed in trade history for buy
galestorm committed Dec 15, 2017
commit cebdbeb993c7b1050ffe3416e489ff3d4c528a1e
9 changes: 9 additions & 0 deletions src/models/order.js
Original file line number Diff line number Diff line change
@@ -13,6 +13,15 @@ const Order = Backbone.Model.extend({
} else {
return false;
}
},
executeOrder: function(changeInfo) {
if (this.get('symbol') === changeInfo.symbol && this.get('buy') === true && changeInfo.currentPrice <= this.get('targetPrice')) {
this.trigger('buy', changeInfo);
this.destroy();
}
if (this.get('symbol') === changeInfo.symbol && this.get('buy') === false && changeInfo.currentPrice >= this.get('targetPrice')) {
//this.bus.trigger('sell', changeInfo);
}
}
});

4 changes: 3 additions & 1 deletion src/views/order_list_view.js
Original file line number Diff line number Diff line change
@@ -17,9 +17,10 @@ const OrderListView = Backbone.View.extend({
template: this.template,
tagName: 'li',
className: 'order',
bus: this.bus
});
this.$('#orders').append(orderView.render().$el);
orderView.listenTo(this.bus, 'priceChange', orderView.executeOrder);
// orderView.listenTo(this.bus, 'priceChange', orderView.executeOrder);
});
return this;
},
@@ -37,6 +38,7 @@ const OrderListView = Backbone.View.extend({
const newOrder = new Order(orderData);
if (newOrder.isValid()) {
this.model.add(newOrder);
newOrder.listenTo(this.bus, 'priceChange', newOrder.executeOrder);
this.$('.order-entry-form [name=price-target]').val("");
this.$('.form-errors').empty();
} else {
10 changes: 4 additions & 6 deletions src/views/order_view.js
Original file line number Diff line number Diff line change
@@ -3,7 +3,9 @@ import Backbone from 'backbone';
const OrderView = Backbone.View.extend({
initialize(params) {
this.template = params.template;
this.bus = params.bus;
this.listenTo(this.model, 'change', this.render);
this.listenTo(this.model, 'buy', this.triggerBuy);
},
render() {
const compiledTemplate = this.template(this.model.toJSON());
@@ -16,12 +18,8 @@ const OrderView = Backbone.View.extend({
deleteOrder: function() {
this.model.destroy();
},
executeOrder: function(changeInfo) {
if (this.model.get('symbol') === changeInfo.symbol && this.model.get('buy') === true && changeInfo.currentPrice <= this.model.get('targetPrice')) {
console.log('I should buy');
}


triggerBuy: function(changeInfo) {
this.bus.trigger('buyOrder', changeInfo)
}
})

8 changes: 8 additions & 0 deletions src/views/quote_view.js
Original file line number Diff line number Diff line change
@@ -7,6 +7,8 @@ const QuoteView = Backbone.View.extend({
this.bus = params.bus;
this.listenTo(this.model, 'change', this.render);
this.listenTo(this.model, 'change', this.alertPriceChange);
this.listenTo(this.bus, 'buyOrder', this.buyOrder);
this.listenTo(this.bus, 'sell', this.sellQuote);
},
render() {
const compiledTemplate = this.template(this.model.toJSON());
@@ -28,6 +30,12 @@ const QuoteView = Backbone.View.extend({
this.trigger('sell', this);
this.model.sell();
},
buyOrder: function(changeInfo) {
if (this.model.get(`symbol`) === changeInfo.symbol) {
this.trigger('buy', this);
this.model.buy();
}
}
})

export default QuoteView;