# WSS Listen to new Trades

Listens to all new token trades through a WebSocket connection on Pumpfun

```python
import solcoin.listen_pf_trades as lt
if __name__ == "__main__":
    try:
        lt.start_websocket("wss://solana-api.instantnodes.io/API_KEY", "")
    except Exception as e:
        print(f"Unexpected error in main event loop: {e}")
```

start websocket takes 2 arguments

1. RPC URL
2. mint pubkey to filter trades on; leave as "" for no filter
   1. <pre><code><strong>listen_pf_trades.start_websocket("wss://solana-api.instantnodes.io/API_KEY", 
      </strong><strong>"9tGpPyY8Je18pgTidgJ1jpzA7ywuk1RpLpryJT9Gpump")
      </strong><strong>
      </strong><strong># filters to only show trades on the token 9tGpPyY8Je18pgTidgJ1jpzA7ywuk1RpLpryJT9Gpump
      </strong></code></pre>

#### Example Output

```json
{
    'mint': mint pubkey, 
    'sol_amount': Amount of sol transacted, 
    'token_amount': Amount of tokens transacted, 
    'is_buy': If the transaction is buying an user buying a token, 
    'user': user who conducted the transaction, 
    'timestamp': time of transaction, 
    'virtual_sol_reserves': bonding curve's current virtural sol reserves in lamports, 
    'virtual_token_reserves': bonding curve's virtural token reserves x 10^6, 
    'txn_sig': transaction signature
}
```

```json
{
    'mint': '7S3apHy76FiMMhNn2EGoLuPetQVzdwr6SMoT4CuJpump', 
    'sol_amount': 1.1316e-05, 
    'token_amount': 324.414107, 
    'is_buy': True, 
    'user': 'Dv4TeifHSUaKqz7iPjTHWR31ZwzEPvtn6ggdpSnw4Vih', 
    'timestamp': 1742773880, 
    'virtual_sol_reserves': 33508441536, 
    'virtual_token_reserves': 960653451037445, 
    'txn_sig': '5uritv3eHozY2SGThXLsiVoATddr9WwrqjqpKq6PQKiyshADfdsytFEKRvx7sDBnDYnPYjC1JwBcxQrHa7nvKdtk'
}
```
