Skip to content

Commit

Permalink
initial reserve funds and redoing the settings page
Browse files Browse the repository at this point in the history
** This branch does not compile in webpack
  • Loading branch information
coltoneshaw committed Aug 4, 2021
1 parent 9880ba5 commit 9f3de74
Show file tree
Hide file tree
Showing 22 changed files with 657 additions and 254 deletions.
85 changes: 85 additions & 0 deletions 3Commas_API_Docs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Accound Endpoints

## Balance Chart Data
Endpoint - `GET /public/api/ver1/accounts/{account_id}/balance_chart_data`
Notes:

Response:
```json
[
{
date: 1619308800, // Epoch date in seconds
usd: 147.76,
btc: 0.002991,
btc_deposit_amount: 0, // The deposit metrics only get updated when you deposit through 3commas
usd_deposit_amount: 0 //
},
...
{
date: 1627862400,
usd: 15634.38,
btc: 0.401757,
btc_deposit_amount: 0,
usd_deposit_amount: 0
}
]
```



Response:

```json
[
{
id: 30035777,
auto_balance_period: 12,
auto_balance_portfolio_id: null,
auto_balance_currency_change_limit: null,
autobalance_enabled: false,
is_locked: false,
smart_trading_supported: true,
smart_selling_supported: true,
available_for_trading: {},
stats_supported: true,
trading_supported: true,
market_buy_supported: true,
market_sell_supported: true,
conditional_buy_supported: true,
bots_allowed: true,
bots_ttp_allowed: true,
bots_tsl_allowed: false,
gordon_bots_available: true,
multi_bots_allowed: true,
created_at: '2021-04-25T10:44:25.648Z',
updated_at: '2021-06-22T04:46:28.128Z',
last_auto_balance: null,
fast_convert_available: true,
grid_bots_allowed: true,
api_key_invalid: false,
nomics_id: 'binance_us',
market_icon: 'https://3commas.io/img/exchanges/binance.png',
supported_market_types: [ 'spot' ],
api_key: 'OVnLHUyXmMiiXT2fQXDkWyYqlOnkC3er3rd3xAC7AKLCWP5Fnom0kYG9ewtNCCoO',
name: 'Binance US',
auto_balance_method: 'time',
auto_balance_error: null,
lock_reason: null,
btc_amount: '0.40997708013273871104906805092618080738584', // total funds converted to BTC as of the current day's close.
usd_amount: '15583.4994007182860145243690006177437680686530544', // total funds available in USD
day_profit_btc: '0.001122175123597340587318102804499239978062',
day_profit_usd: '-24.8593853526494418137533084188808801097469456', // portfolio balance 30 days ago compared with today divided by 30.
day_profit_btc_percentage: '0.02',
day_profit_usd_percentage: '-0.14',
btc_profit: '-0.01083926501132428895093194907381919261416', // trailing 30 day profit
usd_profit: '629.9757352158860145243690006177437680686530544', // trailing 30 day profit
usd_profit_percentage: '4.21',
btc_profit_percentage: '-2.58',
total_btc_profit: '0.4069863069789086',
total_usd_profit: '15435.739595083216', // this appears to count every dollar deposited as profit.
pretty_display_type: 'BinanceUs',
exchange_name: 'Binance US',
market_code: 'binance_us'
}
]
```
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"build": "webpack && electron-builder --dir && electron-builder --mac --win --linux",
"react:dev": "webpack serve --mode=development",
"electron:dev": "nodemon",
"webpack" : "webpack",
"dev": "concurrently --kill-others \"npm run react:dev\" \"npm run electron:dev\"",
"start": "npm run build && electron dist/main.js",
"rebuild": "./node_modules/.bin/electron-rebuild -f -w better-sqlite3"
Expand Down
7 changes: 4 additions & 3 deletions src/app/Components/MainWindow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { DataProvider } from '../Context/DataContext';
import ToastNotifcation from '@/app/Components/ToastNotification'


const MainWindow = (props: { classes: object }) => {
const MainWindow = () => {

const configState = useGlobalState()
const { state: { apiData }, config } = configState;
Expand All @@ -33,11 +33,12 @@ const MainWindow = (props: { classes: object }) => {
</Route>

<DataProvider>
<Route exact path="/botplanner" render={() => <BotPlannerPage classes={props.classes} />} />
<Route exact path="/botplanner" render={() => <BotPlannerPage />} />
<Route exact path="/stats" render={() => <StatsPage />} />
<Route exact path="/settings" render={() => <SettingsPage />} />

</DataProvider>

<Route exact path="/settings" render={() => <SettingsPage />} />
<Route exact path="/donate" render={() => <DonatePage />} />
<Route exact path="/backtesting" render={() => <TradingViewPage />} />

Expand Down
3 changes: 1 addition & 2 deletions src/app/Components/Pages/BotPlanner/BotPlanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { calc_dropMetrics } from '@/utils/formulas'

import { Type_Query_bots } from '@/types/3Commas';

const BotPlannerPage = ({ classes }: { classes: object }) => {
const BotPlannerPage = () => {

const state = useGlobalData();
const { actions: { fetchBotData, updateAllData }, data: { botData, isSyncing, metricsData: { totalBankroll } } } = state;
Expand Down Expand Up @@ -179,7 +179,6 @@ const BotPlannerPage = ({ classes }: { classes: object }) => {
add row
</Button>
<DataTable
classes={classes}
localBotData={localBotData}
updateLocalBotData={updateLocalBotData}
/>
Expand Down
14 changes: 10 additions & 4 deletions src/app/Components/Pages/BotPlanner/DataTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { calc_deviation, calc_DealMaxFunds_bot, calc_maxInactiveFunds, calc_maxB

import { Type_Query_bots } from '@/types/3Commas'

import { MuiClassObject } from '@/app/Context/MuiClassObject'


/**
* TODO
Expand All @@ -18,12 +20,12 @@ import { Type_Query_bots } from '@/types/3Commas'

interface Type_DataTable {
localBotData: Type_Query_bots[]
classes: any
updateLocalBotData: any
}
const DataTable = ({ classes, localBotData, updateLocalBotData }:Type_DataTable) => {
const DataTable = ({ localBotData, updateLocalBotData }:Type_DataTable) => {

const state = useGlobalData()
const classes = MuiClassObject()


// TODO - This needs to be fixed when the other data from this is fixed.
Expand Down Expand Up @@ -64,6 +66,7 @@ const DataTable = ({ classes, localBotData, updateLocalBotData }:Type_DataTable)
}

const handleEditCellChangeCommitted = (e: any) => {
console.log(e)

/**
* 1. Identify the row that was updated (e) and the value, then update it.
Expand All @@ -72,6 +75,7 @@ const DataTable = ({ classes, localBotData, updateLocalBotData }:Type_DataTable)
*/

updateLocalBotData((prevState: Type_Query_bots[]) => {

const newRows = prevState.map(row => {
if (e.id == row.id) {

Expand Down Expand Up @@ -160,16 +164,18 @@ const DataTable = ({ classes, localBotData, updateLocalBotData }:Type_DataTable)
<div style={{ display: 'flex', overflow: "visible" }} className="boxData">
<div className="dataTable" >
<DataGrid
onEditCellChangeCommitted={handleEditCellChangeCommitted}
className={classes.root}
hideFooter={true}
rows={localBotData}

style={{minWidth: "1500px"}}
// @ts-ignore
columns={columns}
disableColumnFilter
disableColumnSelector
disableColumnMenu
onEditCellChangeCommitted={handleEditCellChangeCommitted}
// onCellEditCommit={handleEditCellChangeCommitted}

/>
</div>
</div>
Expand Down
136 changes: 136 additions & 0 deletions src/app/Components/Pages/Settings/Components/AccountDropdown.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
// import React, { useState, useEffect } from 'react';

// import {
// FormControl,
// InputLabel,
// MenuItem,
// Select
// } from '@material-ui/core';

// import Checkbox from '@material-ui/core/Checkbox';
// import ListItemText from '@material-ui/core/ListItemText';
// import Input from '@material-ui/core/Input';

// import { accountDataAll } from '@/utils/3Commas';
// import { useGlobalState } from '@/app/Context/Config';
// import { defaultConfig, findConfigData } from '@/utils/defaultConfig';
// import { Type_Query_Accounts } from '@/types/3Commas'


// const accountIdPath = 'statSettings.account_id'

// // initializing a state for each of the two props that we are using.
// const ITEM_HEIGHT = 48;
// const ITEM_PADDING_TOP = 8;
// const MenuProps = {
// PaperProps: {
// style: {
// maxHeight: ITEM_HEIGHT * 4.5 + ITEM_PADDING_TOP,
// width: 250,
// },
// },
// };

// const noAccount = [{
// currency_code: "USD",
// id: 0,
// account_id: 0,
// account_name: "no account",
// exchange_name: "blank",
// percentage: 0,
// position: 0,
// on_orders: 0,
// btc_value: 0,
// usd_value: 0,
// market_code: 0
// }]



// const AccountDropdown = ( ) => {
// const state = useGlobalState()
// const { config, state: { accountID, updateAccountID } } = state;


// /**
// * TODO
// * - Move this into the config element and pass it down, or pull from the data element.
// */
// const [accountData, changeAccountData] = useState<Type_Query_Accounts[]>( () => noAccount )
// const [select, selectElement] = useState<any[] | undefined>([])

// // @ts-ignore
// useEffect(() => {
// let mounted = true
// accountDataAll()
// .then((data: Type_Query_Accounts[]) => {
// if (mounted) {
// // removing duplicate accounts
// const filteredAccounts = Array.from(new Set(data.map(a => a.account_id))).map(id => data.find(a => a.account_id === id))

// // @ts-ignore
// changeAccountData(filteredAccounts)

// }
// })
// return () => mounted = false
// }, [])

// useEffect(() => {
// // @ts-ignore
// let findAccounts: array[] = findConfigData(config, accountIdPath);
// findAccounts = (findAccounts) ? findAccounts : []
// selectElement(findAccounts)
// }, [config])

// const returnAccountNames = (accountData: Type_Query_Accounts[], accountIdArray: number[]) => {
// return accountData.filter(e => accountIdArray.includes(e.account_id)).map(e => e.account_name).join(', ')
// }

// // const [select, selectElement] = useState(() => accountID)


// // changing the select value
// const handleChange = (event:any ) => {
// updateAccountID(event.target.value)
// selectElement(event.target.value)
// console.log(event.target.value)
// };


// return (
// <FormControl style={{width: "100%"}}>
// <InputLabel>Account Filter</InputLabel>


// <Select
// multiple
// value={select}
// onChange={handleChange}
// input={<Input />}
// // @ts-ignore
// renderValue={() => (accountData.length > 0) ? returnAccountNames(accountData, select) : ""}
// MenuProps={MenuProps}
// >
// {/* Need to think through All because it's now a selector. */}
// {/* <MenuItem value=""></MenuItem> */}

// {/* @ts-ignore */}
// {accountData.map((account) => (
// <MenuItem key={account.account_id} value={account.account_id}>

// {/* @ts-ignore */}

// <Checkbox checked={select.indexOf(account.account_id) > -1} />
// <ListItemText primary={account.account_name} />
// </MenuItem>
// ))}
// </Select>
// </FormControl>
// )



// }

// export default AccountDropdown
Loading

0 comments on commit 9f3de74

Please sign in to comment.