More Code Cleaning
This commit is contained in:
1 parent
8ce0384e00
commit
03422d65d3
7 files changed
+1
-453
No files matched your search
Binary file not shown.
@@ -1,120 +0,0 @@
|
||||
|
||||
function newAggregatedOrdersArray() {
|
||||
|
||||
/* This object generates an array of orders that are aggregated by Amount A. */
|
||||
|
||||
var aggregatedOrdersArray = {
|
||||
eventHandler: undefined,
|
||||
addOrder: addOrder,
|
||||
removeOrder: removeOrder,
|
||||
setSortOrder: setSortOrder,
|
||||
initialize: initialize
|
||||
};
|
||||
|
||||
var array = [];
|
||||
|
||||
var sortOrder = 'ascending';
|
||||
|
||||
aggregatedOrdersArray.eventHandler = newEventHandler();
|
||||
|
||||
return aggregatedOrdersArray;
|
||||
|
||||
function initialize() {
|
||||
this.eventHandler.initialize();
|
||||
}
|
||||
|
||||
function addOrder(order) {
|
||||
|
||||
var wasAdded = false;
|
||||
|
||||
for (var i = 0; i < array.length; i++) {
|
||||
|
||||
var currentItem = array[i];
|
||||
|
||||
if (currentItem.rate === order.rate) {
|
||||
|
||||
currentItem.amountSum = currentItem.amountSum + order.amountA;
|
||||
wasAdded = true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (wasAdded === false) {
|
||||
|
||||
var newItem = {
|
||||
rate: order.rate,
|
||||
amountSum: order.amountA
|
||||
};
|
||||
|
||||
array.push(newItem);
|
||||
|
||||
}
|
||||
|
||||
applySortOrder();
|
||||
|
||||
aggregatedOrdersArray.eventHandler.raiseEvent('Array Changed', array);
|
||||
|
||||
}
|
||||
|
||||
function removeOrder(order) {
|
||||
|
||||
for (var i = 0; i < array.length; i++) {
|
||||
|
||||
var currentItem = array[i];
|
||||
|
||||
if (currentItem.rate === order.rate) { // We find the item in the array where the rate is the same as the orders rate.
|
||||
|
||||
currentItem.amountSum = currentItem.amountSum - order.amountA;
|
||||
|
||||
if (currentItem.amountSum === 0) { // If we reach zero, then there is no reason to keep this element in the array.
|
||||
|
||||
array.splice(i, 1); // This means remove this item from the array.
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
applySortOrder();
|
||||
|
||||
aggregatedOrdersArray.eventHandler.raiseEvent('Array Changed', array);
|
||||
|
||||
}
|
||||
|
||||
function setSortOrder(newSortOrder) {
|
||||
|
||||
sortOrder = newSortOrder;
|
||||
|
||||
applySortOrder();
|
||||
|
||||
aggregatedOrdersArray.eventHandler.raiseEvent('Array Changed', array);
|
||||
|
||||
}
|
||||
|
||||
function applySortOrder() {
|
||||
|
||||
array.sort(compare);
|
||||
|
||||
}
|
||||
|
||||
function compare(itemA, itemB) {
|
||||
|
||||
if (sortOrder === 'ascending') {
|
||||
|
||||
return itemA.rate - itemB.rate;
|
||||
|
||||
}
|
||||
|
||||
if (sortOrder === 'descending') {
|
||||
|
||||
return itemB.rate - itemA.rate;
|
||||
|
||||
}
|
||||
|
||||
return undefined;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -30,7 +30,6 @@
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AccumulatedVolumeBar.js" />
|
||||
<Compile Include="AggregatedOrdersArray.js" />
|
||||
<Compile Include="Animation.js" />
|
||||
<Compile Include="Azure\azure-storage.blob.js" />
|
||||
<Compile Include="FloatingObject.js" />
|
||||
@@ -93,11 +92,9 @@
|
||||
<Compile Include="Panels\ProductsPanel.js" />
|
||||
<Compile Include="Panels\TimeControlPanel.js" />
|
||||
<Compile Include="TimeLineCoordinateSystem.js" />
|
||||
<Compile Include="Resistance.js" />
|
||||
<Compile Include="SplashScreen.js">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="SpreadChart.js" />
|
||||
<Compile Include="ProductStorage.js">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
function newResistance() {
|
||||
|
||||
var resistance = {
|
||||
begin: undefined,
|
||||
end: undefined,
|
||||
type: undefined,
|
||||
rate: undefined,
|
||||
min: undefined,
|
||||
max: undefined,
|
||||
open: undefined,
|
||||
close: undefined
|
||||
};
|
||||
|
||||
return resistance;
|
||||
|
||||
}
|
||||
-309
@@ -1,309 +0,0 @@
|
||||
|
||||
function newSpreadChart() {
|
||||
|
||||
var trades = [];
|
||||
var sells = [];
|
||||
var buys = [];
|
||||
|
||||
var timeLineCoordinateSystem = newTimeLineCoordinateSystem();
|
||||
|
||||
var datetime;
|
||||
var datetimeRange;
|
||||
|
||||
var spreadChart = {
|
||||
setDatetime: setDatetime,
|
||||
setDatetimeRange: setDatetimeRange,
|
||||
container: undefined,
|
||||
draw: draw,
|
||||
getContainer: getContainer,
|
||||
initialize: initialize
|
||||
};
|
||||
|
||||
var container = newContainer();
|
||||
container.initialize();
|
||||
spreadChart.container = container;
|
||||
|
||||
container.displacement.containerName = "Spread Chart";
|
||||
container.frame.containerName = "Spread Chart";
|
||||
|
||||
var marketId;
|
||||
var exchangeId;
|
||||
var marketTrades;
|
||||
|
||||
return spreadChart;
|
||||
|
||||
function initialize(exchange, market, trades) {
|
||||
|
||||
marketId = market;
|
||||
exchangeId = exchange;
|
||||
marketTrades = trades;
|
||||
|
||||
}
|
||||
|
||||
function getContainer(point) {
|
||||
|
||||
var container;
|
||||
|
||||
/* First we check if this point is inside this space. */
|
||||
|
||||
if (this.container.frame.isThisPointHere(point) === true) {
|
||||
|
||||
return this.container;
|
||||
|
||||
} else {
|
||||
|
||||
/* This point does not belong to this space. */
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
function setDatetime(newDatetime) {
|
||||
|
||||
datetime = newDatetime;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function setDatetimeRange(newDatetimeRange) {
|
||||
|
||||
datetimeRange = newDatetimeRange;
|
||||
|
||||
trades = [];
|
||||
|
||||
marketTrades.getTradesByDateRange(datetimeRange, onTradesReady);
|
||||
|
||||
function onTradesReady(tradesReceived) {
|
||||
|
||||
trades = tradesReceived;
|
||||
|
||||
recalculateScale();
|
||||
splitTrades();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function draw() {
|
||||
|
||||
this.container.frame.draw();
|
||||
|
||||
drawBackground();
|
||||
|
||||
plotSpreadChart();
|
||||
}
|
||||
|
||||
|
||||
|
||||
function recalculateScale() {
|
||||
|
||||
var minValue = {
|
||||
x: 10000000000000,
|
||||
y: 10000000000000
|
||||
};
|
||||
|
||||
var maxValue = {
|
||||
x: 0,
|
||||
y: 0
|
||||
};
|
||||
|
||||
for (var i = 0; i < trades.length; i++) {
|
||||
|
||||
var trade = trades[i];
|
||||
|
||||
var datetime = trade.datetime.valueOf();
|
||||
|
||||
if (minValue.x > datetime) {
|
||||
minValue.x = datetime;
|
||||
}
|
||||
|
||||
if (maxValue.x < datetime) {
|
||||
maxValue.x = datetime;
|
||||
}
|
||||
|
||||
var rate = trade.rate;
|
||||
|
||||
if (minValue.y > rate) {
|
||||
minValue.y = rate;
|
||||
}
|
||||
|
||||
if (maxValue.y < rate) {
|
||||
maxValue.y = rate;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
timeLineCoordinateSystem.initialize(
|
||||
minValue,
|
||||
maxValue,
|
||||
spreadChart.container.frame.width,
|
||||
spreadChart.container.frame.height
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function splitTrades() {
|
||||
|
||||
for (let i = 0; i < trades.length; i++) {
|
||||
|
||||
let trade = trades[i];
|
||||
|
||||
if (trade.type === "sell") {
|
||||
sells.push(trade);
|
||||
} else {
|
||||
buys.push(trade);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function plotSpreadChart() {
|
||||
|
||||
if (sells.length > 0) {
|
||||
|
||||
let point;
|
||||
|
||||
let firstPoint = {
|
||||
x: (sells[0].datetime.valueOf() - timeLineCoordinateSystem.min.x) * timeLineCoordinateSystem.scale.x,
|
||||
y: spreadChart.container.frame.height - (sells[0].rate - timeLineCoordinateSystem.min.y) * timeLineCoordinateSystem.scale.y
|
||||
};
|
||||
|
||||
firstPoint = transformThisPoint(firstPoint, spreadChart.container);
|
||||
|
||||
let seconddPoint = {
|
||||
x: (sells[0].datetime.valueOf() - timeLineCoordinateSystem.min.x) * timeLineCoordinateSystem.scale.x,
|
||||
y: spreadChart.container.frame.height
|
||||
};
|
||||
|
||||
seconddPoint = transformThisPoint(seconddPoint, spreadChart.container);
|
||||
|
||||
|
||||
browserCanvasContext.beginPath();
|
||||
|
||||
browserCanvasContext.moveTo(seconddPoint.x, seconddPoint.y);
|
||||
browserCanvasContext.lineTo(firstPoint.x, firstPoint.y);
|
||||
|
||||
let thirdPoint;
|
||||
|
||||
for (let i = 0; i < sells.length; i++) {
|
||||
|
||||
let sell = sells[i];
|
||||
|
||||
point = {
|
||||
x: (sell.datetime.valueOf() - timeLineCoordinateSystem.min.x) * timeLineCoordinateSystem.scale.x,
|
||||
y: spreadChart.container.frame.height - (sell.rate - timeLineCoordinateSystem.min.y) * timeLineCoordinateSystem.scale.y
|
||||
};
|
||||
|
||||
thirdPoint = {
|
||||
x: point.x,
|
||||
y: spreadChart.container.frame.height
|
||||
};
|
||||
|
||||
point = transformThisPoint(point, spreadChart.container);
|
||||
browserCanvasContext.lineTo(point.x, point.y);
|
||||
|
||||
}
|
||||
|
||||
thirdPoint = transformThisPoint(thirdPoint, spreadChart.container);
|
||||
browserCanvasContext.lineTo(thirdPoint.x, thirdPoint.y);
|
||||
|
||||
browserCanvasContext.closePath();
|
||||
|
||||
browserCanvasContext.strokeStyle = 'rgba(117, 27, 5, 0.70)';
|
||||
browserCanvasContext.lineWidth = 1;
|
||||
browserCanvasContext.stroke();
|
||||
|
||||
browserCanvasContext.fillStyle = 'rgba(230, 67, 34, 0.70)';
|
||||
browserCanvasContext.fill();
|
||||
|
||||
}
|
||||
|
||||
if (buys.length > 0) {
|
||||
|
||||
let firstPoint = {
|
||||
x: (buys[0].datetime.valueOf() - timeLineCoordinateSystem.min.x) * timeLineCoordinateSystem.scale.x,
|
||||
y: spreadChart.container.frame.height - (buys[0].rate - timeLineCoordinateSystem.min.y) * timeLineCoordinateSystem.scale.y
|
||||
};
|
||||
|
||||
firstPoint = transformThisPoint(firstPoint, spreadChart.container);
|
||||
|
||||
let seconddPoint = {
|
||||
x: (buys[0].datetime.valueOf() - timeLineCoordinateSystem.min.x) * timeLineCoordinateSystem.scale.x,
|
||||
y: 0
|
||||
};
|
||||
|
||||
seconddPoint = transformThisPoint(seconddPoint, spreadChart.container);
|
||||
|
||||
|
||||
|
||||
browserCanvasContext.beginPath();
|
||||
|
||||
browserCanvasContext.moveTo(seconddPoint.x, seconddPoint.y);
|
||||
browserCanvasContext.lineTo(firstPoint.x, firstPoint.y);
|
||||
|
||||
let thirdPoint;
|
||||
|
||||
for (let i = 0; i < buys.length; i++) {
|
||||
|
||||
let buy = buys[i];
|
||||
|
||||
point = {
|
||||
x: (buy.datetime.valueOf() - timeLineCoordinateSystem.min.x) * timeLineCoordinateSystem.scale.x,
|
||||
y: spreadChart.container.frame.height - (buy.rate - timeLineCoordinateSystem.min.y) * timeLineCoordinateSystem.scale.y
|
||||
};
|
||||
|
||||
thirdPoint = {
|
||||
x: spreadChart.container.frame.width,
|
||||
y: 0
|
||||
};
|
||||
|
||||
point = transformThisPoint(point, spreadChart.container);
|
||||
browserCanvasContext.lineTo(point.x, point.y);
|
||||
|
||||
}
|
||||
|
||||
thirdPoint = transformThisPoint(thirdPoint, spreadChart.container);
|
||||
browserCanvasContext.lineTo(thirdPoint.x, thirdPoint.y);
|
||||
browserCanvasContext.closePath();
|
||||
|
||||
browserCanvasContext.strokeStyle = 'rgba(4, 74, 117, 0.70)';
|
||||
browserCanvasContext.lineWidth = 1;
|
||||
browserCanvasContext.stroke();
|
||||
|
||||
browserCanvasContext.fillStyle = 'rgba(34, 174, 230, 0.70)';
|
||||
browserCanvasContext.fill();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function drawBackground() {
|
||||
|
||||
var market = markets.get(marketId);
|
||||
var label = market.assetA + " " + market.assetB;
|
||||
|
||||
var fontSize = 50;//+ spreadChart.container.zoom.level();
|
||||
|
||||
browserCanvasContext.font = fontSize + 'px verdana';
|
||||
|
||||
/* Now we transform x on the actual coordinate on the canvas. */
|
||||
|
||||
var point = {
|
||||
x: spreadChart.container.frame.width / 2 - label.length / 2 * fontSize / 2,
|
||||
y: spreadChart.container.frame.height * 3 / 8
|
||||
};
|
||||
|
||||
point = transformThisPoint(point, spreadChart.container);
|
||||
|
||||
browserCanvasContext.fillStyle = 'rgba(190, 190, 190, 0.25)';
|
||||
|
||||
browserCanvasContext.fillText(label, point.x, point.y);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,22 +30,18 @@
|
||||
<script type="text/javascript" src="FloatingObject.js"></script>
|
||||
<script type="text/javascript" src="Candle.js"></script>
|
||||
<script type="text/javascript" src="VolumeBar.js"></script>
|
||||
<script type="text/javascript" src="SpreadChart.js"></script>
|
||||
<script type="text/javascript" src="ChartUtilities.js"></script>
|
||||
<script type="text/javascript" src="OrderBookDepthChart.js"></script>
|
||||
<script type="text/javascript" src="TimelineChart.js"></script>
|
||||
<script type="text/javascript" src="Resistance.js"></script>
|
||||
<script type="text/javascript" src="ChartGrid.js"></script>
|
||||
<script type="text/javascript" src="Animation.js"></script>
|
||||
<script type="text/javascript" src="Displace.js"></script>
|
||||
<script type="text/javascript" src="TimeLineCoordinateSystem.js"></script>
|
||||
<script type="text/javascript" src="Utilities.js"></script>
|
||||
<script type="text/javascript" src="ViewPort.js"></script>
|
||||
<script type="text/javascript" src="AggregatedOrdersArray.js"></script>
|
||||
<script type="text/javascript" src="Dashboard.js"></script>
|
||||
<script type="text/javascript" src="AccumulatedVolumeBar.js"></script>
|
||||
|
||||
|
||||
<script type="text/javascript" src="Azure/azure-storage.blob.js"></script>
|
||||
|
||||
<script type="text/javascript" src="Panels/TimeControlPanel.js"></script>
|
||||
|
||||
@@ -6,7 +6,7 @@ if (CONSOLE_LOG === true) {
|
||||
|
||||
}
|
||||
|
||||
const DEBUG_MODE = true; // This forces the server to read Plotters from the local drive.
|
||||
const DEBUG_MODE = false; // This forces the server to read Plotters from the local drive.
|
||||
|
||||
if (CONSOLE_LOG === true && DEBUG_MODE === true) {
|
||||
|
||||
|
||||
Reference in new issue
Block a user