xync-client 0.0.16.dev3__tar.gz → 0.0.16.dev7__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. {xync_client-0.0.16.dev3/xync_client.egg-info → xync_client-0.0.16.dev7}/PKG-INFO +2 -2
  2. xync_client-0.0.16.dev7/tests/TestAgent.py +76 -0
  3. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7}/xync_client/Abc/Agent.py +6 -6
  4. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7}/xync_client/Htx/ex.py +1 -1
  5. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7}/xync_client/TgWallet/agent.py +68 -51
  6. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7}/xync_client/TgWallet/ex.py +4 -3
  7. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7/xync_client.egg-info}/PKG-INFO +2 -2
  8. xync_client-0.0.16.dev3/tests/TestAgent.py +0 -53
  9. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7}/.env.sample +0 -0
  10. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7}/.gitignore +0 -0
  11. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7}/.pre-commit-config.yaml +0 -0
  12. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7}/README.md +0 -0
  13. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7}/makefile +0 -0
  14. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7}/pyproject.toml +0 -0
  15. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7}/setup.cfg +0 -0
  16. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7}/tests/TestEx.py +0 -0
  17. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7}/tests/TestOrder.py +0 -0
  18. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7}/tests/_todo_refact/Binance/test_binance.py +0 -0
  19. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7}/tests/_todo_refact/Bybit/test_bybit.py +0 -0
  20. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7}/tests/_todo_refact/Bybit/test_bybit_p2p.py +0 -0
  21. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7}/tests/_todo_refact/Gate/test_gate.py +0 -0
  22. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7}/tests/_todo_refact/Htx/test_htx_p2p.py +0 -0
  23. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7}/tests/_todo_refact/Wallet/test_agent.py +0 -0
  24. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7}/tests/_todo_refact/Wallet/test_ex.py +0 -0
  25. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7}/tests/_todo_refact/__init__.py +0 -0
  26. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7}/tests/_todo_refact/_test_ex.py +0 -0
  27. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7}/xync_client/Abc/Auth.py +0 -0
  28. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7}/xync_client/Abc/Base.py +0 -0
  29. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7}/xync_client/Abc/BaseTest.py +0 -0
  30. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7}/xync_client/Abc/Ex.py +0 -0
  31. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7}/xync_client/Abc/Order.py +0 -0
  32. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7}/xync_client/Binance/__init__.py +0 -0
  33. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7}/xync_client/Binance/binance_async.py +0 -0
  34. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7}/xync_client/Binance/earn_api.py +0 -0
  35. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7}/xync_client/Binance/ex.py +0 -0
  36. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7}/xync_client/Binance/exceptions.py +0 -0
  37. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7}/xync_client/Binance/sapi.py +0 -0
  38. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7}/xync_client/Binance/web_c2c.py +0 -0
  39. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7}/xync_client/BingX/__init__.py +0 -0
  40. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7}/xync_client/BingX/base.py +0 -0
  41. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7}/xync_client/BingX/ex.py +0 -0
  42. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7}/xync_client/BingX/req.mjs +0 -0
  43. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7}/xync_client/BingX/sign.js +0 -0
  44. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7}/xync_client/BitGet/__init__.py +0 -0
  45. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7}/xync_client/BitGet/agent.py +0 -0
  46. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7}/xync_client/BitGet/ex.py +0 -0
  47. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7}/xync_client/BitGet/req.mjs +0 -0
  48. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7}/xync_client/Bybit/agent.py +0 -0
  49. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7}/xync_client/Bybit/ex.py +0 -0
  50. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7}/xync_client/Bybit/web_earn.py +0 -0
  51. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7}/xync_client/Bybit/web_p2p.py +0 -0
  52. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7}/xync_client/Gate/ex.py +0 -0
  53. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7}/xync_client/Gate/premarket.py +0 -0
  54. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7}/xync_client/Htx/agent.py +0 -0
  55. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7}/xync_client/Htx/earn.py +0 -0
  56. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7}/xync_client/KuCoin/pub.py +0 -0
  57. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7}/xync_client/KuCoin/web.py +0 -0
  58. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7}/xync_client/Okx/ex.py +0 -0
  59. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7}/xync_client/TgWallet/auth.py +0 -0
  60. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7}/xync_client/TgWallet/order.py +0 -0
  61. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7}/xync_client/TgWallet/pyro.py +0 -0
  62. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7}/xync_client/TgWallet/web.py +0 -0
  63. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7}/xync_client/__init__.py +0 -0
  64. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7}/xync_client/loader.py +0 -0
  65. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7}/xync_client.egg-info/SOURCES.txt +0 -0
  66. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7}/xync_client.egg-info/dependency_links.txt +0 -0
  67. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7}/xync_client.egg-info/requires.txt +0 -0
  68. {xync_client-0.0.16.dev3 → xync_client-0.0.16.dev7}/xync_client.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: xync-client
3
- Version: 0.0.16.dev3
3
+ Version: 0.0.16.dev7
4
4
  Author-email: Mike Artemiev <mixartemev@gmail.com>
5
5
  Project-URL: Homepage, https://gitlab.com/XyncNet/client
6
6
  Project-URL: Repository, https://gitlab.com/XyncNet/client
@@ -0,0 +1,76 @@
1
+ import logging
2
+
3
+ import pytest
4
+ from xync_schema.enums import ExStatus, ExAction
5
+ from xync_schema.models import Ex, TestEx, Fiat
6
+ from xync_schema.pydantic import FiatNew
7
+
8
+ from xync_client.Abc.BaseTest import BaseTest
9
+ from xync_client.Abc.Agent import BaseAgentClient
10
+ from xync_client.Abc.Base import BaseClient, DictOfDicts, ListOfDicts
11
+ from xync_client.TgWallet.ex import ExClient
12
+
13
+
14
+ @pytest.mark.asyncio(loop_scope="session")
15
+ class TestAgent(BaseTest):
16
+ @pytest.fixture(scope="class", autouse=True)
17
+ async def clients(self) -> tuple[BaseClient, BaseClient]:
18
+ exs = await Ex.filter(status__gt=ExStatus.plan).prefetch_related("agents__ex")
19
+ agents = [[ag for ag in ex.agents if ag.auth][:2] for ex in exs]
20
+ clients: list[tuple[BaseClient, BaseClient]] = [(t.client(), m.client()) for t, m in agents]
21
+ yield clients
22
+ [(await taker.close(), await maker.close()) for taker, maker in clients]
23
+
24
+ # 0
25
+ async def test_get_orders(self, clients: list[BaseAgentClient]):
26
+ for taker, maker in clients:
27
+ get_orders: ListOfDicts = await taker.get_orders()
28
+ ok = self.is_list_of_dicts(get_orders, False)
29
+ t, _ = await TestEx.update_or_create({"ok": ok}, ex_id=taker.agent.ex_id, action=ExAction.get_orders)
30
+ assert t.ok, "No get orders"
31
+ logging.info(f"{taker.agent.ex_id}:{ExAction.get_orders.name} - ok")
32
+
33
+ # 1
34
+ async def test_order_request(self, clients: list[BaseAgentClient]):
35
+ for taker, maker in clients:
36
+ await taker.agent.fetch_related("ex", "ex__agents")
37
+ ex_client: ExClient = taker.agent.ex.client()
38
+ ads = await ex_client.ads("NOT", "RUB", False)
39
+ for ad in ads:
40
+ order_request: dict | bool = await taker.order_request(ad["id"], ad["orderAmountLimits"]["min"])
41
+ if order_request:
42
+ break
43
+ ok = order_request["status"] == "SUCCESS"
44
+ t, _ = await TestEx.update_or_create({"ok": ok}, ex_id=taker.agent.ex_id, action=ExAction.order_request)
45
+ assert t.ok, "No get orders"
46
+ logging.info(f"{taker.agent.ex_id}:{ExAction.order_request.name} - ok")
47
+
48
+ # 25
49
+ async def test_my_fiats(self, clients: list[BaseAgentClient]):
50
+ for taker, maker in clients:
51
+ my_fiats: DictOfDicts = await taker.my_fiats()
52
+ ok = self.is_dict_of_dicts(my_fiats)
53
+ t, _ = await TestEx.update_or_create({"ok": ok}, ex_id=taker.agent.ex_id, action=ExAction.my_fiats)
54
+ assert t.ok, "No my fiats"
55
+ logging.info(f"{taker.agent.ex_id}:{ExAction.my_fiats.name} - ok")
56
+
57
+ # 26
58
+ async def test_fiat_new(self, clients: list[BaseAgentClient]):
59
+ for taker, maker in clients:
60
+ fn = FiatNew(cur_id=11, pm_id=22, detail="123456789")
61
+ fiat_new: Fiat.pyd() = await taker.fiat_new(fn)
62
+ ok = fiat_new["status"] == "SUCCESS"
63
+ t, _ = await TestEx.update_or_create({"ok": ok}, ex_id=taker.agent.ex_id, action=ExAction.fiat_new)
64
+ assert t.ok, "No add fiat"
65
+ logging.info(f"{taker.agent.ex_id}:{ExAction.fiat_new.name} - ok")
66
+
67
+ # 27
68
+ async def test_fiat_upd(self, clients: list[BaseAgentClient]):
69
+ for taker, maker in clients:
70
+ my_fiats = await taker.my_fiats()
71
+ fiats = [fiat for fiat in my_fiats.values()]
72
+ fiat_upd: Fiat.pyd() = await taker.fiat_upd(fiat_id=fiats[-1]["id"], detail="347890789")
73
+ ok = fiat_upd["status"] == "SUCCESS"
74
+ t, _ = await TestEx.update_or_create({"ok": ok}, ex_id=taker.agent.ex_id, action=ExAction.fiat_upd)
75
+ assert t.ok, "No upd fiat"
76
+ logging.info(f"{taker.agent.ex_id}:{ExAction.fiat_upd.name} - ok")
@@ -26,24 +26,24 @@ class BaseAgentClient(BaseAuthClient):
26
26
  @abstractmethod
27
27
  async def my_fiats(self, cur: Cur = None) -> DictOfDicts: ... # {fiat.exid: {fiat}}
28
28
 
29
- # 26: Создание
29
+ # 26: Создание реквизита моего платежного метода
30
30
  @abstractmethod
31
31
  async def fiat_new(self, fiat: FiatNew) -> Fiat.pyd(): ...
32
32
 
33
- # 27: Редактирование
33
+ # 27: Редактирование реквизита моего платежного метода
34
34
  @abstractmethod
35
35
  async def fiat_upd(self, fiat_id: int, detail: str, name: str = None) -> Fiat.pyd(): ...
36
36
 
37
- # 28: Удаление
37
+ # 28: Удаление реквизита моего платежного метода
38
38
  @abstractmethod
39
39
  async def fiat_del(self, fiat_id: int) -> bool: ...
40
40
 
41
41
  # # # Ad
42
- # 29: Список моих ad
42
+ # 29: Список моих объявлений
43
43
  @abstractmethod
44
44
  async def my_ads(self, status: AdStatus = None) -> ListOfDicts: ...
45
45
 
46
- # 30: Создание ad:
46
+ # 30: Создание объявления
47
47
  @abstractmethod
48
48
  async def ad_new(
49
49
  self,
@@ -60,7 +60,7 @@ class BaseAgentClient(BaseAuthClient):
60
60
  status: AdStatus = AdStatus.active,
61
61
  ) -> Ad.pyd(): ...
62
62
 
63
- # 31: Редактирование
63
+ # 31: Редактирование объявления
64
64
  @abstractmethod
65
65
  async def ad_upd(
66
66
  self,
@@ -67,7 +67,7 @@ async def main():
67
67
  _ = await init_db(PG_DSN, models, True)
68
68
  ex = await Ex.get(name="Htx")
69
69
  cl = ExClient(ex)
70
- await cl.cur_pms_map()
70
+ # await cl.cur_pms_map()
71
71
  await cl.set_pmcurexs()
72
72
  await cl.set_coinexs()
73
73
  await cl.close()
@@ -1,11 +1,10 @@
1
1
  from enum import StrEnum
2
- from typing import Literal
3
2
 
4
3
  from xync_schema.enums import AdStatus
5
4
 
6
- from xync_client.Abc.Base import ListOfDicts, MapOfIdsList, DictOfDicts
5
+ from xync_client.Abc.Base import ListOfDicts, DictOfDicts
7
6
  from xync_client.TgWallet.auth import AuthClient
8
- from xync_schema.models import User, Cur, Order, Coin, OrderStatus, Pmex, Fiat, Ad, Pm
7
+ from xync_schema.models import Cur, Coin, OrderStatus, Pmex, Fiat, Ad, Pm, Pmcur, Fiatex
9
8
  from xync_schema.pydantic import FiatNew
10
9
 
11
10
  from xync_client.Abc.Agent import BaseAgentClient
@@ -22,37 +21,43 @@ class Exceptions(StrEnum):
22
21
 
23
22
  class AgentClient(BaseAgentClient, AuthClient):
24
23
  # 0: Получшение ордеров в статусе status, по монете coin, в валюте coin, в направлении is_sell: bool
25
- async def get_orders(self, status: OrderStatus = OrderStatus.created, coin: Coin = None, cur: Cur = None, is_sell: bool = None) -> ListOfDicts:
24
+ async def get_orders(
25
+ self, status: OrderStatus = OrderStatus.created, coin: Coin = None, cur: Cur = None, is_sell: bool = None
26
+ ) -> ListOfDicts:
26
27
  orders = await self._post(
27
28
  "/p2p/public-api/v2/offer/order/history/get-by-user-id",
28
29
  {"offset": 0, "limit": 100, "filter": {"status": "ALL_ACTIVE"}}, # "limit": 20
29
30
  )
30
- return orders['data']
31
+ return orders["data"]
31
32
 
32
33
  # 1: [T] Запрос на старт сделки
33
34
  async def order_request(self, ad_id: int, amount: float) -> dict | bool:
34
- await self.agent.fetch_related('ex', 'ex__agents')
35
+ await self.agent.fetch_related("ex", "ex__agents")
35
36
  ex_client: ExClient = self.agent.ex.client()
36
37
  ad = await ex_client._get_ad(offer_id=ad_id)
37
38
  fiats = await self.my_fiats()
38
- fiats_pms = [fiat['id'] for fiat in fiats.values()]
39
- ad_pms = [pm['id'] for pm in ad['paymentDetails']]
40
- result = list(set(fiats_pms) & set(ad_pms))
39
+ fiats_pms = {fiat["paymentMethod"]["code"]: fiat["id"] for fiat in fiats.values()}
40
+ if not (pms := ad.get("paymentMethods")):
41
+ print(ad)
42
+ ad_pms = [pm["code"] for pm in pms]
43
+ result = list(set(fiats_pms.keys()) & set(ad_pms))
41
44
  if not result:
42
45
  return False
46
+ pid = result[0]
43
47
  request = await self._post(
44
48
  "/p2p/public-api/v2/offer/order/create-by-amount",
45
49
  {
46
50
  "offerId": ad_id,
47
- "paymentDetailsId": result[0],
48
- "amount": {
49
- "currencyCode": ad['orderAmountLimits']['currencyCode'],
50
- "amount": amount
51
- },
52
- "type": ad['type']
53
- }, 'data'
51
+ "paymentDetailsId": fiats_pms[pid],
52
+ "amount": {"currencyCode": ad["orderAmountLimits"]["currencyCode"], "amount": amount},
53
+ "type": ad["type"],
54
+ },
55
+ "data",
56
+ )
57
+ confirm = await self._post(
58
+ "/p2p/public-api/v2/offer/order/confirm", {"orderId": request["id"], "type": ad["type"]}
54
59
  )
55
- return request
60
+ return confirm
56
61
 
57
62
  # 25: Список реквизитов моих платежных методов
58
63
  async def my_fiats(self, cur: Cur = None) -> DictOfDicts:
@@ -60,9 +65,9 @@ class AgentClient(BaseAgentClient, AuthClient):
60
65
  fiats = {fiat["id"]: fiat for fiat in fiats["data"]}
61
66
  return fiats
62
67
 
63
- # 26: Создание
64
- async def fiat_new(self, fiat: FiatNew) -> Fiat.pyd():
65
- pmex = await Pmex.get_or_create(pm_id=fiat.pm_id, ex=self.agent.ex) # .prefetch_related('pm')
68
+ # 26: Создание реквизита моего платежного метода
69
+ async def fiat_new(self, fiat: FiatNew) -> Fiat:
70
+ pmex, _ = await Pmex.get_or_create(pm_id=fiat.pm_id, ex=self.agent.ex) # .prefetch_related('pm')
66
71
  cur = await Cur[fiat.cur_id]
67
72
  add_fiat = await self._post(
68
73
  "/p2p/public-api/v3/payment-details/create",
@@ -73,39 +78,46 @@ class AgentClient(BaseAgentClient, AuthClient):
73
78
  "attributes": {"version": "V1", "values": [{"name": "PAYMENT_DETAILS_NUMBER", "value": fiat.detail}]},
74
79
  },
75
80
  )
76
- return add_fiat
81
+ pmex = await Pmex.get(exid=add_fiat["data"]["paymentMethod"]["code"], ex=self.agent.ex)
82
+ cur = await Cur.get(ticker=add_fiat["data"]["currency"])
83
+ pmcur, _ = await Pmcur.get_or_create(cur=cur, pm_id=pmex.pm_id)
84
+ attrs = {a["name"]: a["value"] for a in add_fiat["data"]["attributes"]["values"]}
85
+ f, _ = await Fiat.update_or_create(
86
+ {"detail": attrs["PAYMENT_DETAILS_NUMBER"]}, pmcur=pmcur, user_id=self.agent.user_id
87
+ )
88
+ await Fiatex.update_or_create({"exid": add_fiat["data"]["id"]}, ex=self.agent.ex, fiat=f)
89
+ return f
77
90
 
78
- # 27: Редактирование
91
+ # 27: Редактирование реквизита моего платежного метода
79
92
  async def fiat_upd(self, fiat_id: int, detail: str, name: str = None) -> Fiat.pyd():
93
+ fiat = await Fiat.get(fiatexs__exid=fiat_id, fiatexs__ex=self.agent.ex).prefetch_related("pmcur")
94
+ pmex = await Pmex.get(pm_id=fiat.pmcur.pm_id)
80
95
  edit_fiat = await self._post(
81
96
  "/p2p/public-api/v3/payment-details/edit",
82
97
  {
83
98
  "id": fiat_id,
84
- # "paymentMethodCode": code_pms,
85
- # "currencyCode": cur,
99
+ "paymentMethodCode": pmex.exid,
100
+ "currencyCode": fiat.pmcur.cur_id,
86
101
  "name": name,
87
102
  "attributes": {"version": "V1", "values": [{"name": "PAYMENT_DETAILS_NUMBER", "value": detail}]},
88
103
  },
89
104
  )
90
105
  return edit_fiat
91
106
 
92
- # 28: Удаление
107
+ # 28: Удаление реквизита моего платежного метода
93
108
  async def fiat_del(self, fiat_id: int) -> bool:
94
109
  del_fiat = await self._post("/p2p/public-api/v3/payment-details/delete", {"id": fiat_id})
95
110
  return del_fiat
96
111
 
97
- # 29: Список моих ad
112
+ # 29: Список моих объявлений
98
113
  async def my_ads(self, status: AdStatus = None) -> ListOfDicts:
99
- mapping = {
100
- AdStatus.defActive: "INACTIVE",
101
- AdStatus.active: "ACTIVE"
102
- }
114
+ mapping = {AdStatus.defActive: "INACTIVE", AdStatus.active: "ACTIVE"}
103
115
  ads = await self._post(
104
116
  "/p2p/public-api/v2/offer/user-own/list", {"offset": 0, "limit": 20, "offerType": "SALE"}
105
117
  )
106
118
  return [ad for ad in ads["data"] if ad["status"] == mapping[status]] if status else ads
107
119
 
108
- # 30: Создание ad
120
+ # 30: Создание объявления
109
121
  async def ad_new(
110
122
  self,
111
123
  coin: Coin,
@@ -118,7 +130,7 @@ class AgentClient(BaseAgentClient, AuthClient):
118
130
  min_fiat: int = None,
119
131
  details: str = None,
120
132
  autoreply: str = None,
121
- status: AdStatus = AdStatus.active
133
+ status: AdStatus = AdStatus.active,
122
134
  ) -> Ad.pyd():
123
135
  create = await self._post(
124
136
  "/p2p/public-api/v2/offer/create",
@@ -126,7 +138,12 @@ class AgentClient(BaseAgentClient, AuthClient):
126
138
  "type": "SALE" if is_sell else "BUY",
127
139
  "initVolume": {"currencyCode": coin.ticker, "amount": f"{amount}"},
128
140
  "orderRoundingRequired": False,
129
- "price": {"type": "FIXED", "baseCurrencyCode": coin.ticker, "quoteCurrencyCode": cur.ticker, "value": price},
141
+ "price": {
142
+ "type": "FIXED",
143
+ "baseCurrencyCode": coin.ticker,
144
+ "quoteCurrencyCode": cur.ticker,
145
+ "value": price,
146
+ },
130
147
  "orderAmountLimits": {"min": min_fiat},
131
148
  "paymentConfirmTimeout": "PT15M" if is_sell else "PT3H",
132
149
  "comment": "",
@@ -136,29 +153,29 @@ class AgentClient(BaseAgentClient, AuthClient):
136
153
  return create
137
154
 
138
155
  async def _get_my_ad(self, offer_id: int):
139
- get_own = await self._post('/p2p/public-api/v2/offer/get-user-own/', {"offerId": offer_id})
140
- return get_own['data']
156
+ get_own = await self._post("/p2p/public-api/v2/offer/get-user-own/", {"offerId": offer_id})
157
+ return get_own["data"]
141
158
 
142
- # 31: Редактирование
159
+ # 31: Редактирование объявления
143
160
  async def ad_upd(
144
- self,
145
- offer_id: int,
146
- amount: int,
147
- pms: [Pm] = None,
148
- price: float = None,
149
- is_float: bool = None,
150
- min_fiat: int = None,
151
- details: str = None,
152
- autoreply: str = None,
153
- status: AdStatus = None,
161
+ self,
162
+ offer_id: int,
163
+ amount: int,
164
+ pms: [Pm] = None,
165
+ price: float = None,
166
+ is_float: bool = None,
167
+ min_fiat: int = None,
168
+ details: str = None,
169
+ autoreply: str = None,
170
+ status: AdStatus = None,
154
171
  ) -> Ad.pyd():
155
172
  ad = await self._get_my_ad(offer_id)
156
173
  upd = await self._post(
157
174
  "/p2p/public-api/v2/offer/edit",
158
175
  {
159
176
  "offerId": offer_id,
160
- "paymentConfirmTimeout": ad['paymentConfirmTimeout'],
161
- "type": ad['type'],
177
+ "paymentConfirmTimeout": ad["paymentConfirmTimeout"],
178
+ "type": ad["type"],
162
179
  "orderRoundingRequired": False,
163
180
  "price": {"type": "FIXED", "value": price},
164
181
  "orderAmountLimits": {"min": min_fiat},
@@ -172,17 +189,17 @@ class AgentClient(BaseAgentClient, AuthClient):
172
189
  # 32: Удаление
173
190
  async def ad_del(self, offer_id: int) -> bool:
174
191
  ad = await self._get_my_ad(offer_id)
175
- ad_del = await self._post("/p2p/public-api/v2/offer/delete", {"type": ad['type'], "offerId": offer_id})
192
+ ad_del = await self._post("/p2p/public-api/v2/offer/delete", {"type": ad["type"], "offerId": offer_id})
176
193
  return ad_del
177
194
 
178
195
  # 33: Вкл/выкл объявления
179
196
  async def ad_switch(self, offer_id: int, active: bool) -> bool:
180
197
  ad = await self._get_my_ad(offer_id)
181
198
  if active:
182
- active = await self._post("/p2p/public-api/v2/offer/activate", {"type": ad['type'], "offerId": offer_id})
199
+ active = await self._post("/p2p/public-api/v2/offer/activate", {"type": ad["type"], "offerId": offer_id})
183
200
  return active
184
201
  else:
185
- off = await self._post("/p2p/public-api/v2/offer/deactivate", {"type": ad['type'], "offerId": offer_id})
202
+ off = await self._post("/p2p/public-api/v2/offer/deactivate", {"type": ad["type"], "offerId": offer_id})
186
203
  return off
187
204
 
188
205
  # 34: Вкл/выкл всех объявлений
@@ -1,12 +1,13 @@
1
1
  from asyncio import run
2
2
  from x_model import init_db
3
+
3
4
  from xync_schema import models
4
5
  from xync_schema.models import Ex
5
6
 
7
+ from xync_client.loader import PG_DSN
8
+ from xync_client.Abc.Ex import BaseExClient
6
9
  from xync_client.Abc.Base import FlatDict, DictOfDicts, MapOfIdsList, ListOfDicts
7
10
  from xync_client.TgWallet.auth import AuthClient
8
- from xync_client.Abc.Ex import BaseExClient
9
- from xync_client.loader import PG_DSN
10
11
 
11
12
 
12
13
  class ExClient(BaseExClient, AuthClient):
@@ -67,7 +68,7 @@ async def main():
67
68
  await init_db(PG_DSN, models, True)
68
69
  tgex = await Ex.get(name="TgWallet").prefetch_related("agents", "agents__ex")
69
70
  cl = tgex.client()
70
- e = await cl.set_pmcurexs()
71
+ e = await cl.pms()
71
72
  print(e)
72
73
 
73
74
 
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: xync-client
3
- Version: 0.0.16.dev3
3
+ Version: 0.0.16.dev7
4
4
  Author-email: Mike Artemiev <mixartemev@gmail.com>
5
5
  Project-URL: Homepage, https://gitlab.com/XyncNet/client
6
6
  Project-URL: Repository, https://gitlab.com/XyncNet/client
@@ -1,53 +0,0 @@
1
- import logging
2
-
3
- import pytest
4
- from xync_schema.enums import ExStatus, ExAction
5
- from xync_schema.models import Ex, TestEx
6
-
7
- from xync_client.Abc.BaseTest import BaseTest
8
- from xync_client.Abc.Agent import BaseAgentClient
9
- from xync_client.Abc.Base import BaseClient, DictOfDicts, ListOfDicts
10
- from xync_client.TgWallet.ex import ExClient
11
-
12
-
13
- @pytest.mark.asyncio(loop_scope="session")
14
- class TestAgent(BaseTest):
15
- @pytest.fixture(scope="class", autouse=True)
16
- async def clients(self) -> list[BaseClient]:
17
- exs = await Ex.filter(status__gt=ExStatus.plan).prefetch_related("agents__ex")
18
- clients: list[BaseAgentClient] = [[ag for ag in ex.agents if ag.auth].pop().client() for ex in exs]
19
- yield clients
20
- [await cl.close() for cl in clients]
21
-
22
- # 0
23
- async def test_get_orders(self, clients: list[BaseAgentClient]):
24
- for client in clients:
25
- get_orders: ListOfDicts = await client.get_orders()
26
- ok = self.is_list_of_dicts(get_orders, False)
27
- t, _ = await TestEx.update_or_create({"ok": ok}, ex_id=client.agent.ex_id, action=ExAction.get_orders)
28
- assert t.ok, "No get orders"
29
- logging.info(f"{client.agent.ex_id}:{ExAction.get_orders.name} - ok")
30
-
31
- # 1
32
- async def test_order_request(self, clients: list[BaseAgentClient]):
33
- for client in clients:
34
- await client.agent.fetch_related('ex', 'ex__agents')
35
- ex_client: ExClient = client.agent.ex.client()
36
- ads = await ex_client.ads('USDT', 'RUB', True)
37
- for ad in ads:
38
- order_request: dict | bool = await client.order_request(ad['id'], ad['orderAmountLimits']['min'])
39
- if order_request:
40
- continue
41
- ok = isinstance(order_request, dict)
42
- t, _ = await TestEx.update_or_create({"ok": ok}, ex_id=client.agent.ex_id, action=ExAction.order_request)
43
- assert t.ok, "No get orders"
44
- logging.info(f"{client.agent.ex_id}:{ExAction.order_request.name} - ok")
45
-
46
- # 25
47
- async def test_my_fiats(self, clients: list[BaseAgentClient]):
48
- for client in clients:
49
- my_fiats: DictOfDicts = await client.my_fiats()
50
- ok = self.is_dict_of_dicts(my_fiats)
51
- t, _ = await TestEx.update_or_create({"ok": ok}, ex_id=client.agent.ex_id, action=ExAction.my_fiats)
52
- assert t.ok, "No my fiats"
53
- logging.info(f"{client.agent.ex_id}:{ExAction.my_fiats.name} - ok")