GithubHelp home page GithubHelp logo

babzcraig / currency-pair-trader Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 141 KB

A sample app that allows users buy Bitcoin using their USD account at the current exchange rate

JavaScript 84.71% HTML 1.78% CSS 13.51%

currency-pair-trader's Introduction

Currency Pair Trader

This app allows user execute trades against realtime exchange rates of USD to BTC. User has a prefunded account of $156.12 and can make trades of any amount up to his current account balance.

To run

To run the app, clone the repo then run

$ npm install

After modules have installed you can run the app in development mode with

$ npm start

This will run the app using webpack dev-server in development mode. It's set up with hot reloading so that a full browser reload is only made for those changes requiring it. We also include plug-ins for Babel (so we have access to ES6 and ES7 features - such as aync/await) and SCSS for styling.

To build

The development build is not optimized. To create an optimized production build with minification, caching etc, run

$ npm build

This will output a build folder containing the production ready app which can be deployed.

To test

Tests can be run using

$ npm test

This will run unit tests for the components in the app.

**In the interest of time, only a few components have been tested.

Notes

  • The app fetches the last price at intervals. This interval is stored in a constant called POLLING_INTERVAL_IN_MS. If there is an amount to buy value in the form field, the app will also adjust the BTC quote field accordingly. It will also show a warning to the user that the price has changed, alerting them so they can confirm before making a trade. This takes care of the use case where a user might walk away from the app and return after a prolonged interval during which time the exchange rates might have changes due to the volatile nature of bitcoin marketplace.
  • Our babel presets are stored in the .babelrc file. For this project we are using "env", "react" and "stage-2" presets. This will give us the fliexibility to use ES6 and 7 features such as destructuring, spread operators and async/await which helps keep code shorter and more readable.

App Structure

Entry point into the app is the index.js file. The rest of the files are kept in folders.

  • The actions folder contains our redux actions. These dispatch actions to our reducers.
  • The components folder holds all of our components. At the root of this is the App component. This is the base component. Components are further broken down into containers - Smart components which handle data though not always handling state and screens Dumb containers which simply present the data to the user and are almost always functional components. The folders are named accordingly.
  • The constants folder exports our action types and other app constants such as the time-delay for fetching updated data
  • The reducers folder holds our reducers. It uses the combine reducers function provided by redux to combine the various reducers. We have a reducer that handles user data and one for ticker data. Both files are named accordingly.
  • The store is our redux store. This file pulls in the reducers and applies the middleware we will be using. In this project we are using the thunk middleware which allows us write async actions. This is especially useful when actions need to carry out asynchronous operations such as fetching the current BTC rate.
  • The styles folder holds the styling for the app. As this is a one sceen app, this is simply an index.scss file but in a larger app, there would be files for each reasonably large component as well as files for base styles, variables and so on.
  • The utils folder holds our utility functions. This allows components that require a common functions to share them. It also keeps code neat by storing these functions away behind the scenes.

currency-pair-trader's People

Contributors

babzcraig avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.