Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(client): add tests/ gift card API/ multiple fixes #1470

Merged
merged 84 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from 68 commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
0690e7e
first commit
pcriadoperez Nov 4, 2024
ddf5336
ruff check fix
pcriadoperez Nov 4, 2024
35de8fd
ruff format fix
pcriadoperez Nov 4, 2024
7e9d62c
fix lint warnings and error
pcriadoperez Nov 4, 2024
5672f01
type fix for 3.7
pcriadoperez Nov 4, 2024
2e54921
add testnet to test_Ws_api
pcriadoperez Nov 4, 2024
c437f56
change to testnet
pcriadoperez Nov 4, 2024
16dcd9a
ruff@
pcriadoperez Nov 4, 2024
2af3198
return test to async in test
pcriadoperez Nov 4, 2024
4a1d47c
format with ruff
carlosmiei Nov 4, 2024
752bfde
remove blank line
carlosmiei Nov 4, 2024
ae652c8
remove default tif
carlosmiei Nov 4, 2024
a9a962f
add ws_futures, refactor and add tests
pcriadoperez Nov 11, 2024
7f31a7e
lint
pcriadoperez Nov 11, 2024
0df07f1
fix tests
pcriadoperez Nov 11, 2024
a65a45b
ruff
pcriadoperez Nov 11, 2024
2239151
add tests
pcriadoperez Nov 11, 2024
9824956
remove utils
pcriadoperez Nov 11, 2024
3a62a2a
ruff format and pr comments
pcriadoperez Nov 11, 2024
37a585e
ruff format
pcriadoperez Nov 11, 2024
266e83d
fix live tests and add env vars for testnet
pcriadoperez Nov 11, 2024
894a504
merge
pcriadoperez Nov 11, 2024
bf0c0d5
github action
pcriadoperez Nov 11, 2024
3f0f26a
add tox env
pcriadoperez Nov 11, 2024
460e449
fix and test without tox
pcriadoperez Nov 12, 2024
e8dd66f
move tox command
pcriadoperez Nov 12, 2024
41a73f0
Merge branch 'crudWsv2' of https://github.com/pcriadoperez/python-bin…
pcriadoperez Nov 12, 2024
85a4ab0
fix test
pcriadoperez Nov 13, 2024
f0f58be
fix pyright
pcriadoperez Nov 13, 2024
1a96b52
type ignore
pcriadoperez Nov 13, 2024
af145d7
Merge branch 'crudWsv2' of https://github.com/pcriadoperez/python-bin…
pcriadoperez Nov 13, 2024
8031a02
jump test
pcriadoperez Nov 13, 2024
7fb9662
jump test until whitelist
pcriadoperez Nov 13, 2024
aecac03
Merge branch 'crudWsv2' of https://github.com/pcriadoperez/python-bin…
pcriadoperez Nov 13, 2024
a09476c
in progress
pcriadoperez Nov 15, 2024
057a53d
Merge branch 'master' of https://github.com/sammchardy/python-binance…
pcriadoperez Nov 15, 2024
6084a19
Merge branch 'crudWsv2' of https://github.com/pcriadoperez/python-bin…
pcriadoperez Nov 15, 2024
2d158fc
finish tests
pcriadoperez Nov 15, 2024
ff8ee83
remove print
carlosmiei Nov 16, 2024
dfa3b10
add examples
carlosmiei Nov 16, 2024
010cef5
improve docs
carlosmiei Nov 16, 2024
da52383
fix batch order
pcriadoperez Nov 17, 2024
faa6dfc
lint and format
pcriadoperez Nov 17, 2024
86998ff
Merge branch 'master' of https://github.com/sammchardy/python-binance…
pcriadoperez Nov 17, 2024
c5fda09
lint and format
pcriadoperez Nov 17, 2024
6c6b92f
Merge branch 'crudWsv2' of https://github.com/pcriadoperez/python-bin…
pcriadoperez Nov 17, 2024
6968df2
add tests for failed requests
pcriadoperez Nov 19, 2024
f23b030
fix for 3.7
pcriadoperez Nov 19, 2024
bfc2a0a
Merge branch 'crudWsv2' of https://github.com/pcriadoperez/python-bin…
pcriadoperez Nov 19, 2024
dfba408
Add gift cards endpoints and tests'
pcriadoperez Nov 19, 2024
8be3cc4
run tests in parallel
pcriadoperez Nov 19, 2024
02c83d9
run tests in parallel
pcriadoperez Nov 19, 2024
0b050af
reduce parallelism
pcriadoperez Nov 19, 2024
110628b
run github action sequentially
pcriadoperez Nov 19, 2024
8136583
change to 2 parallel
pcriadoperez Nov 19, 2024
8b525e7
fix action
pcriadoperez Nov 19, 2024
909fa0a
ruff format
pcriadoperez Nov 19, 2024
7a8839b
delete empty file
pcriadoperez Nov 19, 2024
3d739a5
Merge branch 'master' of https://github.com/sammchardy/python-binance…
pcriadoperez Nov 20, 2024
766b9f2
skip dust assets test
pcriadoperez Nov 20, 2024
2d7ae45
add missing force params
pcriadoperez Nov 20, 2024
60a4c3f
add rerun to reduce flakiness
pcriadoperez Nov 21, 2024
33befc1
remove change
pcriadoperez Nov 21, 2024
7f1b42e
distribute tests over file
pcriadoperez Nov 21, 2024
8effed7
fix test
pcriadoperez Nov 21, 2024
828b8c9
remove parallel test running
pcriadoperez Nov 21, 2024
d0f9837
increase delay
pcriadoperez Nov 21, 2024
c0f3ed0
update readme
carlosmiei Nov 21, 2024
c6f5f9d
improve get_asset_balance
carlosmiei Nov 21, 2024
d392bf6
add tests
carlosmiei Nov 21, 2024
ab00ff9
reformat
carlosmiei Nov 21, 2024
8892429
tmp: continue on error
carlosmiei Nov 22, 2024
8253f66
fix cancel test
pcriadoperez Nov 26, 2024
79fd3d5
ruff format
pcriadoperez Nov 26, 2024
5822269
Merge branch 'all-tests' of https://github.com/pcriadoperez/python-bi…
pcriadoperez Nov 26, 2024
6a1f2a6
Merge branch 'master' of https://github.com/sammchardy/python-binance…
pcriadoperez Nov 26, 2024
9576346
update headers
pcriadoperez Nov 26, 2024
80b486c
Merge branch 'master' of github.com:sammchardy/python-binance into al…
carlosmiei Nov 27, 2024
8514502
inject headers
carlosmiei Nov 27, 2024
b37deb1
add overridable headers
carlosmiei Nov 27, 2024
15e1c08
add headers tests
carlosmiei Nov 27, 2024
d124b57
format
carlosmiei Nov 27, 2024
cf6b50d
remove import
carlosmiei Nov 27, 2024
c1a4713
fix tests linting
carlosmiei Nov 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ jobs:
run: pip install ruff
- name: Lint code with Ruff
run: ruff check --output-format=github --target-version=py39 .
continue-on-error: false # TODO: delete once ruff errors are fixed
# - name: Check code formatting with Ruff
# run: ruff format --check .
# continue-on-error: false # TODO: delete once ruff errors are fixed
- name: Check code formatting with Ruff
run: ruff format --check .

build:
needs: lint
Expand All @@ -42,6 +40,7 @@ jobs:
TEST_FUTURES_API_KEY: "227719da8d8499e8d3461587d19f259c0b39c2b462a77c9b748a6119abd74401"
TEST_FUTURES_API_SECRET: "b14b935f9cfacc5dec829008733c40da0588051f29a44625c34967b45c11d73c"
strategy:
max-parallel: 1
matrix:
python: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
steps:
Expand Down
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ Features
- Vanilla Options
- Proxy support
- Support other domains (.us, .jp, etc)
- Support for the Gift Card API

Upgrading to v1.0.0+
--------------------
Expand Down
96 changes: 80 additions & 16 deletions binance/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,59 +131,64 @@ async def _request_api(
**kwargs,
):
uri = self._create_api_uri(path, signed, version)
return await self._request(method, uri, signed, **kwargs)
force_params = kwargs.pop("force_params", False)
return await self._request(method, uri, signed, force_params, **kwargs)

async def _request_futures_api(
self, method, path, signed=False, version=1, **kwargs
) -> Dict:
version = self._get_version(version, **kwargs)
uri = self._create_futures_api_uri(path, version=version)

return await self._request(method, uri, signed, False, **kwargs)
force_params = kwargs.pop("force_params", False)
return await self._request(method, uri, signed, force_params, **kwargs)

async def _request_futures_data_api(
self, method, path, signed=False, **kwargs
) -> Dict:
uri = self._create_futures_data_api_uri(path)

return await self._request(method, uri, signed, True, **kwargs)
force_params = kwargs.pop("force_params", True)
return await self._request(method, uri, signed, force_params, **kwargs)

async def _request_futures_coin_api(
self, method, path, signed=False, version=1, **kwargs
) -> Dict:
version = self._get_version(version, **kwargs)
uri = self._create_futures_coin_api_url(path, version=version)

return await self._request(method, uri, signed, False, **kwargs)
force_params = kwargs.pop("force_params", False)
return await self._request(method, uri, signed, force_params, **kwargs)

async def _request_futures_coin_data_api(
self, method, path, signed=False, version=1, **kwargs
) -> Dict:
version = self._get_version(version, **kwargs)
uri = self._create_futures_coin_data_api_url(path, version=version)

return await self._request(method, uri, signed, True, **kwargs)
force_params = kwargs.pop("force_params", True)
return await self._request(method, uri, signed, force_params, **kwargs)

async def _request_options_api(self, method, path, signed=False, **kwargs) -> Dict:
uri = self._create_options_api_uri(path)
force_params = kwargs.pop("force_params", True)

return await self._request(method, uri, signed, True, **kwargs)
return await self._request(method, uri, signed, force_params, **kwargs)

async def _request_margin_api(
self, method, path, signed=False, version=1, **kwargs
) -> Dict:
version = self._get_version(version, **kwargs)
uri = self._create_margin_api_uri(path, version)

return await self._request(method, uri, signed, **kwargs)
force_params = kwargs.pop("force_params", False)
return await self._request(method, uri, signed, force_params, **kwargs)

async def _request_papi_api(
self, method, path, signed=False, version=1, **kwargs
) -> Dict:
version = self._get_version(version, **kwargs)
uri = self._create_papi_api_uri(path, version)

return await self._request(method, uri, signed, **kwargs)
force_params = kwargs.pop("force_params", False)
return await self._request(method, uri, signed, force_params, **kwargs)

async def _request_website(self, method, path, signed=False, **kwargs) -> Dict:
uri = self._create_website_uri(path)
Expand Down Expand Up @@ -1768,17 +1773,28 @@ async def futures_create_order(self, **params):
params["newClientOrderId"] = self.CONTRACT_ORDER_PREFIX + self.uuid22()
return await self._request_futures_api("post", "order", True, data=params)

async def futures_modify_order(self, **params):
"""Modify an existing order. Currently only LIMIT order modification is supported.

https://binance-docs.github.io/apidocs/futures/en/#modify-order-trade

"""
return await self._request_futures_api("put", "order", True, data=params)

async def futures_create_test_order(self, **params):
return await self._request_futures_api("post", "order/test", True, data=params)

async def futures_place_batch_order(self, **params):
for order in params["batchOrders"]:
if "newClientOrderId" not in order:
order["newClientOrderId"] = self.CONTRACT_ORDER_PREFIX + self.uuid22()
query_string = urlencode(params)
query_string = query_string.replace("%27", "%22")
order = self._order_params(order)
query_string = urlencode(params).replace("%40", "@").replace("%27", "%22")
params["batchOrders"] = query_string[12:]
return await self._request_futures_api("post", "batchOrders", True, data=params)

return await self._request_futures_api(
"post", "batchOrders", True, data=params, force_params=True
)

async def futures_get_order(self, **params):
return await self._request_futures_api("get", "order", True, data=params)
Expand All @@ -1799,7 +1815,7 @@ async def futures_cancel_all_open_orders(self, **params):

async def futures_cancel_orders(self, **params):
return await self._request_futures_api(
"delete", "batchOrders", True, data=params
"delete", "batchOrders", True, data=params, force_params=True
)

async def futures_countdown_cancel_all(self, **params):
Expand Down Expand Up @@ -2029,7 +2045,7 @@ async def futures_coin_cancel_order(self, **params):

async def futures_coin_cancel_all_open_orders(self, **params):
return await self._request_futures_coin_api(
"delete", "allOpenOrders", signed=True, data=params
"delete", "allOpenOrders", signed=True, data=params, force_params=True
)

async def futures_coin_cancel_orders(self, **params):
Expand Down Expand Up @@ -3594,3 +3610,51 @@ async def ws_futures_account_status(self, **params):
https://developers.binance.com/docs/derivatives/usds-margined-futures/account/websocket-api/Account-Information
"""
return await self._ws_futures_api_request("account.status", True, params)

####################################################
# Gift Card API Endpoints
####################################################

async def gift_card_fetch_token_limit(self, **params):
return await self._request_margin_api(
"get", "giftcard/buyCode/token-limit", signed=True, data=params
)

gift_card_fetch_token_limit.__doc__ = Client.gift_card_fetch_token_limit.__doc__

async def gift_card_fetch_rsa_public_key(self, **params):
return await self._request_margin_api(
"get", "giftcard/cryptography/rsa-public-key", signed=True, data=params
)

gift_card_fetch_rsa_public_key.__doc__ = (
Client.gift_card_fetch_rsa_public_key.__doc__
)

async def gift_card_verify(self, **params):
return await self._request_margin_api(
"get", "giftcard/verify", signed=True, data=params
)

gift_card_verify.__doc__ = Client.gift_card_verify.__doc__

async def gift_card_redeem(self, **params):
return await self._request_margin_api(
"post", "giftcard/redeemCode", signed=True, data=params
)

gift_card_redeem.__doc__ = Client.gift_card_redeem.__doc__

async def gift_card_create(self, **params):
return await self._request_margin_api(
"post", "giftcard/createCode", signed=True, data=params
)

gift_card_create.__doc__ = Client.gift_card_create.__doc__

async def gift_card_create_dual_token(self, **params):
return await self._request_margin_api(
"post", "giftcard/buyCode", signed=True, data=params
)

gift_card_create_dual_token.__doc__ = Client.gift_card_create_dual_token.__doc__
1 change: 1 addition & 0 deletions binance/base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ def __init__(
def _get_headers(self) -> Dict:
headers = {
"Accept": "application/json",
"Content-Type": "application/json",
carlosmiei marked this conversation as resolved.
Show resolved Hide resolved
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", # noqa
}
if self.API_KEY:
Expand Down
Loading