def format_depth(self, biddepth, askdepth): bids = [] for bid in biddepth['offers']: takerpays = bid['TakerPays'] takergets = bid['TakerGets']['value'] if 'taker_pays_funded' in bid: takerpays = bid['taker_pays_funded'] if 'taker_gets_funded' in bid: takergets = bid['taker_gets_funded']['value'] takerpays = float(takerpays)/1000000 if takerpays == 0: continue takergets = float(takergets) rate = trunc(takergets/takerpays) bids.append([rate, trunc(takerpays)]) bids = self.sort_and_format(bids, True) asks = [] for ask in askdepth['offers']: takerpays = ask['TakerPays']['value'] takergets = ask['TakerGets'] if 'taker_pays_funded' in ask: takerpays = ask['taker_pays_funded']['value'] if 'taker_gets_funded' in ask: takergets = ask['taker_gets_funded'] takerpays = float(takerpays) takergets = float(takergets)/1000000 if takergets == 0: continue rate = trunc(takerpays / takergets) asks.append([rate, trunc(takergets)]) asks = self.sort_and_format(asks, False) return {'asks': asks, 'bids': bids}
def update(self, dt): Sprite.update(self, dt) self.black_hole_checks = {} for behaviour in self.behaviours: behaviour.next() self.x = utils.trunc(self.x + self.vel_x, 0, CONSTS.game_width) self.y = utils.trunc(self.y + self.vel_y, 0, CONSTS.game_height)
def get_balance(self): params = {'account':self.address} xrp_balance = self.server.account_info(params)['account_data']['Balance'] xrp_balance = trunc(float(xrp_balance)/1000000, 4) r = self.server.account_lines(params) for line in r['lines']: if line['account'] == self.issuer_address: cny_balance = line['balance'] cny_balance = trunc(float(cny_balance), 4) return {'xrp':xrp_balance, 'cny':cny_balance}
def chase(self): speed = 5 while (True): if not self.track.dead: vx, vy = utils.normalize(self.track.x - self.x, self.track.y - self.y) theta = math.atan2(self.track.y - self.y, self.track.x - self.x) * 180 / math.pi vx = 5 * (90 - abs(theta)) / 90 if theta < 0: vy = -speed + abs(vx) else: vy = speed - abs(vx) self.x += vx self.y += vy self.vel_x = utils.trunc(self.vel_x + vx * speed, 8) self.vel_y = utils.trunc(self.vel_y + vy * speed, 8) yield 0
def get_avaliable_amount(this_price,type='buy') : ft_num = float(fcoin.get_coin_balance('ft')) usdt_num = float(fcoin.get_coin_balance('usdt')) if ft_num < 2 or usdt_num < 2: avalibal_amount = 0 else: avalibal_amount = 2 if type == 'buy': if avalibal_amount == 0: sell_action('ftusdt',this_price,trunc(ft_num * 0.6,2),0) avalibal_amount = trunc(usdt_num / this_price,0) print('可提的最大数量',avalibal_amount) else: if avalibal_amount == 0: buy_action('ftusdt',this_price,trunc(usdt_num * 0.6,2),0) avalibal_amount = trunc(ft_num * this_price,0 ) print('可卖的最大数量',avalibal_amount) return avalibal_amount
def search_author_publication(self, author_id, show=True, verbose=False): #{{{ search author's publications using authid import warnings import numpy as np import pandas as pd from urllib2 import urlopen from utils import trunc, _parse_author, _parse_xml from bs4 import BeautifulSoup as bs #TODO: Verbose mode ''' Search author's publication by author id ''' url = self._search_url_base + 'apikey={}&query=au-id({})&start=0&httpAccept=application/xml'.format( self.apikey, author_id) soup = bs(urlopen(url).read(), 'lxml') total = float(soup.find('opensearch:totalresults').text) print 'A toal number of ', int( total), ' records for author ', author_id starts = np.array([i * 25 for i in range(int(np.ceil(total / 25.)))]) publication_list = [] for start in starts: search_url = self._search_url_base + 'apikey={}&start={}&query=au-id({})&httpAccept=application/xml'.format( self.apikey, start, author_id) results = bs(urlopen(search_url).read(), 'lxml') entries = results.find_all('entry') for entry in entries: publication_list.append(_parse_xml(entry)) df = pd.DataFrame(publication_list) if show: #pd.set_printoptions('display.expand_frame_repr', False) #print df['title'].to_string(max_rows=10, justify='left') titles = np.array(df['title']) for i in range(titles.size): t = trunc(titles[i]) print i, t # }}} return df
def search_author_publication(self, author_id, show=True, verbose=False): #{{{ search author's publications using authid import warnings import numpy as np import pandas as pd from urllib2 import urlopen from utils import trunc, _parse_author, _parse_xml from bs4 import BeautifulSoup as bs #TODO: Verbose mode ''' Search author's publication by author id returns a list of dictionaries ''' url = self._search_url_base + 'apikey={}&query=au-id({})&start=0&httpAccept=application/xml'.format(self.apikey, author_id) soup = bs(urlopen(url).read(), 'lxml') total = float(soup.find('opensearch:totalresults').text) print 'A toal number of ', int(total), ' records for author ', author_id starts = np.array([i*25 for i in range(int(np.ceil(total/25.)))]) publication_list = [] for start in starts: search_url = self._search_url_base + 'apikey={}&start={}&query=au-id({})&httpAccept=application/xml'.format(self.apikey, start, author_id) results = bs(urlopen(search_url).read(), 'lxml') entries = results.find_all('entry') for entry in entries: publication_list.append(_parse_xml(entry)) if show: #pd.set_printoptions('display.expand_frame_repr', False) #print df['title'].to_string(max_rows=10, justify='left') df = pd.DataFrame(publication_list) titles = np.array(df['title']) for i in range(titles.size): t = trunc(titles[i]) print i, t # }}} return publication_list
def sell(self, price, amount): value = str(trunc(price*amount,2) - 0.01) pays = {'currency': 'CNY','issuer': self.issuer_address, 'value': value} params = {'secret':self.secret, 'tx_json': {'TransactionType':'OfferCreate', 'Account':self.address,'TakerGets':str(amount*1000000), "TakerPays":pays}} return self.server.submit(params)
def update_particles(self): self.emit_counter += 120 while self.emit_counter > self.emit_rate: ix = -1 for i in range(len(self.particle_life)): if self.particle_life[i] <= 0: ix = i break if ix == -1: break self.emit_counter = 0 self.particle_pos[ix * 2] = self.x self.particle_pos[ix * 2 + 1] = self.y self.particle_life[ix] = self.particle_life_i rand = lambda: random.random() * 2 - 1 a = math.radians((180 - self.angle) + 10 * rand()) v_x, v_y = math.cos(a), math.sin(a) sp = 1 * rand() self.particle_rad[ix * 2] = v_x + sp self.particle_rad[ix * 2 + 1] = v_y + sp self.particle_color[ix * 4] = 0.7 self.particle_color[ix * 4 + 1] = 0.2 self.particle_color[ix * 4 + 2] = 0.1 self.particle_color[ix * 4 + 3] = 1.0 self.emit_counter -= self.emit_rate self.life -= 1 if self.life <= 0 and not self.infi_life: self.dead = True for i in xrange(0, len(self.particle_pos), 2): x = self.particle_pos[i] y = self.particle_pos[i + 1] posx, posy = utils.normalize(x, y) self.particle_rad[i] self.particle_rad[i + 1] vel = [self.particle_rad[i], self.particle_rad[i + 1]] self.particle_pos[i] = utils.trunc(self.particle_pos[i] + vel[0], 0, CONSTS.game_width) self.particle_pos[i + 1] = utils.trunc( self.particle_pos[i + 1] + vel[1], 0, CONSTS.game_height) if self.particle_pos[i + 1] == 0 or self.particle_pos[ i + 1] == CONSTS.game_height: self.particle_rad[i + 1] *= -1 if self.particle_pos[i] == 0 or self.particle_pos[ i] == CONSTS.game_width: self.particle_rad[i] *= -1 self.particle_life[(i / 2)] -= 1 self.particle_color[(i / 2) * 4 + 3] -= self.alpha_delta
def _on_convert_end(self, title): self._event(utils.LABEL_STATUS, '"{}" done!'.format(utils.trunc(title, utils.TRUNC_SIZE))) self._event(utils.BTN_DL_ENABLED, True)
def _on_progress_finished(self, prog): video_name = utils.base_filename(prog['filename']) video_name = utils.trunc(video_name, utils.TRUNC_SIZE) status_str = '"{}" to MP3…'.format(video_name) self._event(utils.LABEL_STATUS, status_str)
def _on_progress_update(self, prog): video_name = utils.base_filename(prog['filename']) video_name = utils.trunc(video_name, utils.TRUNC_SIZE) status_str = '"{}" {}'.format(video_name, prog['_percent_str']) self._event(utils.LABEL_STATUS, status_str)
def update(self, dt): self.black_hole_checks = {} if self.dead: self._exit_behaviour.next() return if self.nonactive and not self._enter_behaviour.next(): return self.bullets = [] self.xdt = dt / CONSTS.game_iter Sprite.update(self, dt) last_x, last_y = self.x, self.y for behaviour in self.behaviours: behaviour.next() steer_x = steer_y = 0 # friction if no desired velocity if self._des_vx == 0 and self._des_vy == 0: self.vel_x *= 0.9 self.vel_y *= 0.9 else: steer_x, steer_y = self._des_vx - \ self.vel_x, self._des_vy - self.vel_y # truncate steer_x = utils.trunc(self._des_vx - self.vel_x, 0.5) steer_y = utils.trunc(self._des_vy - self.vel_y, 0.5) self.vel_x += steer_x self.vel_y += steer_y """ Separation """ self._sep_vx /= self._neighbors self._sep_vy /= self._neighbors self._sep_vx, self._sep_vy = utils.normalize(self._sep_vx, self._sep_vy) self._sep_vx *= -2 self._sep_vy *= -2 self.vel_x += self._sep_vx self.vel_y += self._sep_vy self.vel_x = utils.trunc(self.vel_x, -self.max_vel, self.max_vel) self.vel_y = utils.trunc(self.vel_y, -self.max_vel, self.max_vel) if self._exits: self.x = self.x + self.vel_x self.y = self.y + self.vel_y if self.show_on_radar and self.is_outside: self.show_on_radar = False else: self.x = utils.trunc(self.x + self.vel_x, 0, CONSTS.game_width) self.y = utils.trunc(self.y + self.vel_y, 0, CONSTS.game_height) if not self.vel_x == 0: theta = math.atan2(self.y - last_y, self.x - last_x) else: theta = 5 if CONSTS.DEBUG_MODE: self.debug_vertex_list.append( CONSTS.debug_batch.add( 2, pyglet.gl.GL_LINES, None, ('v2f', (self.x, self.y, self.x + math.cos(theta) * 50, self.y + math.sin(theta) * 50)), ('c4B', (0, 255, 0, 255) * 2))) self.debug_vertex_list.append( CONSTS.debug_batch.add( 2, pyglet.gl.GL_LINES, None, ('v2f', (self.x, self.y, self.x + steer_x * 100, self.y + steer_y * 100)), ('c4B', (255, 0, 0, 255) * 2))) self._sep_vx = self._sep_vy = 0 self.evade_list = [] self._neighbors = 1