MCPcopy Create free account
hub / github.com/sammchardy/python-binance / generate_function_code

Function generate_function_code

code-generator.py:371–440  ·  view source on GitHub ↗

Determines which _request_*_api function, path, and version to call based on the endpoint, generates a placeholder function to handle the specified method/endpoint. If the chosen request function is in NO_VERSION_FUNCTIONS, the code does not pass a 'version' argument. If no recogniz

(
    method, endpoint, type="sync", file_name="./binance/client.py"
)

Source from the content-addressed store, hash-verified

369
370
371def generate_function_code(
372 method, endpoint, type="sync", file_name="./binance/client.py"
373):
374 """
375 Determines which _request_*_api function, path, and version to call based on the endpoint,
376 generates a placeholder function to handle the specified method/endpoint.
377 If the chosen request function is in NO_VERSION_FUNCTIONS, the code does not pass a 'version' argument.
378 If no recognized prefix is found, returns an empty string.
379 If GET function will test if the endpoint is public or not
380 """
381 request_function, cleaned_endpoint, version = get_request_function_and_path(
382 endpoint
383 )
384
385 # If no recognized prefix, skip generating
386 if not request_function:
387 return ""
388
389 func_name = convert_to_function_name(method, endpoint)
390
391 # Build version argument if needed
392 version_string = ""
393 if request_function in NO_VERSION_FUNCTIONS or version is None:
394 # No version arg is needed
395 version_arg = None
396 elif request_function == "_request_api":
397 version_arg = f"v{version}"
398 else:
399 # If a version was found, pass version= the integer, else default to 1
400 version_arg = version if version else 1
401
402 if version_arg is not None:
403 if isinstance(version_arg, str):
404 version_string = f', version="{version_arg}"'
405 else:
406 version_string = f", version={version_arg}"
407
408 is_signed = check_function(method, request_function, cleaned_endpoint, version_arg)
409 if is_signed is None:
410 return
411
412 code_snippet = ""
413 if type == "sync":
414 code_snippet = f"""
415 def {func_name}(self, **params):
416 \"\"\"
417 Placeholder function for {method.upper()} {endpoint}.
418 Note: This function was auto-generated. Any issue please open an issue on GitHub.
419
420 :param params: parameters required by the endpoint
421 :type params: dict
422
423 :returns: API response
424 \"\"\"
425 return self.{request_function}("{method.lower()}", "{cleaned_endpoint}", signed={is_signed}, data=params{version_string})
426 """
427 elif type == "async":
428 code_snippet = f"""

Callers 1

mainFunction · 0.85

Calls 3

convert_to_function_nameFunction · 0.85
check_functionFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…