Skip to content

Commit

Permalink
Merge pull request #145 from bogdantimes/dev
Browse files Browse the repository at this point in the history
v4.3.8/v4.3.9
  • Loading branch information
bogdantimes authored Mar 29, 2024
2 parents cdc1598 + d0307cd commit 5e677bc
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 40 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# v4.3.9

* Remove external balance check in Withdrawals logic to make it work for DryRun

# v4.3.8

* Minor fixes:
* Improve candidates strength accuracy.
* Mark top candidates (🛎️⏳).

# v4.3.7

* Minor fixes:
Expand Down
2 changes: 1 addition & 1 deletion apps-script/appsscript.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
{
"userSymbol": "TradingHelperLibrary",
"libraryId": "1HVyGwXDWhXhrJ53E_hc-uzV001f96XfA6dDuLXExYjEkg5r-NqZVtwo9",
"version": "50",
"version": "51",
"developmentMode": false
}
],
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "trading-helper",
"version": "4.3.7",
"version": "4.3.9",
"description": "",
"scripts": {
"glogin": "clasp login",
Expand Down
10 changes: 5 additions & 5 deletions src/gas/TradeManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export class TradeManager {
* @param cost amount of stable coins to pay for the coin
* @param join whether to allow adding more to the existing coin in the portfolio
*/
buy(coin: CoinName, cost?: number, join = true): void {
buy(coin: CoinName, cost: number, join = true): void {
this.#prepare();
const symbol = new ExchangeSymbol(coin, this.#config.StableCoin);
const price = this.#getPrices(symbol)?.currentPrice;
Expand Down Expand Up @@ -404,10 +404,10 @@ export class TradeManager {

#prepare(): void {
this.#initStableBalance();
this.#optimalInvestRatio = Math.max(
this.#config.BudgetSplitMin,
this.plugin.getOptimalInvestRatio(this.candidatesDao),
);
this.#optimalInvestRatio =
this.#config.BudgetSplitMin > 1
? this.#config.BudgetSplitMin
: this.plugin.getOptimalInvestRatio(this.candidatesDao);
this.#updateCanInvest();
}

Expand Down
24 changes: 7 additions & 17 deletions src/gas/WithdrawalsManager.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,23 @@
import { type IExchange } from "./IExchange";
import { Config } from "../lib";
import { type Statistics } from "./Statistics";
import { type ConfigDao } from "./dao/Config";

export class WithdrawalsManager {
constructor(
private readonly configDao: ConfigDao,
private readonly exchange: IExchange,
private readonly statistics: Statistics,
) {}
private readonly statistics: Statistics
) {
}

addWithdrawal(amount: number): { amount: number; balance: number } {
const addWithdrawalFn = (config) => {
const addWithdrawalFn = (config: Config) => {
// Check internal balance
if (amount > config.StableBalance) {
throw new Error(
`Withdrawal amount is greater than the current balance.`,
);
}

const balance = this.exchange.getBalance(config.StableCoin);

// Check external balance
if (amount > balance) {
throw new Error(
`Withdrawal amount is greater than the factual ${config.StableCoin} balance on the exchange: $${balance}.`,
`Withdrawal amount is greater than the current balance.`
);
}

// We can proceed adding withdraw.
config.StableBalance -= amount;
this.statistics.addWithdrawal(amount);
return config;
Expand All @@ -37,7 +27,7 @@ export class WithdrawalsManager {

return {
amount,
balance: latestConfig.StableBalance,
balance: latestConfig.StableBalance
};
}
}
16 changes: 9 additions & 7 deletions src/gas/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
type IStore,
Key,
MASK,
MIN_BUY,
prettyPrintTradeMemo,
StableUSDCoin,
StoreDeleteProp,
Expand Down Expand Up @@ -281,15 +282,20 @@ function getState(): AppState {
};
}

function buy(coin: CoinName, cost?: number): string {
function buy(coin: CoinName, cost: number): string {
return catchError(() => {
if (!coin) {
Log.info(`Specify a coin name, e.g. BTC`);
} else if (cost && !isFinite(+cost)) {
return Log.printInfos();
}

if (!isFinite(+cost) || +cost < MIN_BUY) {
Log.info(
`Specify the amount (available on the balance) you're willing to invest, e.g. 150`,
);
return Log.printInfos();
}

TradeManager.default().buy(coin.toUpperCase(), cost);
return Log.printInfos() || `In progress!`;
});
Expand Down Expand Up @@ -375,11 +381,7 @@ function addWithdrawal(amount: number): string {
if (!isFinite(+amount)) throw new Error(`Amount is not a number.`);

const configDao = new ConfigDao(DefaultStore);
const mgr = new WithdrawalsManager(
configDao,
new Binance(configDao),
new Statistics(DefaultStore),
);
const mgr = new WithdrawalsManager(configDao, new Statistics(DefaultStore));
const { balance } = mgr.addWithdrawal(+amount);
const msg = `Withdrawal of $${+amount} was added to the statistics and the balance was updated. Current balance: $${balance}.`;
Log.alert(msg);
Expand Down
6 changes: 4 additions & 2 deletions src/web/components/cards/BalanceCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default function BalanceCard({
}: BalanceProps): JSX.Element {
const stableBalance = balances[name] ?? 0;
const feesBudget = balances.feesBudget ?? 0;
const total = stableBalance + assetsValue;
const total = Math.max(0, stableBalance) + assetsValue;
const feeCover = Math.max(0, Math.floor(feesBudget / (total * BNBFee * 2)));
const feesWarn =
!viewOnly && feeCover < MINIMUM_FEE_COVERAGE
Expand Down Expand Up @@ -65,7 +65,9 @@ export default function BalanceCard({
<Typography component={`div`} variant="body2" color="text.secondary">
<Box>
<b>Free:</b>
{stableBalance === -1 && <span> Wait...</span>}
{stableBalance === -1 && (
<span style={{ float: `right` }}>Unknown</span>
)}
{hide && <span style={{ float: `right` }}>${SHORT_MASK}</span>}
{!hide && stableBalance !== -1 && (
<CurrencyFormat
Expand Down
11 changes: 6 additions & 5 deletions src/web/components/cards/CandidateCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ export default function CandidateCard({
}: CandidateCardProps): JSX.Element {
const strength = ci[Key.STRENGTH] ?? 0;
const priceMove = ci[Key.PRICE_MOVE] ?? PriceMove.NEUTRAL;
const min = ci[Key.MIN];
const dPriceMove = ci[Key.DAY_PRICE_MOVE];
const perc = ci[Key.PERCENTILE];
const max = ci[Key.MAX];

const imbalance = ci[Key.IMBALANCE];
Expand Down Expand Up @@ -61,8 +62,8 @@ export default function CandidateCard({
alignItems="center"
>
{coin}
{!!ci[Key.COOL_DOWN] && `⭐`}
{growthIconMap.get(priceMove)}
{!!ci[Key.COOL_DOWN] && `🛎️⏳`}
<IconButton
disabled={stateChanging}
sx={{ position: `absolute`, top: `6px`, right: `4px` }}
Expand All @@ -82,17 +83,17 @@ export default function CandidateCard({
alignItems="center"
>
<Typography variant="inherit" fontWeight="bold" mr={`5px`}>
Support:
20-d price:
</Typography>
<Typography variant="inherit">{min}</Typography>
<Typography variant="inherit">{PriceMove[dPriceMove]}</Typography>
</Box>
<Box
display="flex"
justifyContent="space-between"
alignItems="center"
>
<Typography variant="inherit" fontWeight="bold" mr={`5px`}>
Resistance:
{perc > 1 ? `Support:` : `Resistance:`}
</Typography>
<Typography variant="inherit">{max}</Typography>
</Box>
Expand Down

0 comments on commit 5e677bc

Please sign in to comment.