2020-12-14 18:52:43 +00:00
|
|
|
|
import React, {Component} from "react";
|
2020-12-18 14:02:53 +00:00
|
|
|
|
import {EventProp} from "./Events";
|
2020-12-21 13:08:26 +00:00
|
|
|
|
import {
|
|
|
|
|
Balance,
|
|
|
|
|
CurrencyPair,
|
|
|
|
|
EventName,
|
|
|
|
|
FirstConnectMessage,
|
|
|
|
|
NewEventMessage,
|
|
|
|
|
NewTickMessage,
|
|
|
|
|
PositionProp
|
|
|
|
|
} from "../types";
|
2020-12-16 18:29:39 +00:00
|
|
|
|
import {socket} from "../index";
|
2020-12-16 18:46:29 +00:00
|
|
|
|
import {symbolToPair} from "../utils";
|
2020-12-18 14:02:53 +00:00
|
|
|
|
import {Helmet} from "react-helmet";
|
2020-12-19 16:17:48 +00:00
|
|
|
|
import {Navbar, Sidebar} from "./Navbars";
|
|
|
|
|
import {Statusbar} from "./Statusbar";
|
2020-12-19 21:54:04 +00:00
|
|
|
|
import {PositionsTable} from "./Tables";
|
|
|
|
|
import RPlot from "./RPlot";
|
2020-12-13 19:32:33 +00:00
|
|
|
|
|
|
|
|
|
type AppState = {
|
|
|
|
|
current_price: number,
|
|
|
|
|
current_tick: number,
|
2020-12-14 14:50:31 +00:00
|
|
|
|
last_update: Date,
|
2020-12-16 18:46:29 +00:00
|
|
|
|
positions: Array<PositionProp>,
|
|
|
|
|
events: Array<EventProp>,
|
|
|
|
|
active_pair: CurrencyPair,
|
2020-12-21 13:08:26 +00:00
|
|
|
|
available_pairs: Array<CurrencyPair>,
|
|
|
|
|
balances: Array<Balance>
|
2020-12-13 19:32:33 +00:00
|
|
|
|
}
|
2020-12-12 20:18:25 +00:00
|
|
|
|
|
2020-12-14 18:52:43 +00:00
|
|
|
|
class App extends Component<{}, AppState> {
|
2020-12-16 18:29:39 +00:00
|
|
|
|
event_id = 0;
|
|
|
|
|
|
2020-12-13 19:32:33 +00:00
|
|
|
|
state = {
|
|
|
|
|
current_price: 0,
|
|
|
|
|
current_tick: 0,
|
2020-12-14 14:50:31 +00:00
|
|
|
|
last_update: new Date(),
|
2020-12-14 20:26:14 +00:00
|
|
|
|
positions: [],
|
2020-12-16 18:46:29 +00:00
|
|
|
|
events: [],
|
2020-12-21 13:08:26 +00:00
|
|
|
|
balances: [],
|
2020-12-16 18:46:29 +00:00
|
|
|
|
active_pair: symbolToPair("tBTCUSD"),
|
|
|
|
|
available_pairs: []
|
2020-12-13 19:32:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-14 18:52:43 +00:00
|
|
|
|
constructor(props) {
|
|
|
|
|
super(props)
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-13 19:32:33 +00:00
|
|
|
|
componentDidMount() {
|
2020-12-20 12:06:31 +00:00
|
|
|
|
socket.on(EventName.FirstConnect, (data: FirstConnectMessage) => {
|
2020-12-16 11:28:21 +00:00
|
|
|
|
this.setState({
|
|
|
|
|
current_price: data.prices[data.prices.length - 1],
|
|
|
|
|
current_tick: data.ticks[data.ticks.length - 1],
|
|
|
|
|
last_update: new Date(),
|
2020-12-21 13:08:26 +00:00
|
|
|
|
positions: data.positions,
|
|
|
|
|
balances: data.balances
|
2020-12-16 11:28:21 +00:00
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2020-12-20 12:06:31 +00:00
|
|
|
|
socket.on(EventName.NewTick, (data: NewTickMessage) => {
|
2020-12-14 14:50:31 +00:00
|
|
|
|
this.setState({
|
|
|
|
|
current_price: data.price,
|
|
|
|
|
current_tick: data.tick,
|
|
|
|
|
last_update: new Date(),
|
2020-12-14 20:26:14 +00:00
|
|
|
|
positions: data.positions,
|
2020-12-21 13:08:26 +00:00
|
|
|
|
balances: data.balances
|
2020-12-14 14:50:31 +00:00
|
|
|
|
})
|
2020-12-13 19:32:33 +00:00
|
|
|
|
})
|
2020-12-16 12:02:50 +00:00
|
|
|
|
|
2020-12-20 12:06:31 +00:00
|
|
|
|
socket.on(EventName.NewEvent, (data: NewEventMessage) => {
|
2020-12-16 12:02:50 +00:00
|
|
|
|
// ignore new tick
|
|
|
|
|
if (!data.kind.toLowerCase().includes("new_tick")) {
|
2020-12-16 18:29:39 +00:00
|
|
|
|
const new_event: EventProp = {
|
|
|
|
|
id: this.event_id,
|
2020-12-16 12:02:50 +00:00
|
|
|
|
name: data.kind,
|
|
|
|
|
tick: data.tick
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-16 18:29:39 +00:00
|
|
|
|
this.event_id += 1
|
2020-12-16 12:02:50 +00:00
|
|
|
|
|
2020-12-19 16:17:48 +00:00
|
|
|
|
this.setState((state) => ({
|
|
|
|
|
events: [...state.events, new_event]
|
|
|
|
|
}))
|
2020-12-16 12:02:50 +00:00
|
|
|
|
}
|
|
|
|
|
})
|
2020-12-13 19:32:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-12 20:18:25 +00:00
|
|
|
|
render() {
|
|
|
|
|
return (
|
2020-12-18 14:02:53 +00:00
|
|
|
|
<>
|
2020-12-16 12:57:29 +00:00
|
|
|
|
<Helmet>
|
2020-12-17 09:31:09 +00:00
|
|
|
|
<title> Rustico
|
2020-12-21 14:33:53 +00:00
|
|
|
|
- {String(this.state.active_pair.base) + "/" + String(this.state.active_pair.quote)} {String(this.state.current_price.toLocaleString())} </title>
|
2020-12-16 12:57:29 +00:00
|
|
|
|
</Helmet>
|
2020-12-18 19:00:26 +00:00
|
|
|
|
<div className="bg-gray-800">
|
2020-12-19 16:17:48 +00:00
|
|
|
|
<div className="h-screen max-w-screen flex mx-auto">
|
2020-12-18 19:00:26 +00:00
|
|
|
|
<Navbar/>
|
2020-12-19 17:27:46 +00:00
|
|
|
|
|
2020-12-18 19:00:26 +00:00
|
|
|
|
<main
|
2020-12-19 16:17:48 +00:00
|
|
|
|
className="my-1 py-2 px-10 flex-1 bg-gray-200 dark:bg-black rounded-l-lg*
|
2020-12-18 19:00:26 +00:00
|
|
|
|
transition duration-500 ease-in-out overflow-y-auto flex flex-col">
|
|
|
|
|
<div className="flex justify-center text-2xl my-4">
|
2020-12-21 13:08:26 +00:00
|
|
|
|
<Statusbar balances={this.state.balances} positions={this.state.positions}
|
|
|
|
|
price={this.state.current_price}
|
2020-12-19 16:17:48 +00:00
|
|
|
|
tick={this.state.current_tick}/>
|
2020-12-18 19:00:26 +00:00
|
|
|
|
</div>
|
|
|
|
|
|
2020-12-19 16:17:48 +00:00
|
|
|
|
<div className="flex flex-col flex-grow my-8 shadow-md hover:shadow-lg">
|
2020-12-18 19:00:26 +00:00
|
|
|
|
<div
|
2020-12-20 13:29:46 +00:00
|
|
|
|
className="py-2 flex-grow bg-white dark:bg-gray-600 rounded-lg overflow-hidden">
|
2020-12-19 21:54:04 +00:00
|
|
|
|
<RPlot/>
|
2020-12-18 19:00:26 +00:00
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
2020-12-21 13:08:26 +00:00
|
|
|
|
{this.state.positions.length > 0 ?
|
|
|
|
|
<PositionsTable positions={this.state.positions}/> : null}
|
2020-12-19 16:17:48 +00:00
|
|
|
|
|
2020-12-19 17:27:46 +00:00
|
|
|
|
<footer className="flex rounded-lg justify-center bg-gray-600 mt-4 border-t text-gray-300">
|
|
|
|
|
<span className="my-1 mx-1">Made with ❤️ by the Peperone in a scantinato</span>
|
|
|
|
|
</footer>
|
2020-12-18 19:00:26 +00:00
|
|
|
|
</main>
|
2020-12-19 17:27:46 +00:00
|
|
|
|
|
|
|
|
|
<Sidebar/>
|
2020-12-18 19:00:26 +00:00
|
|
|
|
</div>
|
2020-12-18 14:02:53 +00:00
|
|
|
|
</div>
|
|
|
|
|
</>
|
2020-12-12 20:18:25 +00:00
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default App;
|