-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from justinkx/development
Trades
- Loading branch information
Showing
18 changed files
with
334 additions
and
45 deletions.
There are no files selected for viewing
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
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,67 @@ | ||
import React, { memo } from "react"; | ||
import { StyleSheet, Text, View } from "react-native"; | ||
import { format } from "date-fns"; | ||
|
||
import { colors } from "../../style/GlobalStyle"; | ||
import { fixedDecimals } from "../../helpers/number.helpers"; | ||
|
||
const Trades = ({ trade }) => { | ||
const { price, quantity, tradeTime, isMarketOrder } = trade; | ||
return ( | ||
<View | ||
style={[ | ||
styles.row, | ||
isMarketOrder ? styles.bidBackground : styles.askBackground, | ||
]} | ||
> | ||
<View style={styles.contentView}> | ||
<Text style={[styles.value, isMarketOrder ? styles.bid : styles.ask]}> | ||
{`${isMarketOrder ? "\u2191" : "\u2193"} ${price}`} | ||
</Text> | ||
</View> | ||
<View style={[styles.contentView, styles.alignEnd]}> | ||
<Text style={styles.value}>{fixedDecimals(quantity, 3)}</Text> | ||
</View> | ||
<View style={[styles.contentView, styles.alignEnd]}> | ||
<Text style={styles.value}>{format(tradeTime, "H:mm:ss")}</Text> | ||
</View> | ||
</View> | ||
); | ||
}; | ||
|
||
export default memo(Trades); | ||
|
||
const styles = StyleSheet.create({ | ||
row: { | ||
flexDirection: "row", | ||
width: "100%", | ||
justifyContent: "space-between", | ||
alignItems: "center", | ||
height: 30, | ||
paddingHorizontal: 10, | ||
borderBottomWidth: StyleSheet.hairlineWidth, | ||
borderBottomColor: colors.white, | ||
}, | ||
bidBackground: { | ||
backgroundColor: colors.bidBackground, | ||
}, | ||
askBackground: { | ||
backgroundColor: colors.askBackground, | ||
}, | ||
contentView: { width: "30%" }, | ||
value: { | ||
fontSize: 13, | ||
fontWeight: "bold", | ||
color: "#474d57", | ||
}, | ||
|
||
alignEnd: { | ||
alignItems: "flex-end", | ||
}, | ||
bid: { | ||
color: colors.tradeGreen, | ||
}, | ||
ask: { | ||
color: colors.tradeRed, | ||
}, | ||
}); |
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,2 @@ | ||
export const fixedDecimals = (value, decimalPlaces = 2) => | ||
parseFloat(value).toFixed(decimalPlaces); |
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,11 @@ | ||
import { | ||
INITIALIZE_TRADES_CHANNEL, | ||
SAVE_TRADES, | ||
RESET_TRADES_CHANNEL, | ||
} from "./types"; | ||
|
||
export const initializeChannel = () => ({ type: INITIALIZE_TRADES_CHANNEL }); | ||
|
||
export const saveTrades = (trades) => ({ type: SAVE_TRADES, trades }); | ||
|
||
export const resetTradesChannel = () => ({ type: RESET_TRADES_CHANNEL }); |
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,59 @@ | ||
export const tradesAdaptor = (data) => { | ||
const { | ||
e: eventType, // Event type | ||
E: eventTime, // Event time | ||
s: symbol, // Symbol | ||
t: tradeId, // Trade ID | ||
p: price, // Price | ||
q: quantity, // Quantity | ||
b: buyerOrderId, // Buyer order ID | ||
a: sellerOrderId, // Seller order ID | ||
T: tradeTime, // Trade time | ||
m: isMarketOrder, // Is the buyer the market maker? | ||
M: ignore, // Ignore | ||
} = data; | ||
return { | ||
eventType, | ||
eventTime, | ||
symbol, | ||
tradeId, | ||
price, | ||
quantity, | ||
buyerOrderId, | ||
sellerOrderId, | ||
tradeTime, | ||
isMarketOrder, | ||
ignore, | ||
}; | ||
}; | ||
|
||
export const transformedTrade = (data) => { | ||
const { | ||
eventType, | ||
eventTime, | ||
symbol, | ||
tradeId, | ||
price, | ||
quantity, | ||
buyerOrderId, | ||
sellerOrderId, | ||
tradeTime, | ||
isMarketOrder, | ||
ignore, | ||
} = tradesAdaptor(data); | ||
return { | ||
[tradeTime]: { | ||
eventType, | ||
eventTime, | ||
symbol, | ||
tradeId, | ||
price, | ||
quantity, | ||
buyerOrderId, | ||
sellerOrderId, | ||
tradeTime, | ||
isMarketOrder, | ||
ignore, | ||
}, | ||
}; | ||
}; |
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,17 @@ | ||
import _assign from "lodash/assign"; | ||
|
||
import { SAVE_TRADES, RESET_TRADES_CHANNEL } from "../action/types"; | ||
|
||
const initialState = {}; | ||
|
||
export default function tradesReducer(state = initialState, action) { | ||
const { trades, type } = action; | ||
switch (type) { | ||
case SAVE_TRADES: | ||
return trades; | ||
case RESET_TRADES_CHANNEL: | ||
return initialState; | ||
default: | ||
return state; | ||
} | ||
} |
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
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,40 @@ | ||
import { put, takeLatest, select } from "redux-saga/effects"; | ||
import { send } from "@giantmachines/redux-websocket"; | ||
|
||
import { | ||
INITIALIZE_TRADES_CHANNEL, | ||
RESET_TRADES_CHANNEL, | ||
RESET_TICKER_PAIR, | ||
} from "../action/types"; | ||
import { getSelectedPair } from "../selectors/tickerPair.selector"; | ||
|
||
function* tradesListenerSaga() { | ||
const pair = yield select(getSelectedPair); | ||
if (pair) { | ||
yield put( | ||
send({ | ||
method: "SUBSCRIBE", | ||
params: [`${pair}@trade`], | ||
id: 10, | ||
}) | ||
); | ||
} | ||
} | ||
|
||
function* tradesResetSaga() { | ||
const pair = yield select(getSelectedPair); | ||
if (pair) { | ||
yield put( | ||
send({ | ||
method: "UNSUBSCRIBE", | ||
params: [`${pair}@trade`], | ||
id: 102, | ||
}) | ||
); | ||
} | ||
} | ||
|
||
export default function* tradesSaga() { | ||
yield takeLatest(INITIALIZE_TRADES_CHANNEL, tradesListenerSaga); | ||
yield takeLatest([RESET_TRADES_CHANNEL, RESET_TICKER_PAIR], tradesResetSaga); | ||
} |
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
Oops, something went wrong.