-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
250 additions
and
82 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import axios from 'axios'; | ||
const API_URL = 'https://cors-anywhere.herokuapp.com/http://3.93.232.78:7011'; | ||
|
||
const instance = axios.create({ | ||
baseURL: API_URL, | ||
timeout: 1000, | ||
headers: {'X-LiskDexUI-Version': '0.1'} | ||
}); | ||
|
||
export async function getOrderbook() { | ||
const orders = await instance.get('/orders?sort=price:asc'); | ||
return orders; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.askOrderList { | ||
display: flex; | ||
align-items: flex-start; | ||
flex-direction: column-reverse; | ||
height: 100%; | ||
} | ||
|
||
.bidOrderList { | ||
display: flex; | ||
align-items: flex-start; | ||
flex-direction: column; | ||
height: 100%; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,77 @@ | ||
import React from "react"; | ||
import SingleOrder from "./SingleOrder"; | ||
import { getOrderbook } from "./API"; | ||
import "./Orderbook.css"; | ||
|
||
class Orderbook extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { orders: [] }; | ||
/* | ||
export default class Orderbook extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { orders: [], bids: [], asks: [], maxSize: { bid: 0, ask: 0 } }; | ||
/* | ||
Schema of the orders element: | ||
{ | ||
amount: size of the order | ||
price: price at which the order is | ||
} | ||
Orders at the same price will be merged. | ||
*/ | ||
*/ | ||
} | ||
|
||
refreshOrderbook() { | ||
getOrderbook().then(results => { | ||
const bids = []; | ||
const asks = []; | ||
let maxSize = { bid: 0, ask: 0 }; | ||
for (let result of results.data) { | ||
if (result.side === "bid") { | ||
bids.push(result); | ||
if (result.size > maxSize.bid) { | ||
maxSize.bid = result.size; | ||
} | ||
} else if (result.side === "ask") { | ||
asks.push(result); | ||
if (result.size > maxSize.ask) { | ||
maxSize.ask = result.size; | ||
} | ||
} | ||
} | ||
this.setState({ bids, asks, maxSize }); | ||
}); | ||
} | ||
|
||
componentDidMount() { | ||
this.refreshOrderbook(); | ||
} | ||
|
||
render() { | ||
if (this.props.side === "asks") { | ||
const orders = this.state.asks.map(order => ( | ||
<SingleOrder | ||
whole={Math.pow(10, 8)} // 10 ** 8 beddow in one LSK | ||
key={order.orderId} | ||
size={order.size} | ||
price={order.price} | ||
maxSize={this.state.maxSize} | ||
side={this.props.side} | ||
decimals={4} | ||
></SingleOrder> | ||
)); | ||
return <div className="askOrderList">{orders}</div>; | ||
} | ||
|
||
componentDidMount() {} | ||
|
||
render() { | ||
return ( | ||
<> | ||
<div className="top-bar"> | ||
<div className="top-bar-right"> | ||
<b>Lisk DEX</b> | ||
</div> | ||
<div className="top-bar-left"> | ||
API Status: <span style={{ color: "green" }}>Connected</span> | ||
</div> | ||
</div> | ||
<div className="container"> | ||
<div className="buy-panel">BUY</div> | ||
<div className="sell-panel">SELL</div> | ||
<div className="buy-orders"> | ||
ORDERS TO BUY | ||
<br></br> | ||
increasing price top to bottom | ||
</div> | ||
<div className="sell-orders"> | ||
ORDERS TO SELL | ||
<br></br> | ||
decreasing price top to bottom | ||
</div> | ||
<div className="depth-chart">DEPTH CHART / LINES</div> | ||
<div className="your-orders">YOUR ORDERS</div> | ||
<div className="market-name-and-stats"> | ||
MRCL/LSK (current market name) | ||
<br></br> | ||
<br></br> | ||
list of other markets | ||
<br></br> | ||
<br></br> | ||
<br></br> | ||
ect | ||
</div> | ||
</div> | ||
</> | ||
); | ||
if (this.props.side === "bids") { | ||
const orders = this.state.bids.map(order => ( | ||
<SingleOrder | ||
whole={Math.pow(10, 8)} // 10 ** 8 beddow in one LSK | ||
key={order.orderId} | ||
size={order.size} | ||
price={order.price} | ||
maxSize={this.state.maxSize} | ||
side={this.props.side} | ||
decimals={4} | ||
></SingleOrder> | ||
)); | ||
return <div className="bidOrderList">{orders}</div>; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.orderLine { | ||
width: 100%; | ||
border: 1px solid white; | ||
box-sizing: border-box; | ||
margin-top: 2px; | ||
margin-bottom: 2px; | ||
padding: 3px; | ||
background: linear-gradient(to right, #700d0d 70%, rgba(0,0,0,0) 30%); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React from "react"; | ||
import "./SingleOrder.css"; | ||
|
||
export default class SingleOrder extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = {}; | ||
} | ||
|
||
bgCSS() { | ||
if (this.props.side === "asks") { | ||
const percentOfMaxSize = (this.props.size / this.props.maxSize.ask) * 100; | ||
return `linear-gradient(to right, #700d0d ${percentOfMaxSize}%, rgba(0,0,0,0) 1%)`; | ||
} | ||
if (this.props.side === "bids") { | ||
const percentOfMaxSize = (this.props.size / this.props.maxSize.bid) * 100; | ||
return `linear-gradient(to right, #286113 ${percentOfMaxSize}%, rgba(0,0,0,0) 1%)`; | ||
} | ||
} | ||
|
||
render() { | ||
return ( | ||
<div style={{ background: this.bgCSS() }} className="orderLine"> | ||
{this.props.price}, {(this.props.size / this.props.whole).toFixed(this.props.decimals)} | ||
</div> | ||
); | ||
} | ||
} |