forked from AdaGold/ada-trader
-
Notifications
You must be signed in to change notification settings - Fork 43
Pipes - angela - ada-trader #26
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
awilson2017
wants to merge
17
commits into
Ada-C8:master
Choose a base branch
from
awilson2017: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
17 commits
Select commit
Hold shift + click to select a range
5a008be
instansiate QuoteListView in document.ready
awilson2017 1ada40c
add render to quoteListView in document.ready
awilson2017 29cbf73
made quote_list_view initialize
awilson2017 0d328ba
made render for QuoteListView
awilson2017 79a0c0f
made quote_view.js file
awilson2017 2fc5386
create both initialize and render func for QuoteView
awilson2017 1a9fe77
add quote_view events hash, buyQuote, sellQuote, and associated model…
awilson2017 0a2375e
prepend trade transactions to the dom
awilson2017 d68627f
made Order Entry Form quote dropdown
awilson2017 dd1d6dd
order_view_form: add readOrderFormData func
awilson2017 296c6fb
properly render one order to DOM. need to work on rendering order col…
awilson2017 5e74967
render order collection properly
awilson2017 217a4c4
Add cancel functionality to orders
awilson2017 1691285
first attempt at auto-buy functionality. not working
awilson2017 563bbf3
functionality for auto-buy works. making the transaction appear in th…
awilson2017 7f9a558
add tests for the order model validations
awilson2017 dec1445
add the order model validations
awilson2017 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import Quote from 'models/quote'; | ||
| import Order from 'models/order'; | ||
|
|
||
| describe('Order spec', () => { | ||
| let quote; | ||
| let order; | ||
| beforeEach(() => { | ||
| quote = new Quote({ | ||
| symbol: 'CLOTH', | ||
| price: 100.00, | ||
| }); | ||
| order = new Order({ | ||
| symbol: 'CLOTH', | ||
| quote: quote, | ||
| buy: true, | ||
| targetPrice: 100, | ||
| }) | ||
| }); | ||
|
|
||
| describe('Create a new Order', () => { | ||
| it('creates a valid instance of an Order', () => { | ||
| order.set('targetPrice', 80.00); | ||
| order.set('buy', true); | ||
|
|
||
| expect(order.isValid()).toEqual(true); | ||
| }) | ||
|
|
||
| it('invalid order if price is not a number', () => { | ||
| order.set('targetPrice', 'hello'); | ||
|
|
||
| expect(order.isValid()).toEqual(false); | ||
| }) | ||
|
|
||
| it('invalid buy order if price is higher than market', () => { | ||
| order.set('targetPrice', 180); | ||
| order.set('buy', true); | ||
|
|
||
| expect(order.isValid()).toEqual(false); | ||
| }) | ||
|
|
||
| it('invalid sell order if price is lower than market', () => { | ||
| order.set('targetPrice', 8); | ||
| order.set('buy', false); | ||
|
|
||
| expect(order.isValid()).toEqual(false); | ||
| }) | ||
| }); | ||
| }); |
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 |
|---|---|---|
|
|
@@ -2,17 +2,25 @@ 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 Simulator from './models/simulator'; | ||
| import QuoteList from './collections/quote_list'; | ||
| import Order from './models/order' | ||
| import OrderList from './collections/order_list' | ||
|
|
||
| import QuoteListView from './views/quote_list_view'; | ||
| import TradeListView from './views/trade_list_view'; | ||
| import OrderFormView from './views/order_form_view'; | ||
| import OrderListView from './views/order_list_view'; | ||
|
|
||
| const quoteData = [ | ||
| { | ||
| symbol: 'HUMOR', | ||
| symbol: '유머', | ||
| price: 88.50, | ||
| }, | ||
| { | ||
| symbol: 'CLOTH', | ||
| symbol: '피복', | ||
| price: 81.70, | ||
| }, | ||
| { | ||
|
|
@@ -25,11 +33,64 @@ const quoteData = [ | |
| }, | ||
| ]; | ||
|
|
||
| quoteData.forEach(function(quote) { | ||
| $('#dropdown').append(`<option>${quote.symbol}</option>`) | ||
| }) | ||
|
|
||
|
|
||
|
|
||
| $(document).ready(function() { | ||
|
|
||
|
|
||
| let bus = {}; | ||
| bus = _.extend(bus, Backbone.Events); | ||
|
|
||
| let template = _.template($('#quote-template').html()); | ||
| let tradeTemplate = _.template($('#trade-template').html()); | ||
| let orderTemplate = _.template($('#order-template').html()); | ||
|
|
||
| const quotes = new QuoteList(quoteData); | ||
| const simulator = new Simulator({ | ||
| quotes: quotes, | ||
| }); | ||
| const orders = new OrderList(); | ||
|
|
||
| const quoteListView = new QuoteListView({ | ||
| el: '#quotes-container', | ||
| model: quotes, | ||
| template: template, | ||
| bus: bus, | ||
| }); | ||
|
|
||
| const tradeListView = new TradeListView({ | ||
| el: '#trades-container', | ||
| template: tradeTemplate, | ||
| bus: bus, | ||
| }) | ||
| const orderFormView = new OrderFormView({ | ||
| // quoteData: quoteData, | ||
| el: '.order-entry-form', | ||
| bus: bus, | ||
| orderList: orders, | ||
| quoteList: quotes, | ||
| }); | ||
|
|
||
| const order = new Order({ | ||
|
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. It doesn't look like this instance of |
||
| bus: bus, | ||
| }) | ||
|
|
||
| const orderListView = new OrderListView({ | ||
| el: '.orders-list-container', | ||
| model: orders, | ||
| template: orderTemplate, | ||
| bus: bus, | ||
| }); | ||
|
|
||
|
|
||
| orderListView.render(); | ||
| quoteListView.render(); | ||
|
|
||
| simulator.start(); | ||
|
|
||
|
|
||
| }); | ||
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,28 @@ | ||
| import Backbone from 'backbone'; | ||
|
|
||
| const Order = Backbone.Model.extend({ | ||
| defaults: { | ||
| symbol: 'UNDEF', | ||
| targetPrice: 9.00, | ||
| buy: true, | ||
| }, | ||
| validate: function(attributes) { | ||
| let error = ''; | ||
|
|
||
| if (attributes.buy && (attributes.targetPrice >= attributes.quote.get('price'))) { | ||
| error = 'Price higher than market price!'; | ||
| } else if (!attributes.buy && (attributes.targetPrice <= attributes.quote.get('price'))) { | ||
| error = 'Price lower than market price!'; | ||
| } else if (isNaN(attributes.targetPrice)) { | ||
| error = 'Invalid Target Price'; | ||
| } | ||
|
|
||
| if (error != '') { | ||
| return error | ||
| } else { | ||
| return false | ||
| } | ||
| }, | ||
| }) | ||
|
|
||
| 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
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,61 @@ | ||
| import Backbone from 'backbone'; | ||
|
|
||
| import Quote from '../models/quote'; | ||
| import Order from '../models/order'; | ||
| import OrderList from '../collections/order_list'; | ||
| import QuoteList from '../collections/quote_list'; | ||
|
|
||
|
|
||
| const OrderFormView = Backbone.View.extend({ | ||
| initialize(params){ | ||
| this.bus = params.bus; | ||
| this.quoteList = params.quoteList | ||
| }, | ||
| // quoteData.each((quote) => { | ||
| // $('#dropdown').append(`<option>${quote.symbol}</option>`); | ||
| // }), | ||
|
|
||
| readOrderFormData(type) { | ||
| const orderData = {}; | ||
|
|
||
| const $inputSymbolValue = this.$(`select[name="symbol"]`).val(); | ||
| const $inputPriceTargert = this.$(`input[name="price-target"]`) | ||
|
|
||
|
|
||
| const priceValue = parseFloat($inputPriceTargert.val()).toFixed(2); | ||
| // console.log(`priceValue = ${priceValue}`); | ||
|
|
||
| // Don't take empty strings, so that Backbone can | ||
| // fill in default values | ||
| orderData['symbol'] = $inputSymbolValue; | ||
| if (priceValue != '') { | ||
| orderData['targetPrice'] = priceValue; | ||
| } | ||
| orderData['buy'] = type | ||
| console.log(this.quoteList); | ||
| console.log(orderData['symbol']) | ||
| orderData['quote'] = this.quoteList.find({symbol: orderData['symbol']}); | ||
| $inputPriceTargert.val(''); | ||
| return orderData; | ||
| }, | ||
| events: { | ||
| 'click button.btn-buy': 'buyOrder', | ||
| 'click button.btn-sell': 'orderSell', | ||
| }, | ||
| buyOrder(event) { | ||
| event.preventDefault(); | ||
| console.log('test click order'); | ||
| let orderObject = this.readOrderFormData(true) | ||
|
|
||
| this.bus.trigger('newOrder', orderObject) | ||
| }, | ||
|
|
||
| orderSell(event) { | ||
| event.preventDefault(); | ||
| console.log('test click orderSell'); | ||
| let orderObject = this.readOrderFormData(false); | ||
| this.bus.trigger('newOrder', orderObject) | ||
| } | ||
|
|
||
| }); | ||
| 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.
This code should really be within the
$(document).ready(...)callback function.The reason for that is because we're using jQuery to find the
selecttag on the page with IDdropdown, and then manipulating it by appendingoptiontags inside of it. Both of these things are only guaranteed to work properly if we wait until the entire page has been loaded -- which is what the$(document).ready(...)is for.We can see the problem manifest if we change
index.htmlto have thescripttag forapp.bundle.jsinside of theheadtag after themetatags, instead of at the bottom of thebodytag. By moving the JS code to the top of our HTML file, the browser will load it and run the JS code inapp.jsfirst, before, loading the actual HTML content of the page.In that case the drop down selection does not have any options added to it, because when this line of code runs jQuery cannot find the
selecttag with IDdropdown(because it hasn't been loaded yet from the HTML file).