Skip to content

Commit

Permalink
upgrade socket
Browse files Browse the repository at this point in the history
  • Loading branch information
WhidRubeld committed Sep 9, 2021
1 parent 9ba72f4 commit b8db0b8
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
10 changes: 9 additions & 1 deletion src/interfaces/ICandlestick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,23 @@ export interface ITick {
export enum TickResponseType {
add = 'add',
refresh = 'refresh',
update = 'update',
}

export interface TickResponseUpdate {
export interface TickResponseCreate {
type: TickResponseType.add
pair: IPair
interval: _interval
tick: ITick
}

export interface TickResponseUpdate {
type: TickResponseType.update
pair: IPair
interval: _interval
tick: ITick
}

export interface TickResponseInitial {
type: TickResponseType.refresh
pair: IPair
Expand Down
1 change: 1 addition & 0 deletions src/interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ export {
_interval,
TickResponseType,
TickResponseInitial,
TickResponseCreate,
TickResponseUpdate,
} from './ICandlestick'
4 changes: 2 additions & 2 deletions src/screens/Stats/extra/InfoTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default function InfoTable() {
fontWeight: 'bold',
}}
>
{v.force !== null ? `${v.force.toFixed(3)}` : '-'}
{v.force !== null ? `${v.force.toFixed(5)}` : '-'}
</Text>
</DataTable.Cell>
</DataTable.Row>
Expand Down Expand Up @@ -83,7 +83,7 @@ export default function InfoTable() {
fontWeight: 'bold',
}}
>
{v.force !== null ? `${v.force.toFixed(3)}` : '-'}
{v.force !== null ? `${v.force.toFixed(5)}` : '-'}
</Text>
</DataTable.Cell>
</DataTable.Row>
Expand Down
21 changes: 19 additions & 2 deletions src/store/ticks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
IPair,
ITick,
TickResponseCreate,
TickResponseInitial,
TickResponseType,
TickResponseUpdate,
Expand Down Expand Up @@ -31,7 +32,11 @@ export const tickSlice = createSlice({
},
setResponse(
state,
{ payload }: { payload: TickResponseInitial | TickResponseUpdate }
{
payload,
}: {
payload: TickResponseInitial | TickResponseUpdate | TickResponseCreate
}
) {
const { type } = payload
if (type === TickResponseType.refresh) {
Expand All @@ -52,13 +57,25 @@ export const tickSlice = createSlice({
results: [{ interval, ticks }],
})
}
} else {
} else if (type === TickResponseType.add) {
const { interval, pair, tick } = payload
const data = state.data.find((v) => v.pair.symbol === pair.symbol)
if (data) {
const results = data.results.find((v) => v.interval === interval)
if (results) results.ticks.unshift(tick)
}
} else if (type === TickResponseType.update) {
const { interval, pair, tick } = payload
const data = state.data.find((v) => v.pair.symbol === pair.symbol)
if (data) {
const results = data.results.find((v) => v.interval === interval)
if (results) {
const index = results.ticks.findIndex(
(v) => v.closeTime === tick.closeTime
)
if (index !== -1) results.ticks[index] = tick
}
}
}
},
},
Expand Down

0 comments on commit b8db0b8

Please sign in to comment.