Diagram about selling - deniyuda348/pump-fun-pump-swap-sniper-copy-bot GitHub Wiki
flowchart TD
A["Start: update_metrics()"] --> B["Extract Transaction Data"]
B --> C["Get SOL Change"]
B --> D["Get Token Change"]
B --> E["Get Transaction Type (Buy/Sell)"]
B --> F["Get Timestamp"]
C --> G["Calculate Price"]
D --> G
G --> H{"Price > 0?"}
H -->|No| I["Log Error & Return"]
H -->|Yes| J["Get Wallet Info"]
J --> K["Calculate ATA Address"]
K --> L["Query Token Balance"]
L --> M["Get/Create Token Metrics Entry"]
M --> N{"Transaction Type?"}
N -->|Buy| O["Buy Transaction Logic"]
N -->|Sell| P["Sell Transaction Logic"]
O --> Q["Calculate Token Amount"]
Q --> R{"Existing Position?"}
R -->|Yes| S["Calculate Weighted Average Entry Price"]
R -->|No| T["Set Initial Entry Price"]
S --> U["Update Entry Price & Cost Basis"]
T --> U
P --> V["Calculate Sell Percentage"]
V --> W["Adjust Cost Basis Proportionally"]
W --> X["Keep Entry Price Unchanged"]
U --> Y["Update Common Metrics"]
X --> Y
Y --> Z["Update Amount Held"]
Y --> AA["Update Current Price"]
Y --> BB["Update Highest Price"]
Y --> CC["Update Lowest Price"]
Y --> DD["Update Price History"]
Z --> EE["Calculate PnL"]
AA --> EE
BB --> EE
CC --> EE
DD --> EE
EE --> FF["Log Updated Metrics"]
FF --> GG["Return Success"]
style A fill:#e1f5fe
style G fill:#fff3e0
style H fill:#ffcc80
style I fill:#ffcdd2
style O fill:#c8e6c9
style P fill:#ffcdd2
style S fill:#bbdefb
style EE fill:#f3e5f5
style GG fill:#c8e6c9