This repository simplifies the complexity of interacting with the Binance Smart Chain that is a blockchain deployed by Binance. Binance is a cryptocurrency exchange. This library also simplifies interaction with Pancake-swap which is a DeFi exchange.
git clone https://github.com/deshiyan1010/pyPancakeSwap
cd pyPancakeSwap
python setup.py install
class pyPancakSwap.pyPancakeSwap(rpc_endpoint:str=None,testnet:bool=False)
Default RPC endpoint:
| Testnet | RPC |
| ----- | ---- |
| False | 'https://bsc-dataseed.binance.org/' |
| True | 'https://data-seed-prebsc-1-s1.binance.org:8545/' |
| ... | ... |
Table: Default RPC table
pyPancakeSwap.isConnected(None)
Returns True is connected to RPC.
pyPancakeSwap.connect_wallet(self,address:str,private_key:str)
Returns True if the public address and private key match eachother and connects wallet.
pyPancakeSwap.get_balance(self,token_address:str=None,token_abi:str=None)
Returns balance of BNB if token address is not mentioned, if mentioned the returns balance of the specified token. Returns two types of values, true balance and other without decimal.
pyPancakeSwap.set_router_address(self,address:str)->None
By default PancakeSwap Router is set.
pyPancakeSwap.get_price(self,token:str)->float
Returns price of token of the contract address passed.
pyPancakeSwap.get_liquidity(self,token:str)->float
Returns liquidity in pool of token of the contract address passed.
pyPancakeSwap.buy_token_with_bnb(self,token_contract_address:str,amount_bnb:float,gas:float=None,gasPrice:float=None,milliseconds_to_expire:int=None,min_tokens_expected:float=None)-> Tuple[TxReceipt, float]
approve_token_for_bnb(self,token_contract_address:str,amount_token:float,gas:float=None,gasPrice:float=None) -> Tuple[TxReceipt, float]:
pyPancakeSwap.sell_token_for_bnb(self,token_contract_address:str,amount_token:float,gas:float=None,gasPrice:float=None,milliseconds_to_expire:int=None,min_tokens_expected:float=None) -> Tuple[TxReceipt, float]:
pyPancakeSwap.sendBNB(self,amount_bnb:float,receiver_address:str,gas:float=None,gasPrice:float=None,milliseconds_to_expire:int=None) -> Tuple[TxReceipt, float]: