Beispiel #1
0
def order(currency, t="b"):
    _account = account()
    chbtc_api = api.chbtc_api(access_key, access_secret)
    a = float(_account["result"]["balance"][currency.split("_")[0].upper()]
              ["amount"])
    b = float(_account["result"]["balance"][currency.split("_")[-1].upper()]
              ["amount"])
    tick = _tick(currency)
    sell = float(tick["ticker"]["sell"])
    buy = float(tick["ticker"]["buy"])
    cur = "%.3f" % (a, )

    if t == "b":
        t = 1
        price = "%.3f" % (sell, )
        amount = "%.3f" % (b / sell, )
    else:
        t = 0
        price = "%.3f" % (buy, )
        amount = cur

    if float(amount) < 0.001 and t == 1:
        print "no money left."
        return False

    if float(cur) < 0.001 and t == 0:
        print "nothing to sell."
        return False

    print price, amount, t, currency
    r = chbtc_api.order(price, amount, t, currency)
    r["price"] = price
    r["status"] = "open"
    return r
Beispiel #2
0
def _cancel(currency):
    chbtc_api = api.chbtc_api(access_key, access_secret)
    buy_orders = chbtc_api.get_orders(currency, 1)
    sell_orders = chbtc_api.get_orders(currency, 0)
    orders = buy_orders + sell_orders
    for o in orders:
        if o["status"] not in [2, 1]:
            retry = 3
            while retry > 0:
                try:
                    r = cancel_order(o["id"], currency)
                    print "cancel%s" % (o["id"], )
                    if r["code"] != "1000":
                        retry -= 1
                        continue
                except Exception as e:
                    print e
                    retry -= 1
                    continue
Beispiel #3
0
def cancel_order(oid, currency):
    chbtc_api = api.chbtc_api(access_key, access_secret)
    order = chbtc_api.cancel_order(oid, currency)
    return order
Beispiel #4
0
def account():
    chbtc_api = api.chbtc_api(access_key, access_secret)
    account = chbtc_api.query_account()
    return account