Exemple #1
0
 async def query(self):
     async with websockets.connect(StockUrl(account=Player.get().account, stock=Player.get().stock,
                                            is_ticker_tape=True).str()) as websocket:
         while True:
             # print(json.loads(await websocket.recv()))
             quote = json.loads(await websocket.recv())['quote']
             await self.callback(quote)
Exemple #2
0
 async def query(self):
     async with websockets.connect(
             StockUrl(account=Player.get().account, stock=Player.get().stock, is_execution=True).str()) as websocket:
         while True:
             # print(json.loads(await websocket.recv()))
             execution = json.loads(await websocket.recv())
             await self.callback(execution)
def BlastPlayers( ):
   global GLOB_PLAYERS

   while( 1 ):
      stdscr.clear()
      stdscr.addstr( "Blast set of players into initiative.\n" )
      stdscr.addstr( "Blank line to finish!\n" )
      stdscr.addstr( "Next name to add...\n" )

      tmp = GetInput( "> ", str )
      if ( len( tmp ) ):
         mule = Player()
         mule.Name = tmp
         GLOB_PLAYERS.append( mule )
      else:
         break
   BlastInitiative()
   return
Exemple #4
0
def getMsg(request):
    uid = request.GET.get('uid', None)  # 获取请求消息用户ID
    if uid is not None:
        uid = int(uid)
        if uid not in user_dict:  # 如果用户首次请求则建立用户实例
            user_dict[uid] = Player()
        try:
            msgs = user_dict[uid].gettMsg(
            )  # 返回所有消息列表 [{from_id:111,to_id:111.....},{},{}]
            return HttpResponse(json.dumps(msgs))  # 响应一个json格式字符串
        except Exception, e:
            print str(e)
Exemple #5
0
def sendMsg(reuqest):
    data = reuqest.POST.get('data', None)  # 接受前端传过来的json
    data = json.loads(data)  # 把json转成python字典
    now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')  # 获取服务器时间
    data['time'] = now
    to_id = int(data['to_id'])  # 获取朋友的id
    if to_id not in user_dict:  # 如果用户不在全局用户字典中则加入
        user_dict[to_id] = Player()
    try:
        user_dict[to_id].msg_q.put(data)  # 向用户字典中的对象的队列里加入一条消息
    except Exception, e:
        print e
def AddPlayer( ):
   global GLOB_PLAYERS

   stdscr.clear()
   stdscr.addstr( "Adding player to game!\n" )
   mule = Player()

   stdscr.addstr( "Player Name: " )
   curses.echo()
   mule.Name = stdscr.getstr()
   curses.noecho()
   
   # Error check for empty names!
   if( not len( mule.Name ) ):
      return
 
   stdscr.addstr( "Initiative: " )
   mule.Initiative = GetInput( "", float )

   GLOB_PLAYERS.append( mule )

   return 
Exemple #7
0
def parse_rankings(file, order=False):
    csv_reader = csv.reader(file)
    players_list = next(csv_reader)[1:]
    players_map = dict(zip(players_list, [Player(name=player) for player in players_list]))

    for ratings_row in csv_reader:
        # Column 1 is the timestamp value
        # Update player mapping with weighted score for each letter rank
        for col_idx, rating in enumerate(ratings_row[1:]):
            if RANKING_WEIGHT[rating] is not None:
                players_map[players_list[col_idx]].ratings.append(RANKING_WEIGHT[rating])

    if order:
        return _ordered_tuple_from(players_map)
    else:
        return players_map
Exemple #8
0
    async def recover_order(self):
        started = datetime.datetime.now()
        while True:
            if datetime.datetime.now() - started >= datetime.timedelta(seconds=30):
                print('Did not recover any order')
                break
            await asyncio.sleep(1)

            if self.remote_order:
                # We have already recovered it through other means
                break

            existing_ids = self.order_set.get_all_order_ids()
            server_orders = await Primitive.all_orders_stock()
            matching_orders = [order for order in server_orders if
                               order['id'] not in existing_ids and order['originalQty'] == self.amount and order[
                                   'symbol'] == Player.get().stock and order[
                                   'price'] == self.price and order['direction'] == self.direction and order[
                                   'orderType'] == self.orderType]
            if len(matching_orders) > 0:
                # If there are multiple matching orders then pick any one
                self.remote_order = matching_orders[0]
                print('Recovered order {}'.format(self.remote_order))
                break
Exemple #9
0
 def __init__(self, my_idx):
     Player.__init__(self, my_idx)
     self.my_idx = my_idx
def DefaultGroup( ):
   global GLOB_PLAYERS


   # ClearScreen()
   stdscr.clear()
   stdscr.addstr( "Initiate Default Group!\n" )
   
   for i in GLOB_PLAYERS:
      if i.Active :
         stdscr.addstr( "WARNING! Active Player Detected! Overwrite? (y/n)\n" )
         
         # Check to see if the user really wants to overwrite.
         stdscr.addstr( ">> " )
         if stdscr.getkey() == 'y' :
            break
         else:
            # Anything other then a y will result in aborting the overwrite
            return

   # Clear global list if it exists
   GLOB_PLAYERS = []

   # Initiate default players list
   # TODO: This would be better as a pull from local user settings.
   mule = Player()   
   mule.Name = "Nate H"
   mule.Initiative = 0
   GLOB_PLAYERS.append( mule )
   
   mule = Player()   
   mule.Name = "John T"
   mule.Initiative = 0
   GLOB_PLAYERS.append( mule )
   
   mule = Player()   
   mule.Name = "Alexandria T"
   mule.Initiative = 0
   GLOB_PLAYERS.append( mule )
   
   mule = Player()   
   mule.Name = "Victor T"
   mule.Initiative = 0
   GLOB_PLAYERS.append( mule )
   
   mule = Player()   
   mule.Name = "NPC(s)"
   mule.Initiative = 0
   GLOB_PLAYERS.append( mule )

   # Write changes to disk
   SaveGame()

   return
Exemple #11
0
 def bootstrap():
     Player.get('sell_side')
     asyncio.get_event_loop().run_until_complete(MarketMaker().run())
Exemple #12
0
 def __init__(self):
     super().__init__("War")
     self.players = [Player() for i in range(self.np)]
Exemple #13
0
 def reset_game(self):
     self.players = [Player() for i in range(self.np)]
     self.deck = Deck()