Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const numberValue = stringValue ? Number(numbro.unformat(stringValue)) : 0;
// default to 0 if defaultValue is NaN
if (is.number(numberValue) && !is.empty(stringValue)) {
let newValue = numberValue;
if (key === 'ArrowDown') {
newValue = Number(numbro(numberValue).subtract(props.step).format({ mantissa: countDecimals(props.step) }));
if (greaterThanMin(newValue) && lessThanMax(newValue)) {
const updateError = displayErrorMessage(!is.empty(stringValue) ? newValue : '');
context.updateState({ value: toCurrency(newValue, countDecimals(props.step)), ...updateError }, () => {
if (is.fn(props.onChange)) {
props.onChange(newValue, props.id, type, key);
}
});
}
} else if (key === 'ArrowUp') {
newValue = Number(numbro(numberValue).add(props.step).format({ mantissa: countDecimals(props.step) }));
if (greaterThanMin(newValue) && lessThanMax(newValue)) {
const updateError = displayErrorMessage(!is.empty(stringValue) ? newValue : '');
context.updateState({ value: toCurrency(newValue, countDecimals(props.step)), ...updateError }, () => {
if (is.fn(props.onChange)) {
props.onChange(newValue, props.id, type, key);
}
});
}
}
}
};
.value()
// prettier-ignore
const deposit = this.conf.deposit
// @ts-ignore
? Math.max(0, n(this.conf.deposit).subtract(this.s.asset_capital))
: this.balance.currency // zero on negative
this.balance.deposit = n(deposit < this.balance.currency ? deposit : this.balance.currency).value()
if (!this.s.start_capital) {
this.s.start_price = n(quote.ask).value()
this.s.start_capital = n(this.balance.deposit)
.add(this.s.asset_capital)
.value()
this.s.real_capital = n(this.balance.currency)
.add(this.s.asset_capital)
.value()
this.s.net_currency = this.balance.deposit
if (this.conf.mode !== 'sim') {
this.pushMessage(
'Balance ' + this.exchange.name.toUpperCase(),
'sync balance ' + this.s.real_capital + ' ' + this.selector.currency + '\n'
)
}
} else {
this.s.net_currency = n(this.s.net_currency)
.add(postCurrency)
.value()
}
dump(statsonly: boolean = false, dumpOnly: boolean = true) {
const tmp_balance = n(this.s.net_currency)
.add(n(this.s.period.close).multiply(this.s.balance.asset))
.format('0.00000000')
const profit = this.s.start_capital
? n(tmp_balance)
.subtract(this.s.start_capital)
.divide(this.s.start_capital)
: n(0)
const buy_hold = this.s.start_price
? n(this.s.period.close).multiply(n(this.s.start_capital).divide(this.s.start_price))
: n(tmp_balance)
const buy_hold_profit = this.s.start_capital
? n(buy_hold)
.subtract(this.s.start_capital)
.divide(this.s.start_capital)
: n(0)
const output_lines = []
// prettier-ignore
output_lines.push('last balance: ' + n(tmp_balance).format('0.00000000').yellow + ' (' + profit.format('0.00%') + ')')
// prettier-ignore
output_lines.push('buy hold: ' + buy_hold.format('0.00000000').yellow + ' (' + n(buy_hold_profit).format('0.00%') + ')')
// prettier-ignore
output_lines.push('vs. buy hold: ' + n(tmp_balance).subtract(buy_hold).divide(buy_hold).format('0.00%').yellow)
}
}
await this.syncBalance()
const on_hold =
type === 'buy'
? n(this.balance.deposit)
.subtract(this.balance.currency_hold || 0)
.value() <
n(order.price)
.multiply(order.remaining_size)
.value()
: n(this.balance.asset)
.subtract(this.balance.asset_hold || 0)
.value() < n(order.remaining_size).value()
if (!on_hold || this.balance.currency_hold <= 0) return ORDER_STATUS.CANCELED
debug.msg('funds on hold after cancel, waiting 5s')
return await asyncTimeout(() => this.checkHold(order, type), this.conf.wait_for_settlement)
}
' '
).cyan
)
cols.push(
z(
5,
n(s.period.divergent)
.format('0')
.substring(0, 7),
' '
).cyan
)
cols.push(
z(
2,
n(s.period._switch)
.format('0')
.substring(0, 2),
' '
).cyan
)
}
} else {
cols.push(' ')
}
return cols
},
const toValue = (value: string): VALUE_TYPE => {
if (!value) {
return null;
}
const unformatted = numbro().unformat(value);
return unformatted;
};
private formatNumberWithLocale = (n?: string | number): string | undefined => {
if (!!n && this.isSeparatorLastChar(String(n))) {
const numberString = String(n);
return `${numberString.slice(0, numberString.length - 1)},`;
}
if (Number(n) || n === 0) {
return numbro(n).format();
}
return !!n ? String(n) : undefined;
};
{this.props.delegations.sort((b, a) => (a.balance - b.balance)).map((d, i) => {
return
{numbro(d.shares).format("0,0")}
{new Coin(d.balance).stakeString()}
})}
constructor(props){
super(props);
if (Meteor.isServer){
let data = {}
if (this.props.chainStates.communityPool){
data.communityPool = this.props.chainStates.communityPool.map((pool,i) => {
return <span>{new Coin(pool.amount).stakeString('0,0.00')}</span>
})
data.inflation = numbro(this.props.chainStates.inflation).format("0.00%")
}
if (this.props.coinStats.usd){
data.price = this.props.coinStats.usd,
data.marketCap = numbro(this.props.coinStats.usd_market_cap).format("$0,0.00")
}
this.state = data;
}
else{
this.state = {
price: "-",
marketCap: "-",
inflation: 0,
communityPool: 0
}
}
}
onReport(s) {
const cols = []
if (typeof s.period.trend_hma === 'number') {
let color = 'grey'
if (s.period.trend_hma_rate > 0) {
color = 'green'
} else if (s.period.trend_hma_rate < 0) {
color = 'red'
}
cols.push(z(8, n(s.period.trend_hma).format('0.0000'), ' ')[color])
cols.push(z(6, n(s.period.trend_hma_rate).format('0.00'), ' ')[color])
}
return cols
},