Skip to content

Commit

Permalink
finish tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pcriadoperez committed Nov 15, 2024
1 parent 6084a19 commit 2d158fc
Show file tree
Hide file tree
Showing 13 changed files with 2,538 additions and 2,687 deletions.
8 changes: 8 additions & 0 deletions binance/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1766,6 +1766,14 @@ 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)

Expand Down
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",
"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
66 changes: 60 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
proxies = {}
proxy = os.getenv("PROXY")

proxy="http://51.83.140.52:16301"
proxy = "http://51.83.140.52:16301"
if proxy:
proxies = {"http": proxy, "https": proxy} # tmp: improve this in the future
else:
Expand All @@ -19,11 +19,11 @@
futures_api_key = os.getenv("TEST_FUTURES_API_KEY")
futures_api_secret = os.getenv("TEST_FUTURES_API_SECRET")
testnet = os.getenv("TEST_TESTNET", "true").lower() == "true"
api_key="u4L8MG2DbshTfTzkx2Xm7NfsHHigvafxeC29HrExEmah1P8JhxXkoOu6KntLICUc"
api_secret="hBZEqhZUUS6YZkk7AIckjJ3iLjrgEFr5CRtFPp5gjzkrHKKC9DAv4OH25PlT6yq5"
api_key = "u4L8MG2DbshTfTzkx2Xm7NfsHHigvafxeC29HrExEmah1P8JhxXkoOu6KntLICUc"
api_secret = "hBZEqhZUUS6YZkk7AIckjJ3iLjrgEFr5CRtFPp5gjzkrHKKC9DAv4OH25PlT6yq5"
testnet = True
futures_api_key="227719da8d8499e8d3461587d19f259c0b39c2b462a77c9b748a6119abd74401"
futures_api_secret="b14b935f9cfacc5dec829008733c40da0588051f29a44625c34967b45c11d73c"
futures_api_key = "227719da8d8499e8d3461587d19f259c0b39c2b462a77c9b748a6119abd74401"
futures_api_secret = "b14b935f9cfacc5dec829008733c40da0588051f29a44625c34967b45c11d73c"


# Configure logging for all tests
Expand All @@ -47,6 +47,11 @@ def client():
return Client(api_key, api_secret, {"proxies": proxies}, testnet=testnet)


@pytest.fixture(scope="function")
def optionsClient():
return Client(api_key, api_secret, {"proxies": proxies}, testnet=False)


@pytest.fixture(scope="function")
def futuresClient():
return Client(
Expand All @@ -66,6 +71,11 @@ def futuresClientAsync():
)


@pytest.fixture(scope="function")
def optionsClientAsync():
return AsyncClient(api_key, api_secret, https_proxy=proxy, testnet=False)


@pytest.fixture(autouse=True, scope="function")
def event_loop():
"""Create new event loop for each test"""
Expand All @@ -78,5 +88,49 @@ def event_loop():
loop.run_until_complete(asyncio.gather(*pending, return_exceptions=True))
loop.close()


def pytest_addoption(parser):
parser.addoption("--run-portfolio-tests", action="store_true", default=False, help="Run portfolio tests")
parser.addoption(
"--run-spot", action="store_true", default=True, help="Run margin tests"
)
parser.addoption(
"--run-futures", action="store_true", default=True, help="Run margin tests"
)
parser.addoption(
"--run-margin", action="store_true", default=False, help="Run margin tests"
)
parser.addoption(
"--run-portfolio",
action="store_true",
default=False,
help="Run portfolio tests",
)


def pytest_configure(config):
config.addinivalue_line("markers", "spot: mark a test as part of the spot tests")
config.addinivalue_line(
"markers", "futures: mark a test as part of the futures tests"
)
config.addinivalue_line(
"markers", "margin: mark a test as part of the margin tests"
)
config.addinivalue_line(
"markers", "portfolio: mark a test as part of the portfolio tests"
)


def pytest_collection_modifyitems(config, items):
skip_spot = pytest.mark.skip(reason="need --run-spot option to run")
skip_futures = pytest.mark.skip(reason="need --run-futures option to run")
skip_margin = pytest.mark.skip(reason="need --run-margin option to run")
skip_portfolio = pytest.mark.skip(reason="need --run-portfolio option to run")
for item in items:
if "spot" in item.keywords and not config.getoption("--run-spot"):
item.add_marker(skip_spot)
if "futures" in item.keywords and not config.getoption("--run-futures"):
item.add_marker(skip_futures)
if "margin" in item.keywords and not config.getoption("--run-margin"):
item.add_marker(skip_margin)
if "portfolio" in item.keywords and not config.getoption("--run-portfolio"):
item.add_marker(skip_portfolio)
Loading

0 comments on commit 2d158fc

Please sign in to comment.