How to use the pywaves.WAVES function in PyWaves

To help you get started, we’ve selected a few PyWaves examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wavesplatform / demo-python-trading-bot / SimpleBot.py View on Github external
my_address = pw.Address(privateKey=bot.private_key)

    waves_btc = pw.AssetPair(bot.amount_asset, bot.price_asset)
    while True:
        waves_balance = my_address.balance()
        bot.log("Your balance is %18d" % waves_balance)
        btc_balance = my_address.balance(bot.price_asset_id)
        bot.log("Your balance is %18d" % btc_balance)
        my_address.cancelOpenOrders(waves_btc)
        order_book = waves_btc.orderbook()
        best_bid = order_book["bids"][0]["price"]
        best_ask = order_book["asks"][0]["price"]
        spread_mean_price = ((best_bid + best_ask) // 2) * 10 ** (bot.price_asset.decimals - bot.amount_asset.decimals)
        bid_price = spread_mean_price * (1 - bot.price_step)
        ask_price = spread_mean_price * (1 + bot.price_step)
        bid_amount = int((btc_balance / bid_price) * 10 ** pw.WAVES.decimals) - bot.order_fee

        bot.log("Best_bid: {0}, best_ask: {1}, spread mean price: {2}".format(best_bid, best_ask, spread_mean_price))

        if bid_amount >= bot.min_amount:
            bot.log("Post buy order with price: {0}, amount:{1}".format(bid_price, bid_amount))
            my_address.buy(assetPair=waves_btc, amount=bid_amount, price=bid_price, matcherFee=bot.order_fee,
                           maxLifetime=bot.order_lifetime)

        waves_balance, btc_balance = my_address.tradableBalance(waves_btc)
        ask_amount = int(waves_balance) - bot.order_fee
        if ask_amount >= bot.min_amount:
            bot.log("Post sell order with price: {0}, ask amount: {1}".format(ask_price, ask_amount))
            my_address.sell(assetPair=waves_btc, amount=ask_amount, price=ask_price, matcherFee=bot.order_fee,
                            maxLifetime=bot.order_lifetime)

        bot.log("Sleep {0} seconds...".format(bot.seconds_to_sleep))
github wavesplatform / demo-python-trading-bot / SimpleBot.py View on Github external
def __init__(self):
        self.log_file = "bot.log"
        self.node = "https://nodes.wavesnodes.com"
        self.chain = "mainnet"
        self.matcher = "https://matcher.waves.exchange"
        self.order_fee = int(0.003 * 10 ** 8)
        self.order_lifetime = 29 * 86400  # 29 days
        self.private_key = ""
        self.amount_asset = pw.WAVES
        self.price_asset_id = "8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS" # BTC
        self.price_asset = pw.Asset(self.price_asset_id)  
        self.price_step = 0.005
        self.min_amount = 1
        self.seconds_to_sleep = 15