Skip to content
This repository has been archived by the owner on May 13, 2024. It is now read-only.

Commit

Permalink
Merge branch 'release/0.7.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
beeb committed May 30, 2022
2 parents 44958f8 + 94829b5 commit 1527f5b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions pancaketrade/network/bsc.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,10 +392,16 @@ def calculate_price_impact(
token_price, _ = self.get_token_price(token_address)
if self.price_in_usd: # we need price in BNB / token
token_price = token_price / self.get_bnb_price()
quote_amount_out = amount_in * token_price if sell else amount_in / token_price
quote_amount_out = amount_in * token_price if sell else amount_in / token_price # with "in" token decimals
if swap_path is None or amount_out is None:
swap_path, amount_out = self.get_best_swap_path(token_address, amount_in, sell)
slippage = (quote_amount_out - amount_out) / quote_amount_out
swap_path, amount_out = self.get_best_swap_path(token_address, amount_in, sell) # with "out" token decimals
quote_amount_out_normalized = quote_amount_out * Decimal(
10 ** (18 - self.get_token_decimals(swap_path[0]))
) # normalize to 18 decimals
amount_out_normalized = Decimal(amount_out) * Decimal(
10 ** (18 - self.get_token_decimals(swap_path[-1]))
) # normalize to 18 decimals
slippage = (quote_amount_out_normalized - amount_out_normalized) / quote_amount_out_normalized
lpFee = Decimal("0.0025") if len(swap_path) == 2 else Decimal("0.0049375") # 1 - (1-0.25%)^2
return slippage - lpFee

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pancaketrade"
version = "0.7.1"
version = "0.7.2"
description = "Trading bot for PancakeSwap"
authors = ["Valentin Bersier <[email protected]>"]

Expand Down

0 comments on commit 1527f5b

Please sign in to comment.