How to use url_path method in tempest

Best Python code snippet using tempest_python

BinanceAPI.py

Source:BinanceAPI.py Github

copy

Full Screen

1import hashlib2import hmac3import time4from urllib.parse import urlencode5import requests6# Simple support binance rest api7class Binance:8 """9 General class with mandatory params API or FAPI pub. and secret key.10 public_key=pub_val, secret_key=secret_val11 """12 def __init__(self, public_key, secret_key):13 self.PUBLIC_KEY = public_key14 self.SECRET_KEY = secret_key15 self.BASE_URL = "https://api.binance.com" # BASE URL16 self.BASE_URL_FAPI = "https://fapi.binance.com"17 self.recv = True18 def return_api_keys(self):19 return "{} - {}".format(self.PUBLIC_KEY, self.SECRET_KEY)20 def sha256(self, data):21 return hmac.new(self.SECRET_KEY.encode('utf-8'), data.encode('utf-8'), digestmod=hashlib.sha256).hexdigest()22 def server_time(self):23 url_path = "/api/v3/time"24 return self.public_api_query("GET", url_path)25 def get_timestamp(self):26 return int(time.time() * 1000)27 def _request(self, method, url, headers):28 response = requests.request(method, url, headers=headers)29 return response30 def private_api_query(self, method, url_path, payload: dict = None, fapi=False):31 headers = {32 'Content-Type': 'application/json;charset=utf-8',33 'X-MBX-APIKEY': self.PUBLIC_KEY34 }35 if self.recv is True:36 payload.update(recvWindow=10000)37 payload = urlencode(sorted(payload.items()))38 if payload:39 payload = f"{payload}&timestamp={self.get_timestamp()}"40 else:41 payload = f"timestamp={self.get_timestamp()}"42 if fapi is True:43 full_url = self.BASE_URL_FAPI + url_path + '?' + payload + '&signature=' + self.sha256(payload)44 else:45 full_url = self.BASE_URL + url_path + '?' + payload + '&signature=' + self.sha256(payload)46 print(full_url)47 return self._request(method, full_url, headers)48 def public_api_query(self, method, url_path, payload={}, fapi=False):49 headers = {50 'Content-Type': 'application/json;charset=utf-8'51 }52 payload = urlencode(sorted(payload.items()))53 if fapi is True:54 full_url = self.BASE_URL_FAPI + url_path + '?' + payload55 else:56 full_url = self.BASE_URL + url_path + '?' + payload57 # return full_url58 return self._request(method, full_url, headers)59 def create_order(self, params):60 """61 symbol STRING YES\n62 side ENUM YES\n63 type ENUM YES\n64 timeInForce ENUM NO\n65 quantity DECIMAL NO (If limit - YES)\n66 quoteOrderQty DECIMAL NO\n67 price DECIMAL NO (If limit - YES)\n68 newClientOrderId STRING NO\n69 stopPrice DECIMAL NO\n70 icebergQty DECIMAL NO\n71 newOrderRespType ENUM NO\n72 recvWindow LONG NO\n73 timestamp LONG YES74 """75 url_path = '/api/v3/order'76 return self.private_api_query('POST', url_path, params)77 def cancel_order(self, params):78 """79 MANDATORY:\n80 symbol STRING YES\n81 orderId LONG YES\n82 origClientOrderId STRING NO\n83 newClientOrderId STRING NO\n84 recvWindow LONG NO\n85 timestamp LONG YES\n86 """87 url_path = '/api/v3/order'88 return self.private_api_query('DELETE', url_path, params)89 def cancel_all_orders(self, **kwargs):90 url_path = '/api/v3/openOrders'91 return self.private_api_query('DELETE', url_path, kwargs)92 def query_order(self, **params):93 """94 MANDATORY:\n95 * symbol STRING YES\n96 * orderId LONG NO\n97 * origClientOrderId STRING NO\n98 * recvWindow LONG NO\n99 * timestamp LONG YES\n100 """101 url_path = "/api/v3/order"102 return self.private_api_query('GET', url_path, params)103 def open_orders(self, **kwargs):104 # active, canceled, filled orders105 url_path = '/api/v3/openOrders'106 return self.private_api_query('GET', url_path, kwargs)107 def get_account_info(self, url_path='/api/v3/account'):108 return self.private_api_query('GET', url_path)109 def current_open_orders(self, **kwargs):110 """111 MANDATORY:\n112 * symbol STRING NO\n113 * recvWindow LONG NO\n114 * timestamp LONG YES\n115 """116 url_path = '/api/v3/openOrders'117 return self.private_api_query('GET', url_path)118 def query_margin_acc_open_orders(self, **kwargs):119 url_path = '/sapi/v1/margin/openOrders'120 return self.private_api_query('GET', url_path, kwargs)121 def order_book(self, **params):122 """123 symbol STRING YES\n124 limit INT NO (Default 100)\n125 params = {'symbol': 'YFIBTC', 'limit': 5-100}126 """127 url_path = "/api/v3/depth"128 p = params129 return self.public_api_query('GET', url_path, p)130 def account_trade_list(self, **params):131 """132 MANDATORY:\n133 * symbol - YES\n134 * stratTime - NO\n135 * endTime - NO\n136 * fromId - NO\n137 * limit - NO (default 500, max 1000)\n138 * recWindow - NO\n139 * timestamp - YES140 """141 url_path = "/api/v3/myTrades"142 return self.private_api_query('GET', url_path, params)143 def all_orders(self, **params):144 """145 symbol STRING YES\n146 orderId LONG NO\n147 startTime LONG NO\n148 endTime LONG NO\n149 limit INT NO Default 500; max 1000.\n150 recvWindow LONG NO\n151 timestamp LONG YES\n152 """153 url_path = "/api/v3/allOrders"154 return self.private_api_query('GET', url_path, params)155 def candlestick_data(self, **params):156 """157 **symbol** STRING YES\n158 **interval** ENUM YES\n159 **startTime** LONG NO\n160 **endTime** LONG NO\n161 **limit** INT NO Default 500; max 1000.\n162 -------------------\n163 Example:164 [\n165 1613656800000, // Open time [0]\n166 "0.13813000", // Open[1]\n167 "0.14000000", // High[2]\n168 "0.12882000", // Low[3]\n169 "0.13318000", // Close[4]\n170 "12167135.1", // Volume[5]\n171 1613660399999, // Close time[6]\n172 "1626878.46196500", // Quote asset[7]\n173 4835, // Numb of trade[8]\n174 "3637996.5", // Taker buy base asset vol[9]\n175 "491470.141585", // Taker buy quote asset vol[10]\n176 "0" // Ignore[11]\n177 ]178 """179 url_path = "/api/v3/klines"180 return self.public_api_query('GET', url_path, params)181 def test_connctivity(self):182 url_path = "/api/v3/ping"183 return self.public_api_query("GET", url_path)184 def ticker_price_change_statisrics24h(self, **params):185 """186 symbol: YES/NO187 """188 url_path = "/api/v3/ticker/24hr"189 return self.public_api_query("GET", url_path, params)190 def fapi_balance(self):191 url_path = "/fapi/v2/balance"192 return self.private_api_query("GET", url_path, fapi=True)193 def fapi_order_book(self, **params):194 url_path = "/fapi/v1/depth"195 return self.public_api_query("GET", url_path, params, fapi=True)196 def fapi_new_order(self, **params):197 url_path = "/fapi/v1/order"198 return self.private_api_query("POST", url_path, params, fapi=True)199 def fapi_query_order(self, **params):200 url_path = "/fapi/v1/order"201 return self.private_api_query("GET", url_path, params, fapi=True)202 def fapi_all_orders(self, **params):203 url_path = "/fapi/v1/allOrders"204 return self.private_api_query("GET", url_path, params, fapi=True)205 def fapi_current_all_open_orders(self, **params):206 '''207 "/fapi/v1/openOrders"208 https://binance-docs.github.io/apidocs/futures/en/#current-all-open-orders-user_data209 '''210 url_path = "/fapi/v1/openOrders"211 return self.private_api_query("GET", url_path, params, fapi=True)212 def fapi_query_current_order(self, **params):213 '''214 "/fapi/v1/openOrder"215 https://binance-docs.github.io/apidocs/futures/en/#query-current-open-order-user_data216 '''217 url_path = "/fapi/v1/openOrder"218 return self.private_api_query("GET", url_path, params, fapi=True)219 def fapi_position_info_v2(self, **params):220 url_path = "/fapi/v1/positionRisk"221 return self.private_api_query("GET", url_path, params, fapi=True)222 def fapi_klines(self, **params):223 url_path = "/fapi/v1/klines"224 return self.public_api_query("GET", url_path, params, fapi=True)225 def fapi_exchange_info(self, **params):226 url_path = "/fapi/v1/exchangeInfo"227 return self.public_api_query("GET", url_path, params, fapi=True)228 def fapi_cancel_all_orders(self, **params):229 url_path = "/fapi/v1/allOpenOrders"230 return self.private_api_query("DELETE", url_path, params, fapi=True)231 def fapi_account_balance(self, **params):232 url_path = "/fapi/v2/balance"233 return self.private_api_query("GET", url_path, params, fapi=True)234 def fapi_listen_key(self, **params):235 url_path = "/fapi/v1/listenKey"236 return self.private_api_query("POST", url_path, params, fapi=True)237 def fapi_keepalive_key(self, **params):238 url_path = "/fapi/v1/listenKey"239 return self.private_api_query("PUT", url_path, params, fapi=True)240 def fapi_close_key(self, **params):241 url_path = "/fapi/v1/listenKey"242 return self.private_api_query("DELETE", url_path, params, fapi=True)243 def fapi_aggregate_trade_list(self, **params):244 url_path = "/fapi/v1/aggTrades"245 return self.public_api_query("GET", url_path, params, fapi=True)246 def fapi_server_time(self):247 url_path = "/fapi/v1/time"...

Full Screen

Full Screen

unit_test.py

Source:unit_test.py Github

copy

Full Screen

...85 assert Queries().var.by_sources('source-1', 'source-2').url_path == '/var/src/source-1,source-2'86 assert Queries().var.by_sources('source-1').observed.url_path == '/var/src/source-1/observed'87 assert Queries().var.by_sources('source-1').forecast.url_path == '/var/src/source-1/forecast'88 @staticmethod89 def test_create_aoi_url_path():90 operation = Transactions()\91 .add_aoi\92 .for_user("fake-user-name")\93 .with_name("fake-aoi-id")\94 .with_description("fake-aoi-name")\95 .with_category("fake-category-name")96 assert operation.url_path == '/aoi/user/fake-user-name/fake-aoi-id'97 @staticmethod98 def test_delete_aoi_url_path():99 operation = Transactions()\100 .delete_aoi\101 .from_user("fake-user-name")\102 .with_aoi("fake-aoi-id")103 assert operation.url_path == '/aoi/user/fake-user-name/fake-aoi-id'104 @staticmethod105 def test_create_subscription_url_path():106 operation = Transactions()\107 .periodic_subsc\108 .for_user("fake-user-name")\109 .with_variable("fake-var-name")\110 .with_operation("fake-oper-name")\111 .with_aoi("fake-aoi-name")112 assert operation.url_path == '/subsc/user/fake-user-name'113 @staticmethod114 def test_delete_subscription_url_path():115 operation = Transactions()\116 .unsubscribe\117 .from_user("fake-user-name")\118 .with_subsc("fake-subsc-id")119 assert operation.url_path == '/subsc/user/fake-user-name/fake-subsc-id'120if __name__ == '__main__':...

Full Screen

Full Screen

api.py

Source:api.py Github

copy

Full Screen

1#2# Copyright (C) 2019 Ocom Software- All Rights Reserved3# Unauthorized copying of this file, via any medium is strictly prohibited4# Proprietary and confidential5# Written by Ocom Software <licence@ocom.com.au, 20196#7#8from ocom.tests import api9class AuthTokenApi(api.AuthTokenApiEndpoint):10 pass11class JobApi(api.ApiEndpoint):12 alias = "Job API"13 url_path = '/api/job/'14class SubbieApi(api.ApiEndpoint):15 alias = "Subbie API"16 url_path = '/api/subbie/'17class SupervisorApi(api.ApiEndpoint):18 alias = "Supervisor API"19 url_path = '/api/supervisor/'20class ClientApi(api.ApiEndpoint):21 alias = "Client API"22 url_path = '/api/client/'23class FilesApi(api.ApiEndpoint):24 alias = "Files API"25 url_path = '/api/files/'26class NotesApi(api.ApiEndpoint):27 alias = "Notes API"28 url_path = '/api/notes/'29class CodeJobTypeApi(api.ApiEndpoint):30 alias = "CodeJobType API"31 url_path = '/api/code_job_type/'32class CodeSubbieTypeApi(api.ApiEndpoint):33 alias = "CodeSubbieType API"34 url_path = '/api/code_subbie_type/'35class CodePavingColourApi(api.ApiEndpoint):36 alias = "CodePavingColour API"37 url_path = '/api/code_paving_colour/'38class CodePavingTypeApi(api.ApiEndpoint):39 alias = "CodePavingType API"40 url_path = '/api/code_paving_type/'41class CodeRepairTypeApi(api.ApiEndpoint):42 alias = "CodeRepairType API"43 url_path = '/api/code_repair_type/'44class CodeDrainTypeApi(api.ApiEndpoint):45 alias = "CodeDrainType API"46 url_path = '/api/code_drain_type/'47class CodeFileTypeApi(api.ApiEndpoint):48 alias = "CodeFileType API"49 url_path = '/api/code_file_type/'50class CodeTaskTypeApi(api.ApiEndpoint):51 alias = "CodeTaskType API"52 url_path = '/api/code_task_type/'53class UserApi(api.ApiEndpoint):54 alias = "User API"55 url_path = '/api/users/'56class RoleApi(api.ApiEndpoint):57 alias = "Role API"...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tempest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful