Пример #1
0
def roll_market_depth():
    try:
        while 1:
            print Data.get_market_depth(limit=1)
            time.sleep(0.25)
    except:
        roll_market_depth()
Пример #2
0
def top_bid(amount=0.01):
    order = Order(access_id, secret_key)

    market_depth = Data.get_market_depth(limit=1)
    bid_price, bid_amount = map(float, market_depth["data"]["bids"][0])
    ask_price, ask_amount = map(float, market_depth["data"]["asks"][0])

    od = order.order_limit("buy", amount=amount, price=ask_price - 0.01)
    od_price = float(od["data"]["price"])
    od_id = od["data"]["id"]

    time.sleep(2)

    market_depth = Data.get_market_depth(limit=5)
    bid_price1, bid_amount1 = map(float, market_depth["data"]["bids"][0])
    ask_price1, ask_amount1 = map(float, market_depth["data"]["asks"][0])
    bid_price2, bid_amount2 = map(float, market_depth["data"]["bids"][1])
    ask_price2, ask_amount2 = map(float, market_depth["data"]["asks"][1])

    if bid_price1 != od_price:
        print "Shit, the deal has been eaten."
    else:
        if bid_amount1 != amount or bid_price2 == od_price - 0.01:
            print "There is a follower, let's crush him!"
            order.order_withdraw(order_id=od_id)
        else:
            print "There is no follower, peace."
            order.order_withdraw(order_id=od_id)
Пример #3
0
def clean_ask(level=1):
    order = Order(access_id, secret_key)
    market_depth = Data.get_market_depth()
    asks = market_depth["data"]["asks"][:level]
    bids = market_depth["data"]["bids"][:level]
    for i in asks:
        order.order_limit("buy", float(i[1]), float(i[0]))
Пример #4
0
def self_deal(price, amount=0.01):
    order = Order(access_id, secret_key)

    market_depth = Data.get_market_depth(limit=1)
    bid_price, bid_amount = map(float, market_depth["data"]["bids"][0])
    ask_price, ask_amount = map(float, market_depth["data"]["asks"][0])

    if price > ask_price or price < bid_price:
        print "Shit, your deal is going to be eaten, change your price."
        return 0

    order.order_limit("buy", price=price, amount=amount)
    order.order_limit("sell", price=price, amount=amount)
    order.withdraw_all()
Пример #5
0
    def store_data(data_type, market="BCCCNY"):
        """

        :param data_type:

            1min : 1分钟;
            3min:3分钟;
            5min : 5分钟;
            15min:15分钟;
            30min:30分钟;
            1hour:1小时;
            2hour:2小时;
            4hour:4小时;
            6hour:6小时;
            12hour:12小时;
            1day:1日;
            3day:3日;
            1week:1周;

        :param market: one from market list
        :return:
        """
        target = "data/" + market + "_" + data_type + ".csv"

        # 得到最新的从老到新排列的数据
        candles = Data.get_candles(type=data_type, market=market).get("data")
        candles_df = pd.DataFrame(
            candles, columns=["time", "open", "close", "high", "low", "vol"])

        # 得到过去从老到新排列的数据
        try:
            # 如果老数据存在
            old_candles_df = pd.DataFrame.from_csv(target)
            merge_candles = pd.concat([old_candles_df, candles_df])
            csv = merge_candles.drop_duplicates(
                "time", keep="first").reset_index(drop=True)
            print len(csv)
            csv.to_csv(target)
        except:
            # 如果老数据不存在
            print "1st time to store data, just create one."
            csv = candles_df
            print len(csv)
            csv.to_csv(target)
Пример #6
0
def pull_up(step=0.01, amount=0.01):
    order = Order(access_id, secret_key)
    last_id = ""
    last_price = 0
    while 1:
        time.sleep(0.5)
        print "0"
        market_depth = Data.get_market_depth(limit=1)
        bid_price, bid_amount = map(float, market_depth["data"]["bids"][0])
        ask_price, ask_amount = map(float, market_depth["data"]["asks"][0])

        # 先写一个追踪策略
        if ask_price > bid_price + step:
            if last_id != "":
                print "1"
                order.order_withdraw(last_id)
                if last_price + step >= ask_price:
                    print "4"
                    break
                buy1 = order.order_limit("buy",
                                         price=max([bid_price, last_price]) +
                                         step,
                                         amount=amount)
                print buy1
                last_id = buy1["data"]["id"]
                last_price = float(buy1["data"]["price"])
            else:
                print "2"
                buy1 = order.order_limit("buy",
                                         price=bid_price + step,
                                         amount=amount)
                print buy1
                last_id = buy1["data"]["id"]
                last_price = float(buy1["data"]["price"])
        else:
            print "3"
            order.withdraw_all()
            break
Пример #7
0
def butt_price():
    market_depth = Data.get_market_depth(limit=1)
    bid_price, bid_amount = map(float, market_depth["data"]["bids"][0])
    ask_price, ask_amount = map(float, market_depth["data"]["asks"][0])
    return bid_price + 0.01