forked from AdaGold/ada-trader
-
Notifications
You must be signed in to change notification settings - Fork 43
Ada-Trader-Mariana-Pipes #44
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
Open
lmarianarp19
wants to merge
6
commits into
Ada-C8:master
Choose a base branch
from
lmarianarp19: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
6 commits
Select commit
Hold shift + click to select a range
e7c1eb5
Show the quotes
lmarianarp19 9d9458b
show trade history
lmarianarp19 948771b
add dropdown menu
lmarianarp19 a1bd044
refactor wave 2
lmarianarp19 662621a
Can add a new order to the list
lmarianarp19 3653d65
sekll button quote working
lmarianarp19 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,12 @@ | ||
| import Backbone from 'backbone'; | ||
|
|
||
| const Order = Backbone.Model.extend({ | ||
| // defaults: { | ||
| // symbol: 'UNDEF', | ||
| // targetPrice: 0.00, | ||
| // buy: true, | ||
| // } | ||
|
|
||
| }); | ||
|
|
||
| export default Order; |
This file contains hidden or 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 hidden or 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,11 @@ | ||
| import Backbone from 'backbone'; | ||
|
|
||
| const OpenLitsView = Backbone.View.extend({ | ||
| initialize(params){ | ||
| this.template = params.template; | ||
| // TODO to change click, I want to add the element to the list after they click buy or sellQuote | ||
| }, | ||
| }); | ||
|
|
||
|
|
||
| export default OpenListView; |
This file contains hidden or 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,64 @@ | ||
| import Backbone from 'backbone'; | ||
| import Order from '../models/order'; | ||
| import OrderView from '../views/order_view'; | ||
| import OrderList from '../collections/order_list'; | ||
| import _ from 'underscore'; | ||
|
|
||
| const OrderListView = Backbone.View.extend({ | ||
| initialize(params){ | ||
| this.template = params.template; | ||
| this.listenTo(this.model, 'update', this.renderOrders) | ||
| }, | ||
| events: { | ||
| 'click .btn-buy, .btn-sell': 'addOrder', | ||
| }, | ||
| renderOrders(){ | ||
|
|
||
| this.model.each((order) => { | ||
|
|
||
| const orderView = new OrderView({ | ||
| model: order, | ||
| template: this.template, | ||
| tagName: 'li', | ||
| className: 'order', | ||
| // bus: this.bus, | ||
| }); | ||
| this.$('#orders').append(orderView.renderOrder().$el); | ||
| }); | ||
| return this; | ||
|
|
||
| }, | ||
|
|
||
| addOrder(event) { | ||
| event.preventDefault(); | ||
| const formData = this.getFormData(); | ||
| formData['buy'] = event.target.classList[0] === ('btn-buy') ? true : false; | ||
| const newOrder = new Order(formData); | ||
| // const viewOrder = new OrderView({ | ||
| // model: newOrder, | ||
| // template: this.$('#order-template'), | ||
| // el: 'li' | ||
| // // _.template(this.$('#order-template')), | ||
| // }); | ||
|
|
||
| this.model.add(newOrder) | ||
| // console.log(viewOrder); | ||
| }, | ||
|
|
||
| getFormData() { | ||
| const orderData = {}; | ||
| // ['symbol', 'price-target'].forEach((field) => { | ||
| const val = Number(this.$('#order-form input[name="targetPrice"]').val()); | ||
|
|
||
| // this.$(`#add-task-form input[name=${field}]`).val(); | ||
| // if (val !== '') { | ||
| orderData['targetPrice'] = val; | ||
| // } | ||
| // }); | ||
| orderData['symbol'] = this.$('select[name=symbol]').val(); | ||
| return orderData; | ||
| }, | ||
|
|
||
| }); | ||
|
|
||
| export default OrderListView; | ||
This file contains hidden or 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,16 @@ | ||
| import Backbone from 'backbone'; | ||
|
|
||
| const OrderView = Backbone.View.extend({ | ||
| initialize(params){ | ||
| this.template = params.template; | ||
| // TODO to change click, I want to add the element to the list after they click buy or sellQuote | ||
| }, | ||
| renderOrder(){ | ||
| const compiledTemplate = this.template(this.model.toJSON()); | ||
| this.$el.html(compiledTemplate); | ||
| return this | ||
| }, | ||
| }); | ||
|
|
||
|
|
||
| export default OrderView; |
This file contains hidden or 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,39 @@ | ||
| import Backbone from 'backbone'; | ||
| import Quote from '../models/quote'; | ||
| import QuoteList from '../collections/quote_list'; | ||
| import _ from 'underscore'; | ||
|
|
||
| const QuoteListView = Backbone.View.extend({ | ||
| initialize(params){ | ||
| this.template = params.template; | ||
| this.listenTo(this.model, 'update', this.render) | ||
| // TODO to change click, I want to add the element to the list after they click buy or sellQuote | ||
| }, | ||
| events: { | ||
| 'click .btn-buy': 'addTraderBuy', | ||
| 'click .btn-sell': 'addTraderSell' | ||
| }, | ||
| addTraderBuy(){ | ||
| console.log("inside the addTraderBuy"); | ||
| }, | ||
| addTraderSell(){ | ||
| console.log('inside the addTraderSell'); | ||
| }, | ||
| // copy | ||
| // addTraderBuy(event){ | ||
| // event.preventDefault(); | ||
| // // TODO get form data | ||
| // const formData = this.getFormData(); | ||
| // const newTask = new Task(formData); | ||
| // | ||
| // this.model.add(newTask); | ||
| // | ||
| // endcopy | ||
| render(){ | ||
| const compiledTemplate = this.template(this.model.toJSON()); | ||
| this.$el.html(compiledTemplate); | ||
| return this | ||
| } | ||
| }); | ||
|
|
||
| export default QuoteListView; |
This file contains hidden or 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 Quote from '../models/quote'; | ||
|
|
||
| const QuoteView = Backbone.View.extend({ | ||
| initialize(params){ | ||
| this.bus = params.bus; | ||
| this.template = params.template; | ||
| this.listenTo(this.model, 'change', this.render) | ||
| }, | ||
| events: { | ||
| 'click .btn-buy': 'buyQuote', | ||
| 'click .btn-sell': 'sellQuote', | ||
| }, | ||
| buyQuote(){ | ||
| this.model.buy(), | ||
| this.bus.trigger('buyQuote', this.model) | ||
| console.log("inside buyQuote"); | ||
| }, | ||
| sellQuote(){ | ||
| this.model.sell(), | ||
| this.bus.trigger('sellQuote', this.model) | ||
| }, | ||
| render(){ | ||
| const compiledTemplate = this.template(this.model.toJSON()); | ||
| this.$el.html(compiledTemplate); | ||
| return this | ||
| } | ||
| }); | ||
|
|
||
|
|
||
| export default QuoteView; |
This file contains hidden or 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,73 @@ | ||
| import Backbone from 'backbone'; | ||
| import TraderView from '../views/trader_view'; | ||
|
|
||
| import _ from 'underscore'; | ||
|
|
||
| const TraderListView = Backbone.View.extend({ | ||
| initialize(params){ | ||
| this.bus = params.bus; | ||
| this.template = params.template; | ||
| // Liste the but, sell event | ||
| this.listenTo(params.bus, 'buyQuote', this.addTraderBuy); | ||
| this.listenTo(params.bus, 'sellQuote', this.addTraderSell); | ||
| // this.listenTo(this.model, 'buy', this.addTraderBuy); | ||
| // this.listenTo(this.model, 'sell', this.addTraderSell); | ||
| // TODO to change click, I want to add the element to the list after they click buy or sellQuote | ||
| }, | ||
| addTraderBuy(quote){ | ||
| const trade = { | ||
| symbol:quote.get('symbol'), | ||
| price: quote.get('price'), | ||
| buy: true | ||
|
|
||
| } | ||
| const traderView = new TraderView({ | ||
| model: trade, | ||
| template: this.template, | ||
| bus: this.bus, | ||
| }); | ||
|
|
||
| this.$('.trades').prepend(traderView.render().$el); | ||
| console.log("inside the addTraderBuy"); | ||
| }, | ||
|
|
||
| addTraderSell(quote){ | ||
|
|
||
|
|
||
| const tradesell = { | ||
| symbol:quote.get('symbol'), | ||
| price: quote.get('price'), | ||
| buy: false | ||
|
|
||
| }; | ||
|
|
||
| const traderView = new TraderView({ | ||
| model: tradesell, | ||
| template: this.template, | ||
| bus: this.bus, | ||
| }); | ||
|
|
||
| this.$('.trades').prepend(traderView.render().$el); | ||
| console.log("inside the addSell"); | ||
|
|
||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| // const traderView = new TraderView({ | ||
| // model: trade, | ||
| // template: this.template, | ||
| // }); | ||
| // | ||
| // this.$('.trades').prepend(traderView.render().$el); | ||
| // }, | ||
| }); | ||
|
|
||
| export default TraderListView; |
This file contains hidden or 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,18 @@ | ||
| import Backbone from 'backbone'; | ||
| import Quote from '../models/quote'; | ||
| import QuoteList from '../collections/quote_list'; | ||
| import _ from 'underscore'; | ||
|
|
||
| const TraderView = Backbone.View.extend({ | ||
| initialize(params){ | ||
| this.template = params.template; | ||
| this.bus = params.bus; | ||
| }, | ||
| render(){ | ||
| const compiledTemplate = this.template(this.model); | ||
| this.$el.html(compiledTemplate); | ||
| return this | ||
| } | ||
| }); | ||
|
|
||
| export default TraderView; |
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.
At this point you need to connect the new
Orderwith its correspondingQuote. Probably the cleanest way to do this would be to add a function toQuoteListto get aQuoteby symbol, and then pass theQuoteListinto theOrderListViewat instantiation.This will allow you to validate the
Orderbased on the current price, and to listen for price changes on theQuoteso theOrdercan execute automatically when the price is right.