Giter VIP home page Giter VIP logo

avalanche-python-api's Introduction

Avalanche-Python-API

Avalanche C-Chain buy/sell bot in Python using web3

Example code:

from AvalancheAPI import AvalancheAPI

avapi = AvalancheAPI()

address = '0x60781C2586D68229fde47564546784ab3fACA982' # PNG token address
AVAX_TO_SPEND = 0.02 # How many AVAX to spend on buying the token

# Buy the token
buy_tx = avapi.buy(address, AVAX_TO_SPEND)
print(buy_tx)
buy_receipt = avapi.awaitReceipt(buy_tx) # Wait for transaction to finish
print(buy_receipt)

if buy_receipt.status == 1: # Check if the transaction went through
    print('bought successfully!')
else:
    print('buy failed,  exiting...')
    exit()

# Approve the token, must be done once before selling
approve_tx = avapi.approve(address)
print(approve_tx)
approve_receipt = avapi.awaitReceipt(approve_tx)
print(approve_receipt)

# Get info about the token, and get current token value. 
# Useful if we want to sell when we for example hit 2x the value we bought at
balance, value = avapi.get_token_holdings(address)
symbol, decimals = avapi.get_token_info(address)
print(f'We have {balance/(10**decimals)} {symbol}, worth {value/(10**18)} AVAX')

# Sell the token, we can set a percentage to sell
sell_tx = avapi.sell(address, sell_prcnt=50) # Here we sell half of our tokens (50%)
print(sell_tx)
sell_receipt = avapi.awaitReceipt(sell_tx)
print(sell_receipt)

avalanche-python-api's People

Contributors

sjoerd1999 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.