本文整理汇总了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))
示例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)
示例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