diff --git a/websrc/components/App.tsx b/websrc/components/App.tsx index bcf069a..4cf61ac 100644 --- a/websrc/components/App.tsx +++ b/websrc/components/App.tsx @@ -4,12 +4,14 @@ import HCard from "./HCard"; import RPlot from "./RPlot"; import {NewTickData, PositionState, socket} from "../"; import {PositionTable} from "./Tables"; +import {EventData, Events} from "./Events"; type AppState = { current_price: number, current_tick: number, last_update: Date, - positions: Array + positions: Array, + events: Array } @@ -18,7 +20,8 @@ class App extends Component<{}, AppState> { current_price: 0, current_tick: 0, last_update: new Date(), - positions: [] + positions: [], + events: [] } constructor(props) { @@ -27,11 +30,14 @@ class App extends Component<{}, AppState> { componentDidMount() { socket.on("new_tick", (data: NewTickData) => { + const event: EventData = {name: "New Tick", id: data.tick, tick: data.tick} + this.setState({ current_price: data.price, current_tick: data.tick, last_update: new Date(), - positions: data.positions + positions: data.positions, + events: [...this.state.events, event] }) }) } @@ -40,22 +46,25 @@ class App extends Component<{}, AppState> { return (
- Rustico - BfxBot + Rustico - BfxBot {/* Toolbar column */} - + - + + + + {/* Graph column */} @@ -71,7 +80,7 @@ class App extends Component<{}, AppState> { */} -
+
Made with ❤️ by the Pepe diff --git a/websrc/components/Events.tsx b/websrc/components/Events.tsx new file mode 100644 index 0000000..5faeef4 --- /dev/null +++ b/websrc/components/Events.tsx @@ -0,0 +1,49 @@ +import React, {Component} from "react"; +import {Container, ListGroup} from "react-bootstrap"; + + +export type EventData = { + id: number, + name: string, + tick: number +} + + +const testEvent: EventData = { + id: 1, + name: "Test", + tick: 1 +} + +export class Events extends Component<{ events: Array }, { events: Array }> { + constructor(props) { + super(props); + } + + state = { + events: this.props.events + } + + mapEvents() { + return this.state.events.map((event: EventData) => { + return ( + + {event.name} @ Tick {event.tick} + + ) + }) + } + + render() { + return ( + +
+

Events

+
+ + {this.mapEvents()} + +
+ ) + } +} \ No newline at end of file diff --git a/websrc/components/Tables.tsx b/websrc/components/Tables.tsx index b062301..fe1cdd8 100644 --- a/websrc/components/Tables.tsx +++ b/websrc/components/Tables.tsx @@ -1,33 +1,71 @@ import React, {Component} from "react" -import {Container, Table} from "react-bootstrap" -import {NewTickData, PositionState, socket} from '../'; +import {Badge, Button, Container, Table} from "react-bootstrap" +import {PositionState} from '../'; export class PositionTable extends Component<{}, { positions: Array }> { + testPosition: PositionState = { + base_price: 1, + id: 1, + profit_loss: 1000, + profit_loss_percentage: 1000, + state: "loss", + symbol: "PAPARCOIN" + } + state = { - positions: [] + positions: [this.testPosition] } constructor(props) { super(props) } + stateVariantFromStr(state: string): string { + const lower_state = state.toLowerCase() + let res: string; + + if (lower_state.includes("profit")) { + res = "success" + } else if (lower_state.includes("break")) { + res = "primary" + } else { + res = "danger" + } + + return res + } + + plColorFromStr(amount: number): string { + if (amount > 0) { + return "success" + } else { + return "danger" + } + } + componentDidMount() { - socket.on('new_tick', (data: NewTickData) => { - this.setState({ - positions: data.positions - }) + this.setState({ + positions: [this.testPosition] }) + + // socket.on('new_tick', (data: NewTickData) => { + // this.setState({ + // positions: [...this.state.positions, data.positions] + // }) + // }) } tableData() { return this.state.positions.map((position: PositionState) => { return ( - {position.id} - {position.symbol} - {position.base_price.toFixed(2)} - {position.profit_loss.toFixed(2)} - {position.profit_loss_percentage.toFixed(2)} % + {position.state} + {position.symbol} + {position.base_price.toFixed(2)} + {position.profit_loss.toFixed(2)} + {position.profit_loss_percentage.toFixed(2)} % + ) }) } @@ -38,14 +76,15 @@ export class PositionTable extends Component<{}, { positions: Array

Open positions

- +
- + + diff --git a/websrc/index.tsx b/websrc/index.tsx index 5f30412..2d36b35 100644 --- a/websrc/index.tsx +++ b/websrc/index.tsx @@ -14,6 +14,7 @@ export type NewTickData = { export type PositionState = { id: number, + state: string, base_price: number, symbol: string, profit_loss: number,
IDState Symbol Base price P/L P/L %Action