當前位置: 首頁>>代碼示例>>Python>>正文


Python Book.parse方法代碼示例

本文整理匯總了Python中book.Book.parse方法的典型用法代碼示例。如果您正苦於以下問題:Python Book.parse方法的具體用法?Python Book.parse怎麽用?Python Book.parse使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在book.Book的用法示例。


在下文中一共展示了Book.parse方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: run

# 需要導入模塊: from book import Book [as 別名]
# 或者: from book.Book import parse [as 別名]
def run():
    mbook = Book.parse(get_mtgox())
    bbook = Book.parse(bitfloor.book(level=2))

    mbook.flatten('0.01')

    our_book, our_book2 = get_our_book()

    # remove our stuff from bbook
    # bbook will have the orders we don't control
    bbook.subtract(our_book2)

    # mbook will now have the gap needed to be filled by our orders
    mbook.subtract(bbook)

    funds = get_funds()

    # get the total remaining area needed to fill
    # find which factor of it we can fill with our total funds
    sumb = sum(o.price*o.size for o in mbook.bids if o.size > 0)*D('1.04')
    bfactor = min(1, funds['USD']/sumb) if sumb > 0 else 1
    suma = sum(o.size for o in mbook.asks if o.size > 0)
    afactor = min(1, funds['BTC']/suma) if suma > 0 else 1

    print afactor, bfactor
    print suma, sumb

    # multiply everything positive by the factor
    # mbook will now have what we need to provide to bitfloor's book
    for o in mbook.bids:
        if o.size > 0:
            o.size *= bfactor
            o.size = o.size.quantize(D('0.00000001'), rounding=decimal.ROUND_DOWN)
    for o in mbook.asks:
        if o.size > 0:
            o.size *= afactor
            o.size = o.size.quantize(D('0.00000001'), rounding=decimal.ROUND_DOWN)

    # now, get the difference between what we need to provide and what we have
    mbook.subtract(our_book2)

    # cancel orders first which are above the gap
    cancel(mbook, our_book, 'bid')
    cancel(mbook, our_book, 'ask')

    # send in orders to fill the gaps
    for o in mbook.bids:
        if o.size > SIZE_LIMIT:
            print 'bid', o
            bitfloor.buy(size=str(o.size), price=str(o.price))
    for o in mbook.asks:
        if o.size > SIZE_LIMIT:
            print 'ask', o
            bitfloor.sell(size=str(o.size), price=str(o.price))
開發者ID:shadww,項目名稱:trader.python,代碼行數:56,代碼來源:bitfloor_mirror_mtgox.py

示例2: get_our_book

# 需要導入模塊: from book import Book [as 別名]
# 或者: from book.Book import parse [as 別名]
def get_our_book():
    orders = bitfloor.orders()

    our_book = {
        'bids': {},
        'asks': {}
    }

    our_book2 = {
        'bids': [],
        'asks': []
    }

    for o in orders:
        size = D(str(o['size']))
        price = D(str(o['price']))
        order = Order(size, price)
        order.id = o['order_id'] # TODO: hacky
        tup = (str(price), str(size))
        if o['side'] == 0:
            our_book['bids'].setdefault(price, []).append(order)
            our_book2['bids'].append(tup)
        elif o['side'] == 1:
            our_book['asks'].setdefault(price, []).append(order)
            our_book2['asks'].append(tup)

    return our_book, Book.parse(our_book2)
開發者ID:shadww,項目名稱:trader.python,代碼行數:29,代碼來源:bitfloor_mirror_mtgox.py

示例3: entirebook

# 需要導入模塊: from book import Book [as 別名]
# 或者: from book.Book import parse [as 別名]
 def entirebook(self,ordergrouping=1):
 #Open orders book with bids and asks
     url = "order_book/"
     params = {"group":ordergrouping}    #group orders with the same price (0 - false; 1 - true). Default: 1
     orderbook = self.get(url,params) 
     from book import Book
     entirebook = Book.parse(orderbook)
     entirebook.sort()
     return entirebook       #Returns a sorted Book class object,containing entirebook.bids and entirebook.asks
開發者ID:vic0,項目名稱:trader.python,代碼行數:11,代碼來源:bitstamp.py


注:本文中的book.Book.parse方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。