def call(req_params, required_params, optional_params=None): # first validate required parameters params = {k: v for k, v in req_params.items() if k in required_params} __validate_required_params(required_params, params) # then identify unknown parameters all_params = set([k for k in req_params.keys()]) unknown_params = all_params - (optional_params | required_params ) # given params minus union of allowed if len(unknown_params) > 0: raise InvalidParam( 'Unrecognized parameters: {0}'.format(unknown_params)) # finally add optional parameters to required parameters other_params = { k: v for k, v in req_params.items() if k in optional_params } # do some additional checking for placements if 'placements' in other_params: __validate_placements(other_params['placements']) params.update(other_params) client = Client(ip=request.remote_addr, geolocation_provider=provider, **params) return jsonify(client.get_spocs())
def get_tweets(username, max_num=1000): client = Client(CONSUMER_KEY, CONSUMER_SECRET) request_url = 'https://api.twitter.com/1.1/statuses/user_timeline.json' + \ '?screen_name=' + str(username) + \ '&count=' + str(max_num) tweets = client.request(request_url) # 200 tweets while len(tweets) < max_num: tweets.extend(client.request(request_url + '&max_id=' + str(tweets[-1]['id']))) return tweets
def test_init_client(self): # Given name = "John Doe" # When client = Client(name) # Then assert client.name == name
def get_package_by_id(cls, package_id): pkg = Package.query.filter_by(package_id=package_id).first() if pkg and pkg.delivery_status != cls.SIGNED: express = Express.query.filter_by( express_id=pkg.express_id).first() package_info = Client().get_package(express.code, pkg.number) pkg.update(package_info) return pkg
def test_client_default_account(self): # Given name = "John Doe" # When client = Client(name) # Then assert client.account is not None assert isinstance(client.account, Account)
def test_client_with_account(self): # Given name = "John Doe" account = Account(Decimal(10)) # When client = Client(name, account) # Then assert client.account is account
def main(input_args: BaseModel) -> None: client = Client(api_key=API_KEY, api_secret=SECRET_KEY) symbol = client.get_symbol(input_args.symbol) # Place a market buy order if input_args.buy_type == "limit": buy_order = LimitOrder(symbol=symbol, side=Order.SideEnum.buy, price=input_args.price, quantity=input_args.quantity) elif input_args.buy_type == "market": buy_order = MarketOrder(symbol=symbol, side=Order.SideEnum.buy, total=input_args.total) else: sys.exit("Buy order type not supported") order_in_progress = client.execute_buy_strategy(buy_order) print("=========================") print("=== Buy order summary ===") print( f"=> Buy price: " f"{get_formated_price(order_in_progress.info.price, symbol.price_decimal_precision)} " f"{symbol.quoteAsset}") print( "=> Total price: " f"{get_formated_price(order_in_progress.info.cummulative_quote_quantity, symbol.price_decimal_precision)} " f"{symbol.quoteAsset}") print( f"=> Buy quantity: {get_formated_price(order_in_progress.info.executed_quantity, symbol.qty_decimal_precision)} " f"{symbol.baseAsset}") stop_loss_limit_order, limit_maker_order = client.execute_sell_strategy( order_in_progress, input_args.profit, input_args.loss, ) print("=========================") print("=== OCO order summary ===") print("== Stop loss limit order:", stop_loss_limit_order) print("== Limit maker order:", limit_maker_order)
def get_all_express(cls): rsp = Client().get_all_express() result = [] for r in rsp: e = cls.query.filter_by(code=r['type']).first() if not e: e = cls(r['name'], r['type'], r.get("tel")) result.append(e) return result
def get_package(cls, user_id, express_code, package_number): try: package_info = Client().get_package(express_code, package_number) except: return None express = Express.query.filter_by(code=express_code).first() package = cls.query.filter_by(user_id=user_id, number=package_number).first() if not package: package = cls(user_id, express.express_id, package_info) else: package.update(package_info) return package
def main(name, balance): if balance is None: balance = 0 click.echo("Bonjour {}, Bienvenue au Kata SGCIB".format(name)) account = Account(Decimal(balance)) client = Client(name, account) click.echo("Votre solde est actuellement de : {} EUR".format( client.account.balance)) if click.confirm('Voulez vous retirer de l\'argent?'): amount = click.prompt('Veuillez taper un montant correct', type=int) client.account.withdraw(amount) click.echo("Votre solde est désormais de : {} EUR".format( client.account.balance)) click.echo("A bientôt !")
def test_client(start_time, end_time, resolution, tmpdir, timeout, correct_hash): path = tmpdir.mkdir('test') client = Client(path=path, num_processes=max(cpu_count() - 1, 1), start_time=start_time.isoformat(), end_time=end_time.isoformat(), resolution=resolution, timeout=timeout).prepare() process = Process(target=client.run) process.start() process.join() client2 = Client(path=path, num_processes=1, start_time=start_time.isoformat(), end_time=end_time.isoformat(), resolution=resolution, timeout=timeout).prepare() assert client2.hashes == correct_hash
class AppThingSuite(unittest.TestCase): project_name = None def setUp(self): self.client = Client() self.project_name = "nombre" @patch('app.client.Client.generate_project_files') def test_add_project_return_dict_is_correct(self,mock): # GIVEN project_id = self.project_name # WHEN project_data = self.client.add_project(self.project_name) # THEN project = project_data['project'] id = project_data['id'] token = project_data['token'] self.assertTrue(len(token) == 32)
class StrListConverter(BaseConverter): regex = r'\w+(?:;\w+)*;?' def to_python(self, value): return [str(x) for x in value.split(';')] def to_url(self, value): return ';'.join(str(x) for x in value) app.url_map.converters['str_list'] = StrListConverter sns.set_style("whitegrid") client = Client(config.DBUSER, config.DBPASSWORD, config.HOST, config.DATABASE) sp = spotipy.Spotify(auth_manager=SpotifyClientCredentials( client_id=config.SPOTIFY_CLIENT_ID, client_secret=config.SPOTIFY_CLIENT_SECRET)) def generate_barplot(x, y, color, xrotation=0, tick_intervals=[], xlabel="", ylabel=""): fig = Figure(figsize=(16, 6)) ax = fig.subplots()
def step_impl(context): balance = Decimal(100) account = Account(balance) name = "pierre-jean" context.client = Client(name, account)
def get_client(): client = Client(service_host=os.getenv('MARKET_SERVICE_HOST')) # health check client.health_check() return client
if __name__ == '__main__': from app.client import Client args = Client.args() Client(agent_type=args.type).run()
from app.client import Client from app.utils import parse_args, check_params, setup_logging if __name__ == '__main__': args = parse_args() print('Downloading wallpapers with arguments:') for arg in vars(args): print("{0:<15} {1:<15}".format(arg, getattr(args, arg))) start = time.time() if not check_params(args): logging.error(f'Program params wasn\'t correct!') exit(1) setup_logging(args.log_file, args.verbose) num_processes = max(multiprocessing.cpu_count() - 1, 1) client = Client( path=args.path, num_processes=num_processes, start_time=args.start_time, end_time=args.end_time, resolution=args.resolution, timeout=args.timeout ).prepare().run() logging.info(f'Program execution time: {time.time() - start} s') print(f'Downloading was finished in {int(time.time() - start)} s')
#/usr/bin/env python3 import logging logging.basicConfig(level=logging.DEBUG) logging.info(' * main.py * ') # this creates module-level loggers in client.py from app.client import Client logging.info(" * main.py: Client().greet() ") Client().greet()
#!/usr/bin/env python import os from app.client import Client badge = """ ####### ####### ### # # # ###### # ## ##### # # ###### ##### ### #### # # # # # # # # # ## ## # # # # # # ###### ##### ##### # # # # # ## # ##### # # # #### # # # # # ###### ##### # # # ##### # # # # # # # # # # # # # # # # # # # # ###### # # # # # # # ###### # # #### # # ## ## ## ##### # # ###### ##### # # # # # # # # # # # # # # # # # # # #### ##### # # # ###### ##### # # # # # # # # # # # # # # # # # # # # # # ###### # """ if __name__ == "__main__": print(badge) Client(service_host=os.getenv('MARKET_SERVICE_HOST')).start()
def setUp(self): self.client = Client() self.project_name = "nombre"