Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Dania02525 committed Jan 14, 2018
0 parents commit be13aae
Show file tree
Hide file tree
Showing 46 changed files with 1,545 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# App artifacts
/_build
/db
/deps
/*.ez

# Generated on crash by the VM
erl_crash.dump

# Generated on crash by NPM
npm-debug.log

# Static artifacts
/assets/node_modules

# Since we are building assets from assets/,
# we ignore priv/static. You may want to comment
# this depending on your deployment strategy.
/priv/static/

# Files matching config/*.secret.exs pattern contain sensitive
# data and you should not commit them into version control.
#
# Alternatively, you may comment the line below and commit the
# secrets files as long as you replace their contents by environment
# variables.
/config/*.secret.exs
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# ElixirExchange

To start your Phoenix server:

* Install dependencies with `mix deps.get`
* Create and migrate your database with `mix ecto.create && mix ecto.migrate`
* Install Node.js dependencies with `cd assets && npm install`
* Start Phoenix endpoint with `mix phx.server`

Now you can visit [`localhost:4000`](http://localhost:4000) from your browser.

Ready to run in production? Please [check our deployment guides](http://www.phoenixframework.org/docs/deployment).

## Learn more

* Official website: http://www.phoenixframework.org/
* Guides: http://phoenixframework.org/docs/overview
* Docs: https://hexdocs.pm/phoenix
* Mailing list: http://groups.google.com/group/phoenix-talk
* Source: https://github.com/phoenixframework/phoenix
62 changes: 62 additions & 0 deletions assets/brunch-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
exports.config = {
// See http://brunch.io/#documentation for docs.
files: {
javascripts: {
joinTo: "js/app.js"

// To use a separate vendor.js bundle, specify two files path
// http://brunch.io/docs/config#-files-
// joinTo: {
// "js/app.js": /^js/,
// "js/vendor.js": /^(?!js)/
// }
//
// To change the order of concatenation of files, explicitly mention here
// order: {
// before: [
// "vendor/js/jquery-2.1.1.js",
// "vendor/js/bootstrap.min.js"
// ]
// }
},
stylesheets: {
joinTo: "css/app.css"
},
templates: {
joinTo: "js/app.js"
}
},

conventions: {
// This option sets where we should place non-css and non-js assets in.
// By default, we set this to "/assets/static". Files in this directory
// will be copied to `paths.public`, which is "priv/static" by default.
assets: /^(static)/
},

// Phoenix paths configuration
paths: {
// Dependencies and current project directories to watch
watched: ["static", "css", "js", "vendor"],
// Where to compile files to
public: "../priv/static"
},

// Configure your plugins
plugins: {
babel: {
// Do not use ES6 compiler in vendor code
ignore: [/vendor/]
}
},

modules: {
autoRequire: {
"js/app.js": ["js/app"]
}
},

npm: {
enabled: true
}
};
1 change: 1 addition & 0 deletions assets/css/app.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* This file is for your main application css. */
28 changes: 28 additions & 0 deletions assets/css/phoenix.css

Large diffs are not rendered by default.

193 changes: 193 additions & 0 deletions assets/js/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
// Brunch automatically concatenates all files in your
// watched paths. Those paths can be configured at
// config.paths.watched in "brunch-config.js".
//
// However, those files will only be executed if
// explicitly imported. The only exception are files
// in vendor, which are never wrapped in imports and
// therefore are always executed.

// Import dependencies
//
// If you no longer want to use a dependency, remember
// to also remove its path from "config.paths.watched".
import "phoenix_html"

import {Socket} from "phoenix"

// Import local files
//
// Local files can be imported directly using relative
// paths "./socket" or full ones "web/static/js/socket".

//import socket from "./socket"

let socket = new Socket("/socket", {params: {token: window.userToken}})

socket.connect()

let channel = socket.channel("trading:xrb:xlm", {})


channel.join()
.receive("ok", resp => { console.log("Joined successfully", resp) })
.receive("error", resp => { console.log("Unable to join", resp) })


var margin = {top: 20, right: 20, bottom: 30, left: 50},
width = 960 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom;

var parseDate = d3.timeParse("%d-%b-%y");

var x = techan.scale.financetime()
.range([0, width]);

var y = d3.scaleLinear()
.range([height, 0]);

var candlestick = techan.plot.candlestick()
.xScale(x)
.yScale(y);

var xAxis = d3.axisBottom()
.scale(x);

var yAxis = d3.axisLeft()
.scale(y);

var svg = d3.select("body").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");

var data = [];

channel.on("update", payload => {
data.shift();
data.push({
date: d3.isoParse(payload.data.date),
open: payload.data.open,
high: payload.data.high,
low: payload.data.low,
close: payload.data.close,
volume: payload.data.volume
})
draw();
})

channel.on("init", payload => {
data = payload.data.map(function(d) {
return {
date: d3.isoParse(d.date),
volume: d.volume,
open: d.open,
high: d.high,
low: d.low,
close: d.close
};
});

svg.append("g")
.attr("class", "candlestick");

svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")");

svg.append("g")
.attr("class", "y axis")
.append("text")
.attr("transform", "rotate(-90)")
.attr("y", 6)
.attr("dy", ".71em")
.style("text-anchor", "end")
.text("Price ($)");

draw();
})


function initData() {
var i;
for(i=0;i<199;i++) {
data.push(generateDatum())
}

svg.append("g")
.attr("class", "candlestick");

svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")");

svg.append("g")
.attr("class", "y axis")
.append("text")
.attr("transform", "rotate(-90)")
.attr("y", 6)
.attr("dy", ".71em")
.style("text-anchor", "end")
.text("Price ($)");

draw();
}

function beginFeedData() {
setInterval(function() {
data.shift();
data.push(generateDatum());
console.log(data);
draw()
}, 5000)
}

function generateDatum() {
if(data.length === 0) {
return {
date: new Date(),
open: 40.9,
high: 41.94,
low: 40.62,
close: 41.34,
volume: 94162358
}
}
var prevData = data[data.length-1]
var prevTime = prevData.Date;
var newOpen = randomPriceFrom(prevData.open, randomSign());
var newHigh = randomPriceFrom(newOpen, 1);
var newLow = randomPriceFrom(newOpen, -1);

return {
date: addMinutes(prevData.date, 5),
open: newOpen,
high: newHigh,
low: newLow,
close: randomPriceFrom(newOpen, randomSign()),
volume: prevData.volume
}
}

function addMinutes(date, minutes) {
return new Date(date.getFullYear(), date.getMonth(), date.getDay(), date.getHours(), date.getMinutes() + minutes)
}

function randomSign() {
return (Math.random() < 0.5) ? -1 : 1;
}

function randomPriceFrom(float, sign) {
var pct = (((Math.random() * 10) + 1) / 100) * sign;
return float * (1 + pct);
}

function draw() {
x.domain(data.map(candlestick.accessor().d));
y.domain(techan.scale.plot.ohlc(data, candlestick.accessor()).domain());

svg.selectAll("g.candlestick").datum(data).call(candlestick);
svg.selectAll("g.x.axis").call(xAxis);
svg.selectAll("g.y.axis").call(yAxis);
}
23 changes: 23 additions & 0 deletions assets/js/socket.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// NOTE: The contents of this file will only be executed if
// you uncomment its entry in "assets/js/app.js".

// To use Phoenix channels, the first step is to import Socket
// and connect at the socket path in "lib/web/endpoint.ex":
import {Socket} from "phoenix"

let socket = new Socket("/socket", {params: {token: window.userToken}})

socket.connect()

// Now that you are connected, you can join channels with a topic:
let channel = socket.channel("trading:xrb:xlm", {})

channel.on("update", payload => {
console.log(payload);
})

channel.join()
.receive("ok", resp => { console.log("Joined successfully", resp) })
.receive("error", resp => { console.log("Unable to join", resp) })

export default socket
18 changes: 18 additions & 0 deletions assets/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"repository": {},
"license": "MIT",
"scripts": {
"deploy": "brunch build --production",
"watch": "brunch watch --stdin"
},
"dependencies": {
"phoenix": "file:../deps/phoenix",
"phoenix_html": "file:../deps/phoenix_html"
},
"devDependencies": {
"babel-brunch": "6.1.1",
"brunch": "2.10.9",
"clean-css-brunch": "2.10.0",
"uglify-js-brunch": "2.10.0"
}
}
Binary file added assets/static/favicon.ico
Binary file not shown.
Binary file added assets/static/images/phoenix.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions assets/static/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file
#
# To ban all spiders from the entire site uncomment the next two lines:
# User-agent: *
# Disallow: /
27 changes: 27 additions & 0 deletions config/config.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# This file is responsible for configuring your application
# and its dependencies with the aid of the Mix.Config module.
#
# This configuration file is loaded before any dependency and
# is restricted to this project.
use Mix.Config

# General application configuration
config :elixir_exchange,
ecto_repos: [ElixirExchange.Repo]

# Configures the endpoint
config :elixir_exchange, ElixirExchangeWeb.Endpoint,
url: [host: "localhost"],
secret_key_base: "+JP6irDDa7NQCWkOKvW+hJD87Oa6eqSEcT3AZiKFJ9y/BYfts9K6wNBk4mUGn8OY",
render_errors: [view: ElixirExchangeWeb.ErrorView, accepts: ~w(html json)],
pubsub: [name: ElixirExchange.PubSub,
adapter: Phoenix.PubSub.PG2]

# Configures Elixir's Logger
config :logger, :console,
format: "$time $metadata[$level] $message\n",
metadata: [:request_id]

# Import environment specific config. This must remain at the bottom
# of this file so it overrides the configuration defined above.
import_config "#{Mix.env}.exs"
Loading

0 comments on commit be13aae

Please sign in to comment.