Skip to content

Commit

Permalink
general fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob Plaster committed Aug 2, 2019
1 parent 293d59b commit dc058e9
Show file tree
Hide file tree
Showing 36 changed files with 115 additions and 327 deletions.
4 changes: 2 additions & 2 deletions scripts/start-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const run = async () => {
secret: creds.secret,
})
})

app.post('/api-key', async (req, res) => {
const { key, secret } = req.body

Expand All @@ -103,7 +103,7 @@ const run = async () => {
secret,
})
} catch (error) {
console.log(error)
console.error(error)
return res.status(500).json({ error: error.message })
}
startHFServer()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { connect } from 'react-redux'

import TableActions from '../../redux/actions/table'
import AlgoOrderActions from '../../redux/actions/algo-orders'
import EditorActions from '../../redux/actions/editor'
import RestHfActions from '../../redux/actions/rest-hf-server'

import AlgoOrderDefinitionsTableView from './AlgoOrderDefinitionsTable'

const mapStateToProps = (state = {}) => {
const { algoOrders = [], orders = [] } = state.table
const { algoOrders = [], orders = [] } = state.algoOrders
const { editorOpened = false } = state.editor
return {
algoOrders,
Expand All @@ -18,13 +17,13 @@ const mapStateToProps = (state = {}) => {

const mapDispatchToProps = dispatch => ({
changeStatus: (index) => {
dispatch(TableActions.changeStatus(index))
dispatch(AlgoOrderActions.changeStatus(index))
},
toggleEditor: (flag) => {
dispatch(EditorActions.toggleEditor(flag))
},
stopOrder: (gId) => {
dispatch(RestHfActions.stopAlgoOrder(gId))
dispatch(AlgoOrderActions.stopOrder(gId))
},
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default class AlgoOrderTable extends React.Component {
const newAlgoOrders = nextProps.algoOrders
const newOrders = nextProps.orders
const { algoOrders, orders } = this.props
if (orders.length !== newOrders.length) {
if (orders !== newOrders) {
return true
}
if (newAlgoOrders.length !== algoOrders.length) {
Expand All @@ -35,7 +35,7 @@ export default class AlgoOrderTable extends React.Component {

render() {
const { orders, stopOrder } = this.props
const orderObjects = orders.map((ao) => {
const orderObjects = orders.reverse().map((ao) => {
const isActive = !!ao[2]
let status = <p>Inactive</p>
if (isActive) {
Expand Down
6 changes: 3 additions & 3 deletions src/components/AlgoOrderTable/AlgoOrderTable.container.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { connect } from 'react-redux'
import { withRouter } from 'react-router-dom'

import TableActions from '../../redux/actions/table'
import AlgoOrderActions from '../../redux/actions/algo-orders'
import EditorActions from '../../redux/actions/editor'

import AlgoOrderTableView from './AlgoOrderTable'

const mapStateToProps = (state = {}, ownProps = {}) => {
const { orders = [] } = ownProps
const { algoOrders = [] } = state.table
const { algoOrders = [] } = state.algoOrders
const { editorOpened = false } = state.editor
return {
algoOrders,
Expand All @@ -19,7 +19,7 @@ const mapStateToProps = (state = {}, ownProps = {}) => {

const mapDispatchToProps = dispatch => ({
changeStatus: (index) => {
dispatch(TableActions.changeStatus(index))
dispatch(AlgoOrderActions.changeStatus(index))
},
toggleEditor: (flag) => {
dispatch(EditorActions.toggleEditor(flag))
Expand Down
2 changes: 1 addition & 1 deletion src/components/HFUI/HFUI.container.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { connect } from 'react-redux'
import { withRouter } from 'react-router-dom'
import APIKeyActions from '../../redux/actions/apiKey'
import APIKeyActions from '../../redux/actions/api-key'
import WSHFActions from '../../redux/actions/ws-hf-server'
import HFUI from './HFUI'

Expand Down
1 change: 1 addition & 0 deletions src/components/HFUI/_HFUI.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
flex-direction: row;
}


.hfui_view__wrapper {
padding: 0 32px;
display: flex;
Expand Down
1 change: 0 additions & 1 deletion src/components/PLChart/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ class PLChart extends React.PureComponent {
if (_isEmpty(data)) {
return null
}
console.log('%c ChartData: ', 'color:white;background:blue;', data)

const start = xAccessor(data[Math.max(0, data.length - 1000)])
const end = xAccessor(_last(data))
Expand Down
15 changes: 8 additions & 7 deletions src/pages/AlgoOrders/AlgoOrders.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ export default class AlgoOrdersView extends React.Component {
return (
<div className='hfui_view__wrapper'>
<h1>Algo Orders</h1>
<AlgoOrderTable
algoOrders={algoOrders}
/>
{/* <AlgoOrderForm /> */}
<AlgoOrderDefinitions
algoOrders={algoOrders}
/>
<div className='hfui_content__wrapper'>
<AlgoOrderTable
algoOrders={algoOrders}
/>
<AlgoOrderDefinitions
algoOrders={algoOrders}
/>
</div>
</div>
)
}
Expand Down
3 changes: 1 addition & 2 deletions src/pages/Settings/Settings.container.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { connect } from 'react-redux'
import SettingsView from './SettingsView'
import APIKeyActions from '../../redux/actions/apiKey'
import APIKeyActions from '../../redux/actions/api-key'
import WSHFActions from '../../redux/actions/ws-hf-server'

const mapStateToProps = (state = {}, ownProps = {}) => {
const { dataHF = {} } = state
const { apiKey = {} } = dataHF
const { key, secret } = apiKey
console.log(apiKey)


return {
Expand Down
30 changes: 17 additions & 13 deletions src/pages/Settings/SettingsView.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,28 @@ import APIComboDialog from '../../components/APIComboDialogMenu'

export default class SettingsView extends React.Component {

constructor(props) {
super(props)
this.onSubmitKeys = this.onSubmitKeys.bind(this)
}
onSubmitKeys({ key, secret } = {}) {
const { updateAPIKey, cycleBFXConnection } = this.props
updateAPIKey({ key, secret })
}
constructor(props) {
super(props)
this.onSubmitKeys = this.onSubmitKeys.bind(this)
}

onSubmitKeys({ key, secret } = {}) {
const { updateAPIKey, cycleBFXConnection } = this.props
updateAPIKey({ key, secret })
}

render() {
const { apiKey } = this.props
const { key, secret } = apiKey
console.log(this.props)
return (
<div className='hfui_view__wrapper'>
<h1>Settings</h1>
<Settings />
<APIComboDialog onSubmit={this.onSubmitKeys} />
<div style={{ flex: 1, display: 'flex', flexDirection: 'row' }}>
<div className='hfui_sidenavbar' style={{ backgroundColor: 'rgba(27,38,45,0.95)' }}>
<div style={{ marginTop: '90px' }} />
<Settings />
</div>
<div style={{ flex: 1, marginTop: '90px'}}>
<APIComboDialog onSubmit={this.onSubmitKeys} />
</div>
</div>
)
}
Expand Down
58 changes: 58 additions & 0 deletions src/redux/actions/algo-orders.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import axios from 'axios'
import HfServerConsts from '../constants/rest-hf-server'

const stopOrder = (gId) => {
return (dispatch) => {
return axios.get(`${HfServerConsts.HOST}/v1/orders/${gId}/stop`)
.then((response) => {
// success
dispatch({
type: 'RECEIVE_ORDERS',
payload: Object.values(response.data).map((v) => {
return [
v.gid,
v.algoID,
v.active,
v.state,
]
}),
})
})
.catch((error) => {
// failed
console.error(error)
})
.finally(() => {
dispatch({ type: 'RECEIVE_ORDERS_DONE' })
})
}
}

function changeStatus(index) {
return {
type: 'CHANGE_STATUS',
index,
}
}

function getAlgoData() {
return {
type: 'GET_ALGO_DATA',
}
}

function receiveAlgoData() {
return {
type: 'RECEIVE_ALGO_DATA',
payload: {
data: [],
},
}
}

export default {
stopOrder,
changeStatus,
getAlgoData,
receiveAlgoData,
}
File renamed without changes.
17 changes: 0 additions & 17 deletions src/redux/actions/rest-hf-server.js

This file was deleted.

27 changes: 0 additions & 27 deletions src/redux/actions/table.js

This file was deleted.

1 change: 0 additions & 1 deletion src/redux/actions/ws-hf-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ export default {
*/
recvBitfinex: (msg = []) => {
const payload = msg[1]
console.log(msg)
if (_isObject(payload) && payload.event) {
switch (payload.event) {
/*
Expand Down
4 changes: 0 additions & 4 deletions src/redux/adapters/bts.js

This file was deleted.

4 changes: 0 additions & 4 deletions src/redux/adapters/candles.js

This file was deleted.

5 changes: 0 additions & 5 deletions src/redux/adapters/trades.js

This file was deleted.

3 changes: 3 additions & 0 deletions src/redux/constants/rest-hf-server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
HOST: 'http://localhost:7799',
}
4 changes: 3 additions & 1 deletion src/redux/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createStore, applyMiddleware, compose } from 'redux'
import createSagaMiddleware from 'redux-saga'
import thunk from 'redux-thunk';

import reducer from './reducers'
import constants from './constants'
Expand All @@ -20,6 +21,7 @@ export function configureStore(

let middleware = [
hfSocketMiddleware(),
thunk,
sagaMiddleware,
]

Expand Down Expand Up @@ -49,7 +51,7 @@ export function configureStore(
}

export function runSaga() {
console.log('%c runSaga is deprecated: it is already run in configureStore', 'color:white;background:orange;')
console.error('%c runSaga is deprecated: it is already run in configureStore', 'color:white;background:orange;')
}

export default {
Expand Down
1 change: 0 additions & 1 deletion src/redux/middleware/ws-data-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ const socketMiddleware = () => {
}

const [msg] = payload
console.log(JSON.stringify(action))
switch (msg) {
case 'error': {
console.error('[wss] error ', payload)
Expand Down
1 change: 0 additions & 1 deletion src/redux/middleware/ws-hf-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export default () => {
}

const { type, payload = {} } = action
console.log(JSON.stringify(action))
switch (type) {
case WSHFTypes.CONNECT: {
if (socket !== null) {
Expand Down
1 change: 0 additions & 1 deletion src/redux/middleware/ws-hf/on_message.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export default (ws, store) => (e = {}) => {
}

const [scope, msg] = payload
console.log(JSON.stringify(e))
switch (scope) {
case 'error': {
console.error('[wss] error ', payload)
Expand Down
Loading

0 comments on commit dc058e9

Please sign in to comment.