How to use the pywaves.AssetPair 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
def main():
    bot = SimpleBot()
    bot.read_config("config.cfg")
    pw.setNode(node=bot.node, chain=bot.chain)
    pw.setMatcher(node=bot.matcher)
    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))
github PyWaves / BlackBot / BlackBot.py View on Github external
BLACKBOT = pw.Address(privateKey=PRIVATE_KEY)

    log("-" * 80)
    log("          Address : %s" % BLACKBOT.address)
    log("  Amount Asset ID : %s" % amountAssetID)
    log("   Price Asset ID : %s" % priceAssetID)
    log("-" * 80)
    log("")
except:
    log("Error reading config file")
    log("Exiting.")
    exit(1)

pw.setNode(NODE, "mainnet")
pw.setMatcher(MATCHER)
PAIR = pw.AssetPair(pw.Asset(amountAssetID), pw.Asset(priceAssetID))

# grid list with GRID_LEVELS items. item n is the ID of the order placed at the price calculated with this formula
# price = int(basePrice * (1 + INTERVAL) ** (n - GRID_LEVELS / 2))

grid = ["-"] * GRID_LEVELS

log("Cancelling open orders...")

# cancel all open orders on the specified pair
BLACKBOT.cancelOpenOrders(PAIR)
log("Deleting order history...")

# delete order history on the specified pair
BLACKBOT.deleteOrderHistory(PAIR)
log("")