Custom Applications

Uptick is designed in a way that allows you to build your own applications and use the existing infrastructure of pybitshares and uptick easily. This means that you can use so called decorators to simplify development of your own application.

Example 1: Cancel all orders in a market

from pprint import pprint
from uptick.decorators import unlock, online
from uptick.main import main
from bitshares.market import Market
import click

@main.command()
@click.option("--account", default=None)
@click.argument("market")
@click.pass_context
@online
@unlock
def cancelall(ctx, market, account):
    market = Market(market)
    ctx.bitshares.bundle = True
    market.cancel([
        x["id"] for x in market.accountopenorders(account)
    ], account=account)
    pprint(ctx.bitshares.txbuffer.broadcast())


if __name__ == "__main__":
    main()

Example 2: Spread multiple orders evenly in a market:

from pprint import pprint
from numpy import linspace
from uptick.decorators import unlock, online
from uptick.main import main
from bitshares.market import Market
import click


@main.command()
@click.option("--account", default=None)
@click.argument("market")
@click.argument("side", type=click.Choice(['buy', 'sell']))
@click.argument("min", type=float)
@click.argument("max", type=float)
@click.argument("num", type=float)
@click.argument("amount", type=float)
@click.pass_context
@online
@unlock
def spread(ctx, market, side, min, max, num, amount, account):
    market = Market(market)
    ctx.bitshares.bundle = True

    if min < max:
        space = linspace(min, max, num)
    else:
        space = linspace(max, min, num)

    func = getattr(market, side)
    for p in space:
        func(p, amount / float(num), account=account)
    pprint(ctx.bitshares.txbuffer.broadcast())

Decorators

uptick.decorators.chain(f)

This decorator allows you to access ctx.bitshares which is an instance of BitShares.

uptick.decorators.configfile(f)

This decorator will parse a configuration file in YAML format and store the dictionary in ctx.config

uptick.decorators.customchain(**kwargsChain)

This decorator allows you to access ctx.bitshares which is an instance of BitShares. But in contrast to @chain, this is a decorator that expects parameters that are directed right to BitShares().

… code-block::python

@main.command() @click.option(“–worker”, default=None) @click.pass_context @customchain(foo=”bar”) @unlock def list(ctx, worker):

print(ctx.obj)
uptick.decorators.offline(f)

This decorator allows you to access ctx.bitshares which is an instance of BitShares with offline=True.

uptick.decorators.unlock(f)

This decorator will unlock the wallet by either asking for a passphrase or taking the environmental variable UNLOCK

uptick.decorators.verbose(f)

Add verbose flags and add logging handlers