Skip to content
Snippets Groups Projects
Commit e9697612 authored by Quoc Huy Nguyen Dinh's avatar Quoc Huy Nguyen Dinh
Browse files

Fix internal market trade history rendering

parent 614eeecd
No related branches found
No related tags found
2 merge requests!142merge develop to master for new release,!141Fix market trade history
...@@ -13,8 +13,8 @@ import TransactionError from 'app/components/elements/TransactionError'; ...@@ -13,8 +13,8 @@ import TransactionError from 'app/components/elements/TransactionError';
import DepthChart from 'app/components/elements/DepthChart'; import DepthChart from 'app/components/elements/DepthChart';
import Orderbook from 'app/components/elements/Orderbook'; import Orderbook from 'app/components/elements/Orderbook';
import OrderHistory from 'app/components/elements/OrderHistory'; import OrderHistory from 'app/components/elements/OrderHistory';
import { Order } from 'app/utils/MarketOrder'; import { MarketOrder } from 'app/utils/MarketOrder';
import { TradeHistory } from 'app/utils/MarketTradeHistory'; import { MarketTradeHistory } from 'app/utils/MarketTradeHistory';
import { roundUp, roundDown } from 'app/utils/MarketUtils'; import { roundUp, roundDown } from 'app/utils/MarketUtils';
import tt from 'counterpart'; import tt from 'counterpart';
import { import {
...@@ -269,7 +269,7 @@ class Market extends React.Component { ...@@ -269,7 +269,7 @@ class Market extends React.Component {
if (typeof orders == 'undefined') return { bids: [], asks: [] }; if (typeof orders == 'undefined') return { bids: [], asks: [] };
return ['bids', 'asks'].reduce((out, side) => { return ['bids', 'asks'].reduce((out, side) => {
out[side] = orders[side].map((o) => { out[side] = orders[side].map((o) => {
return new Order(o, side); return new MarketOrder(o, side);
}); });
return out; return out;
}, {}); }, {});
...@@ -423,10 +423,11 @@ class Market extends React.Component { ...@@ -423,10 +423,11 @@ class Market extends React.Component {
if (!trades || !trades.length) { if (!trades || !trades.length) {
return []; return [];
} }
// eslint-disable-next-line no-shadow // eslint-disable-next-line no-shadow
const norm = (trades) => { const norm = (trades) => {
return trades.map((t) => { return trades.map((t) => {
return new TradeHistory(t); return new MarketTradeHistory(t);
}); });
}; };
......
...@@ -62,7 +62,7 @@ export default function reducer(state = defaultState, action = {}) { ...@@ -62,7 +62,7 @@ export default function reducer(state = defaultState, action = {}) {
return state.set('history', payload); return state.set('history', payload);
case APPEND_TRADE_HISTORY: case APPEND_TRADE_HISTORY:
return state.set('history', [...payload, ...state.get('history')]); return state.set('history', [...state.get('history'), ...payload]);
case TOGGLE_OPEN_ORDERS_SORT: case TOGGLE_OPEN_ORDERS_SORT:
const toggledColumn = action.payload.column || 'created'; const toggledColumn = action.payload.column || 'created';
......
...@@ -17,7 +17,6 @@ export const wait = (ms) => new Promise((resolve) => { ...@@ -17,7 +17,6 @@ export const wait = (ms) => new Promise((resolve) => {
}); });
let polling = false; let polling = false;
let last_trade = null;
export function* fetchMarket(location_change_action) { export function* fetchMarket(location_change_action) {
const { pathname } = location_change_action.payload; const { pathname } = location_change_action.payload;
...@@ -26,7 +25,7 @@ export function* fetchMarket(location_change_action) { ...@@ -26,7 +25,7 @@ export function* fetchMarket(location_change_action) {
return; return;
} }
if (polling == true) return; if (polling === true) return;
polling = true; polling = true;
while (polling) { while (polling) {
...@@ -34,26 +33,8 @@ export function* fetchMarket(location_change_action) { ...@@ -34,26 +33,8 @@ export function* fetchMarket(location_change_action) {
const state = yield call([api, api.getOrderBookAsync], 500); const state = yield call([api, api.getOrderBookAsync], 500);
yield put(marketActions.receiveOrderbook(state)); yield put(marketActions.receiveOrderbook(state));
let trades; const trades = yield call([api, api.getRecentTradesAsync], 1000);
if (last_trade == null) { yield put(marketActions.receiveTradeHistory(trades));
trades = yield call([api, api.getRecentTradesAsync], 25);
yield put(marketActions.receiveTradeHistory(trades));
} else {
const start = last_trade.toISOString().slice(0, -5);
trades = yield call(
[api, api.getTradeHistoryAsync],
start,
'1969-12-31T23:59:59',
1000
);
trades = trades.reverse();
yield put(marketActions.appendTradeHistory(trades));
}
if (trades.length > 0) {
last_trade = new Date(
new Date(Date.parse(trades[0].date)).getTime() + 1000
);
}
const state3 = yield call([api, api.getTickerAsync]); const state3 = yield call([api, api.getTickerAsync]);
yield put(marketActions.receiveTicker(state3)); yield put(marketActions.receiveTicker(state3));
......
...@@ -2,7 +2,7 @@ import { roundDown, roundUp } from './MarketUtils'; ...@@ -2,7 +2,7 @@ import { roundDown, roundUp } from './MarketUtils';
const precision = 1000; const precision = 1000;
export class Order { export class MarketOrder {
constructor(order, side) { constructor(order, side) {
this.side = side; this.side = side;
this.price = parseFloat(order.real_price); this.price = parseFloat(order.real_price);
...@@ -40,7 +40,7 @@ export class Order { ...@@ -40,7 +40,7 @@ export class Order {
} }
add(order) { add(order) {
return new Order( return new MarketOrder(
{ {
real_price: this.price, real_price: this.price,
hive: this.hive + order.hive, hive: this.hive + order.hive,
...@@ -60,4 +60,4 @@ export class Order { ...@@ -60,4 +60,4 @@ export class Order {
} }
} }
export default Order; export default MarketOrder;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment