示例#1
0
文件: web.py 项目: haoccheng/pegasus
def sell_request(symbol, share, ask):
  try:
    symbol = str(symbol)
    share = int(share)
    ask = float(ask)
    if share > 0 and ask > 0.0:
      orderid = market.sell_request(symbol, share, ask)
      market.match(symbol)
      return jsonify({'status':'SELL OK', 'order_id':orderid})
  except:
    return jsonify({'status':'SELL FAILED'})
示例#2
0
文件: web.py 项目: haoccheng/pegasus
def buy_request(symbol, share, bid):
  try:
    symbol = str(symbol)
    share = int(share)
    bid = float(bid)
    if share > 0 and bid > 0.0:
      orderid = market.buy_request(symbol, share, bid)
      market.match(symbol)
      return jsonify({'status':'BUY OK', 'order_id':orderid})
  except:
    return jsonify({'status':'BUY FAILED'})
示例#3
0
	def on_message(self, msg):
		msg_type = msg['type']

		if msg_type == 'subscriptions':
			return

		if 'product_id' not in msg:
			print("Bad MSG:", msg)
		product = msg['product_id']

		market = first(self.markets, lambda m: m.symbol() == product)

		if msg_type == 'snapshot':
			print("Got GDAX", product, "snapshot:", len(json.dumps(msg)), "bytes")
			qinc = market.tick_size()
			ssize = market.step_size()
			bids = { Decimal(p).quantize(qinc): Decimal(s).quantize(ssize) for (p, s) in msg['bids'] }
			asks = { Decimal(p).quantize(qinc): Decimal(s).quantize(ssize) for (p, s) in msg['asks'] }
			market.reset_book(bids, asks)
		elif msg_type == 'last_match' or msg_type == 'match':
			qinc = market.tick_size()
			price = Decimal(msg['price']).quantize(qinc)
			market.match(price)
		elif msg_type == 'l2update':
			changes = msg['changes']
			qinc = market.tick_size()
			ssize = market.step_size()

			for change in changes:
				side = change[0]
				price = Decimal(change[1]).quantize(qinc)
				size = Decimal(change[2]).quantize(ssize)

				if side == 'buy':
					market.update_bid(price, size)
				else:
					market.update_ask(price, size)