Skip to content

Commit

Permalink
major improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
TimoScheuermann committed Apr 2, 2021
1 parent e4ded2d commit b8bb99d
Show file tree
Hide file tree
Showing 19 changed files with 387 additions and 327 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"apexcharts": "^3.25.0",
"axios": "^0.21.1",
"core-js": "^3.6.4",
"moonstonks-boersenapi": "^1.3.2",
"moonstonks-boersenapi": "^1.3.3",
"node-sass": "^4.13.1",
"register-service-worker": "^1.7.1",
"socket.io-client": "2.3.0",
Expand Down
12 changes: 5 additions & 7 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import { Vue, Component } from 'vue-property-decorator';
import BRouter from './components/BRouter.vue';
import BNavbar from './components/BNavbar.vue';
import { Price } from 'moonstonks-boersenapi';
import { ShareManager } from '@/utils/ShareManager';
import BTabbar from './components/BTabbar.vue';
import {
registerMediaQueries,
unregisterMediaQueries
} from '@/utils/mediaQueries';
import backend from './utils/backend';
import { PriceHistoryManager } from './utils/PriceHistoryManager';
import { OrderbookManager } from './utils/OrderbookManager';
@Component({
components: {
Expand All @@ -30,7 +30,6 @@ import backend from './utils/backend';
export default class App extends Vue {
mounted() {
registerMediaQueries();
this.loadOrderbook();
}
beforeDestroy() {
Expand All @@ -39,13 +38,12 @@ export default class App extends Vue {
@Socket('price')
priceChanged(price: Price & { shareId: string }): void {
ShareManager.addPrice(price);
PriceHistoryManager.priceChanged(price.shareId, price);
}
@Socket('update-orderbook')
public async loadOrderbook(): Promise<void> {
const { data } = await backend.get('order/orders');
this.$store.commit('orderbook', data);
public async loadOrderbook(shareId: string): Promise<void> {
OrderbookManager.loadBook(shareId);
}
}
</script>
Expand Down
6 changes: 0 additions & 6 deletions src/components/BNavbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@
routeName="home"
tfcolor="error"
/>
<tc-navbar-item
icon="book-filled"
name="Orderbook"
routeName="orderbook"
tfcolor="error"
/>
<tc-navbar-item
icon="file-text"
name="Clearing"
Expand Down
6 changes: 0 additions & 6 deletions src/components/BTabbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@
routeName="home"
tfcolor="error"
/>
<tc-tabbar-item
icon="book-filled"
title="Orderbook"
routeName="orderbook"
tfcolor="error"
/>
<tc-tabbar-item
icon="file-text"
title="Clearing"
Expand Down
62 changes: 31 additions & 31 deletions src/components/charts/BBuySellCumulative.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<BChartWrapper
v-if="ordersOfShare.length > 0"
v-if="orders.length > 0"
class="view-b-buy-sell-cumulative"
subtitle="Buy & Sell"
title="Cumulative Orders"
Expand All @@ -17,12 +17,14 @@
</template>

<script lang="ts">
import { Share, ShareManager } from '@/utils/ShareManager';
import { Order } from 'moonstonks-boersenapi';
import { Vue, Component, Prop, Watch } from 'vue-property-decorator';
import { Vue, Component, Prop } from 'vue-property-decorator';
import BChartWrapper from './BChartWrapper.vue';
import VueApexCharts from 'vue-apexcharts';
import { LimitAndAmount } from '@/utils/OrderbookManager';
import backend from '@/utils/backend';
import { EventBus } from '@/utils/eventbus';
@Component({
components: {
BChartWrapper,
Expand All @@ -32,46 +34,44 @@ import VueApexCharts from 'vue-apexcharts';
export default class BBuySellCumulative extends Vue {
@Prop() shareId!: string;
@Watch('orders', { deep: true, immediate: true })
updateChart() {
// eslint-disable-next-line
const elem = this.$refs.BBuySellCumulative as any;
if (elem) elem.updateSeries(this.series, true);
}
get share(): Share | null {
return ShareManager.getShare(this.shareId);
}
public orders: LimitAndAmount[] = [];
get orders(): Order[] | null {
return this.$store.getters.orderbook;
mounted() {
this.loadData();
EventBus.$on('order-book-updated', (shareId: string) => {
if (this.shareId === shareId) {
this.loadData();
}
});
}
get ordersOfShare(): Order[] {
if (!this.share) return [];
return (this.orders || []).filter(o => o.shareId === this.shareId);
public loadData(): void {
if (this.shareId) {
backend.get('orderbook/limitsAndAmounts/' + this.shareId).then(res => {
this.orders = res.data;
// eslint-disable-next-line
const elem = this.$refs.BBuySellCumulative as any;
if (elem) elem.updateSeries(this.series, true);
});
}
}
get sellOrders(): Order[] {
return this.ordersOfShare.filter(o => o.type === 'sell');
get sellOrders(): LimitAndAmount[] {
return this.orders.filter(o => o.type === 'sell');
}
get buyOrders(): Order[] {
return this.ordersOfShare.filter(o => o.type === 'buy');
get buyOrders(): LimitAndAmount[] {
return this.orders.filter(o => o.type === 'buy');
}
get uniqueBuyLimits(): number[] {
return [
// eslint-disable-next-line
...new Set(this.buyOrders.map(x => x.limit || this.share!.price))
].sort((a, b) => a - b);
return [...new Set(this.buyOrders.map(x => x.limit))].sort((a, b) => a - b);
}
get uniqueSellLimits(): number[] {
return [
// eslint-disable-next-line
...new Set(this.sellOrders.map(x => x.limit || this.share!.price))
].sort((a, b) => b - a);
return [...new Set(this.sellOrders.map(x => x.limit))].sort(
(a, b) => b - a
);
}
get buySeries(): { x: number; y: number }[] {
Expand Down
150 changes: 150 additions & 0 deletions src/components/charts/BOrderbook.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
<template>
<BChartWrapper
class="b-orderbook"
v-if="share && orderbook"
:subtitle="share.name"
title="Orderbook"
>
<div class="table-wrapper">
<table>
<tr>
<th>Date</th>
<th>Amount</th>
<th>Limit</th>
<th>Amount</th>
<th>Date</th>
</tr>
<tr>
<td></td>
<td></td>
<td colspan="3">
... {{ Math.max(orderbook.totalSellOrders - 10, 0) }} more
</td>
</tr>
<tr v-for="o in orderbook.sellOrders" :key="o.id">
<td></td>
<td></td>
<td :type="o.limit ? 'sell' : 'market'">{{ o.limit || 'Market' }}</td>
<td>{{ Math.round(o.amount * 100) / 100 }}</td>
<td>{{ formatTime(o.timestamp) }}</td>
</tr>
<tr v-for="o in orderbook.buyOrders" :key="o.id">
<td>{{ formatTime(o.timestamp) }}</td>
<td>{{ Math.round(o.amount * 100) / 100 }}</td>
<td :type="o.limit ? 'buy' : 'market'">{{ o.limit || 'Market' }}</td>
<td></td>
<td></td>
</tr>
<tr>
<td colspan="3">
... {{ Math.max(orderbook.totalBuyOrders - 10, 0) }} more
</td>
<td></td>
<td></td>
</tr>
</table>
</div>
</BChartWrapper>
</template>

<script lang="ts">
import { OrderbookManager, Orderbook } from '@/utils/OrderbookManager';
import { ShareManager } from '@/utils/ShareManager';
import { Vue, Component, Prop } from 'vue-property-decorator';
import BChartWrapper from './BChartWrapper.vue';
import { Share } from 'moonstonks-boersenapi';
@Component({
components: {
BChartWrapper
}
})
export default class BOrderbook extends Vue {
@Prop() shareId!: string;
get share(): Share | null {
return ShareManager.getShare(this.shareId);
}
get orderbook(): Orderbook | null {
return OrderbookManager.getBook(this.shareId);
}
public formatTime(timestamp: number): string {
const date = new Date(timestamp);
const y = date.getFullYear();
const m = date.getMonth() + 1;
const d = date.getDate();
const hh = ('0' + date.getHours()).slice(-2);
const mm = ('0' + date.getMinutes()).slice(-2);
const ss = ('0' + date.getSeconds()).slice(-2);
return `${d}.${m}.${y}\n${hh}:${mm}:${ss}`;
}
}
</script>

<style lang="scss" scoped>
.b-orderbook {
.table-wrapper {
overflow-x: auto;
table {
overflow: hidden;
width: 100%;
border-collapse: collapse;
tr {
&:first-child {
background: rgba(#111, 0.3);
backdrop-filter: blur(20px);
border-radius: $border-radius;
overflow: hidden;
}
th {
padding: 5px 10px;
}
td {
text-align: center;
white-space: pre-wrap;
&:nth-child(3) {
font-weight: bold;
}
&:first-child,
&:last-child {
opacity: 0.5;
font-weight: 550;
font-size: 11px;
}
&[type='sell'] {
color: $error;
&::after {
content: '';
}
}
&[type='buy'] {
color: $success;
&::after {
content: '';
}
}
&[type='market'] {
color: $alarm;
}
}
&:nth-child(2),
&:last-child {
td {
padding: 10px;
font-size: 14px;
}
}
}
}
}
}
</style>
Loading

0 comments on commit b8bb99d

Please sign in to comment.