xync-client 0.0.1__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 (45) hide show
  1. xync_client-0.0.1/.env.sample +15 -0
  2. xync_client-0.0.1/.gitignore +8 -0
  3. xync_client-0.0.1/.pre-commit-config.yaml +44 -0
  4. xync_client-0.0.1/PKG-INFO +20 -0
  5. xync_client-0.0.1/README.md +160 -0
  6. xync_client-0.0.1/makefile +27 -0
  7. xync_client-0.0.1/pyproject.toml +47 -0
  8. xync_client-0.0.1/setup.cfg +4 -0
  9. xync_client-0.0.1/tests/Screenshot_788.png +0 -0
  10. xync_client-0.0.1/tests/__init__.py +0 -0
  11. xync_client-0.0.1/tests/test_binance.py +8 -0
  12. xync_client-0.0.1/tests/test_bybit.py +83 -0
  13. xync_client-0.0.1/tests/test_bybit_p2p.py +193 -0
  14. xync_client-0.0.1/tests/test_gate.py +38 -0
  15. xync_client-0.0.1/tests/test_htx_p2p.py +0 -0
  16. xync_client-0.0.1/tests/test_wallet.py +193 -0
  17. xync_client-0.0.1/xync_client/Abc.py +205 -0
  18. xync_client-0.0.1/xync_client/Binance/binance_async.py +83 -0
  19. xync_client-0.0.1/xync_client/Binance/earn_api.py +83 -0
  20. xync_client-0.0.1/xync_client/Binance/sapi.py +265 -0
  21. xync_client-0.0.1/xync_client/Binance/web.py +29 -0
  22. xync_client-0.0.1/xync_client/Binance/web_c2c.py +227 -0
  23. xync_client-0.0.1/xync_client/BitGet/pub.py +44 -0
  24. xync_client-0.0.1/xync_client/Bybit/web_earn.py +83 -0
  25. xync_client-0.0.1/xync_client/Bybit/web_p2p.py +329 -0
  26. xync_client-0.0.1/xync_client/Gate/premarket.py +62 -0
  27. xync_client-0.0.1/xync_client/Gate/pub.py +64 -0
  28. xync_client-0.0.1/xync_client/Htx/web.py +72 -0
  29. xync_client-0.0.1/xync_client/Htx/web_c2c.py +18 -0
  30. xync_client-0.0.1/xync_client/KuCoin/pub.py +42 -0
  31. xync_client-0.0.1/xync_client/KuCoin/web.py +30 -0
  32. xync_client-0.0.1/xync_client/Okx/pub.py +43 -0
  33. xync_client-0.0.1/xync_client/Proto.py +139 -0
  34. xync_client-0.0.1/xync_client/TgWallet/p2p.py +216 -0
  35. xync_client-0.0.1/xync_client/TgWallet/pub.py +101 -0
  36. xync_client-0.0.1/xync_client/TgWallet/pyro.py +32 -0
  37. xync_client-0.0.1/xync_client/TgWallet/web.py +53 -0
  38. xync_client-0.0.1/xync_client/__init__.py +0 -0
  39. xync_client-0.0.1/xync_client/exceptions.py +27 -0
  40. xync_client-0.0.1/xync_client/loader.py +23 -0
  41. xync_client-0.0.1/xync_client.egg-info/PKG-INFO +20 -0
  42. xync_client-0.0.1/xync_client.egg-info/SOURCES.txt +43 -0
  43. xync_client-0.0.1/xync_client.egg-info/dependency_links.txt +1 -0
  44. xync_client-0.0.1/xync_client.egg-info/requires.txt +14 -0
  45. xync_client-0.0.1/xync_client.egg-info/top_level.txt +1 -0
@@ -0,0 +1,15 @@
1
+ BKEY=
2
+ BSEC=
3
+ HKEY=
4
+ HSEC=
5
+ HT=
6
+ OKXKEY=
7
+ OKXSEC=
8
+ OKXPSF=
9
+ BYT=
10
+ BYTP2P=
11
+ BYT2FA=
12
+ BYKEY=
13
+ BYSEC=
14
+ KUKEY=
15
+ KUSEC=
@@ -0,0 +1,8 @@
1
+ /.idea
2
+ /venv
3
+ /.env
4
+ .pytest_cache
5
+ __pycache__
6
+ /dist
7
+ /*.egg-info
8
+ /build
@@ -0,0 +1,44 @@
1
+ repos:
2
+ - repo: local
3
+ hooks:
4
+ # - id: pytest
5
+ # name: pytest
6
+ # entry: pytest tests -v
7
+ # language: python
8
+ # types: [python]
9
+ # verbose: true
10
+ # stages: [pre-commit]
11
+
12
+ - id: tag
13
+ name: tag
14
+ ### make tag with next ver only if "fix" in commit_msg or starts with "feat"
15
+ entry: bash -c 'grep -e "^feat:" -e "^fix:" .git/COMMIT_EDITMSG && make patch || exit 0'
16
+ language: system
17
+ verbose: true
18
+ pass_filenames: false
19
+ always_run: true
20
+ stages: [post-commit]
21
+
22
+ - id: build
23
+ name: build
24
+ ### build & upload package only for "main" branch push
25
+ entry: bash -c 'echo $PRE_COMMIT_LOCAL_BRANCH | grep /master && make twine || echo 0'
26
+ language: system
27
+ pass_filenames: false
28
+ verbose: true
29
+ require_serial: true
30
+ stages: [pre-push]
31
+
32
+ - repo: https://github.com/astral-sh/ruff-pre-commit
33
+ ### Ruff version.
34
+ rev: v0.6.4
35
+ hooks:
36
+ ### Run the linter.
37
+ - id: ruff
38
+ args: [--fix]
39
+ stages: [pre-commit]
40
+ ### Run the formatter.
41
+ - id: ruff-format
42
+ types_or: [python, pyi]
43
+ verbose: true
44
+ stages: [pre-commit]
@@ -0,0 +1,20 @@
1
+ Metadata-Version: 2.1
2
+ Name: xync-client
3
+ Version: 0.0.1
4
+ Author-email: Mike Artemiev <mixartemev@gmail.com>
5
+ Project-URL: Homepage, https://gitlab.com/XyncNet/client
6
+ Project-URL: Repository, https://gitlab.com/XyncNet/client
7
+ Requires-Python: >=3.12
8
+ Requires-Dist: asynchuobi
9
+ Requires-Dist: python-binance
10
+ Requires-Dist: pybit
11
+ Requires-Dist: pyotp
12
+ Requires-Dist: pyrogram
13
+ Requires-Dist: python-okx
14
+ Requires-Dist: xn-client
15
+ Requires-Dist: xync-schema
16
+ Provides-Extra: dev
17
+ Requires-Dist: build; extra == "dev"
18
+ Requires-Dist: python-dotenv; extra == "dev"
19
+ Requires-Dist: pytest-asyncio; extra == "dev"
20
+ Requires-Dist: twine; extra == "dev"
@@ -0,0 +1,160 @@
1
+ ## Order Flow:
2
+ - 0: Получшение заявок за заданное время, в статусе, по валюте, монете, направлению: `get_orders(stauts=OrderStatus.active, coin='USDT', cur='RUB', is_sell=False) => [order]`
3
+
4
+ ### Order Class description:
5
+ - 1: [T] Запрос на старт сделки (`order`) по чужому объявлению (`ad`) тейкером на сумму amount: `order_request(ad_id, amount) => order_id`
6
+ - 1N: [M] - Запрос мейкеру на сделку `order_request_ask => Order`
7
+ - 2: [T] Отмена запроса на сделку `cancel_request()`
8
+ - 2N: [M] - Уведомление об отмене запроса на сделку `request_canceled_notify`
9
+ - 3: [M] Одобрить запрос на сделку `accept_request()`
10
+ - 3N: [T] Уведомление об одобрении запроса на сделку `request_accepted_notify`
11
+ - 4: [M] Отклонить запрос на сделку `reject_request()`
12
+ - 4T: Бездействие 15мин `wait15m_on_order_request`
13
+ - 4N: [T] Уведомление об отклонении запроса на сделку `request_rejected_notify`
14
+ - 5: [B] Перевод сделки в состояние "оплачено", c отправкой чека `mark_payed(receipt)`
15
+ - 5N: [S] Уведомиление продавца об оплате `payed_notify`
16
+ - 6T: Бездействие 15мин `wait15m_on_order_creaed`
17
+ - 6: [B] Отмена сделки `cancel_order()`
18
+ - 6N: [S] Уведомиление продавцу об отмене оредера покупателем `order_canceled_notify`
19
+ - 7: [S] Подтвердить получение оплаты `confirm()`
20
+ - 7N: [B] Уведомиление покупателю об успешном завершении продавцом `order_completed_notify`
21
+ - 8T: Бездействие 10мин `wait10m_on_payed`
22
+ - 8N: [S,B] Уведомление о наступлении возможности подать аппеляцию `appeal_available_notify`
23
+ - 9,10: [S,B] Подать аппеляцию cо скриншотом/видео/файлом `start_appeal(file)`
24
+ - 9N,10N: [S,B] Уведомление о поданной на меня аппеляци `appeal_started`
25
+ - 11,12: [S,B] Встречное оспаривание полученной аппеляции cо скриншотом/видео/файлом `dispute_appeal(file)`
26
+ - 11N,12N: [S,B] Уведомление о встречном оспаривание поданной аппеляции `dispute_appeal(file)`
27
+ - 13T: [S] Бездействие продавца 3часа `seller_wait3h_on_appeal`
28
+ - 14T: [B] Бездействие покупателя 3часа `buyer_wait3h_on_appeal`
29
+ - 13N: [S,B] Уведомление о завершении сделки по аппеляции `order_completed_by_appeal`
30
+ - 14N: [B,S] Уведомление об отмене сделки по аппеляции `order_canceled_by_appeal`
31
+ - 15: [B,S] Отмена аппеляции`cancel_appeal()`
32
+ - 15N: [B,S] Уведомление об отмене аппеляции против меня `appeal_canceled`
33
+ - 16: Отправка сообщения юзеру в чат по ордеру с приложенным файлом `send_order_msg(msg:str, file=None)`
34
+ - 16N Получение сообщения в чате по ордеру `get_order_msg => (msg:str, file=None)`
35
+ - 17: Отправка сообщения по апелляции `send_appeal_msg(file, msg:str=None)`
36
+ - 17N: Получение сообщения по апелляции `get_appeal_msg => msg:str`
37
+
38
+ ### Scheme
39
+ ```mermaid
40
+ flowchart TD
41
+ T1((T)) -->|"`1: [T] **Creates**`"| 1[Requested]
42
+
43
+ 1 .->|1N: Request Notify|M1((M))
44
+
45
+ M1 ==>|"`3: [M] **Accepts**`"| 3[Created]
46
+
47
+ subgraph Rejected
48
+ 2(["[T] Request Canceled"]):::red
49
+ 4(["[M] Rejected"]):::red
50
+ end
51
+
52
+ M1 ==x|"`4: [M] **Rejects**`"| 4
53
+ 1 --x|4T: Wait 15m| 4
54
+ 1 ==x|"`2: [T] **Cancels**`"| 2
55
+
56
+ 2 .->|2N: Taker cancel\norder request| M2((M))
57
+ 4 .->|4N: Maker reject\norder request| T2((T))
58
+
59
+ 3 ==>|"`5: [B] **Marks: PAYED**<br>(with Receipt?)`"| 5[PAYED]
60
+ 3 .-> |3N: Request\nAcepted Notify| T3((T))
61
+ 3 ---x|6T: Delay 15m| 6(((by<br>buyer))):::red
62
+ 3 ===x|"`6: [B] **Cancels**`"| 6
63
+
64
+ Payed ==>|"`7: [S] **Confirms**`"| 7(((By<br>Seller))):::green
65
+ 7 .->|7N: Seller Completed order| B4((B))
66
+
67
+ S2 -->|Delay 3h| 13
68
+
69
+ subgraph Payed
70
+ subgraph Completed
71
+ direction TB
72
+ 13(((By\nAppeal))):::green
73
+ 7
74
+ end
75
+ 5 -->|8T: Wait 10m| 8(PAYED +10m)
76
+ 5 .-> |5N: Order\nPayed Notify| S1((S))
77
+ 15(Appeal Canceled)
78
+ 8 .->|8N: Appeal Available| B3((B))
79
+ 8 .->|8N: Appeal Available| S3((S))
80
+
81
+ B2 <-->|17,17N| SP
82
+ subgraph Appeal
83
+ subgraph ABB [By Buyer]
84
+ 10 .->|10N: Buyer started appeal| S2((S))
85
+ S2 ==>|"`12: **No! I've no payment**<br>(with Screenshot)`"|12{{"[B] Appeal\nDisputed"}}
86
+ end
87
+ SP((Sp))
88
+ subgraph ABS [By Seller]
89
+ 9 .->|9N: Seller started appeal| B2((B))
90
+ B2 ==>|"`11: **No! I've paid**<br>(with Receipt)`"|11{{"[S] Appeal\nDisputed"}}
91
+ end
92
+ S2 <-->|17,17N| SP
93
+ end
94
+ end
95
+
96
+ Payed ==x|"`6: [B] **Cancels**`"| 6
97
+ 6 .-> |6N: Buyer Canceled Order| S4((S))
98
+
99
+ B3 ==>|"`10: [B] **No release**<br>(with Receipt!)`"| 10{{Appeled<br>by Buyer}}
100
+ 15 <===|"`15: [B] **Cancels<br>appeal**`"| ABB
101
+ S3 ==>|"`9: [S] **No payment**<br>(with Screenshot)`"| 9{{Appeled<br>by Seller}}
102
+ 15 <===|"`15: [S] **Cancels<br>appeal**`"| ABS
103
+ 15 .->|15N: Appeal Canceled| B3
104
+ 15 .->|15N: Appeal Canceled| S3
105
+
106
+
107
+ B2 -->|Delay 3h| 14(((by<br>appeal))):::red
108
+ Appeal o-->|50%: Wait for<br>sup decision| 13
109
+ Appeal o-->|50%: Wait for<br>sup decision| 14
110
+
111
+
112
+ 13 .->|13N: Done by appeal| B4
113
+ 13 .->|13N: Done by appeal| S4
114
+ 14 .->|14N: Canceled by appeal| B4
115
+ 14 .->|14N: Canceled by appeal| S4
116
+
117
+ subgraph Canceled
118
+ direction TB
119
+ 6
120
+ 14
121
+ end
122
+
123
+ classDef green stroke:#0f0
124
+ classDef red stroke:#f00
125
+ ```
126
+ ###### Legend
127
+ ***[T] - Taker, [M] - Maker, [S] - Seller, [B] - Buyer***.<br>
128
+ *Clean digits (1, 2, ..)*: Simple outbound HTTP Requests;<br>
129
+ *N suffix (1N, 2N, ..)*: Inbound Notifications - from SSE/WS/Pyrogram client;<br>
130
+ *T suffix (4T, 8T, ..)*: Only Tests with idle waithing time.
131
+
132
+ ### Public
133
+ - 21: Список поддерживаемых валют тейкера `taker_curs() => [Cur]`
134
+ - 22: Список торгуемых монет (с ограничениям по валютам, если есть) `coins(cur:Cur=None) => [Coin]`
135
+ - 23: Список платежных методов по каждой валюте `pms(cur: Cur) => [Pm]`
136
+ - 24: Список объяв по (buy/sell, cur, coin, pm) `ads(coin: Coin, cur: Cur, is_sell: bool, pms:list[Pm]=None)`
137
+
138
+ ### Fiat
139
+ - 25: Список реквизитов моих платежных методов `my_fiats(cur:Cur=None) => [Fiat]`
140
+ - 26: Создание `fiat_new(cur:Cur, pm:Pm, detail:str, type:PmType=None)`
141
+ - 27: Редактирование `fiat_upd(detail:str=None, type:PmType=None)`
142
+ - 28: Удаление `fiat_del(fiat_id:int)`
143
+
144
+ ### Ad
145
+ - 29: Список моих ad
146
+ - 30: Создание ad: `ad_new(coin: Coin, cur:Cur, is_sell: bool, pms:[Pm], price:float, is_float:bool=True, min_fiat:int=None, details:str=None, autoreply:str=None, status:AdvStatus=AdvStatus.active)`
147
+ - 31: Редактирование `ad_upd(pms:[Pm]=None, price:float=None, is_float:bool=None, min_fiat:int=None, details:str=None, autoreply:str=None, status:AdvStatus=None)`
148
+ - 32: Удаление `ad_del()`
149
+ - 33: Вкл/выкл объявления `ad_switch() => result: bool`
150
+ - 34: Вкл/выкл всех объявлений `ads_switch() => result: bool`
151
+
152
+ ### User
153
+ - 35: Получить объект юзера по его ид `get_user(user_id) => user`
154
+ - 36: Отправка сообщения юзеру с приложенным файлом `send_user_msg(msg:str, file=None)`*
155
+ - 37: (Раз)Блокировать юзера `block_user(is_blocked:bool=True)`
156
+ - 38: Поставить отзыв юзеру `rate_user(positive:bool)`<br>
157
+ **Inbound:**
158
+ - 36N: Получение сообщения от юзера `get_user_msg => (msg:str, file=None)`
159
+ - 37N: Получение уведомления о (раз)блокировке юзером `got_blocked => is_blocked:bool`
160
+ - 38N: Получение уведомления о полученном отзыве `got_rated => (user_id:int, order_id:int)`
@@ -0,0 +1,27 @@
1
+ include .env
2
+ PACKAGE := xync_schema
3
+ VPYTHON := $(VENV)/bin/python
4
+
5
+ .PHONY: all install pre-commit test clean build twine patch
6
+
7
+ all:
8
+ make install test clean build
9
+
10
+ install: $(VENV)
11
+ $(VPYTHON) -m pip install -e .[dev]; make pre-commit
12
+ pre-commit: .pre-commit-config.yaml
13
+ pre-commit install -t pre-commit -t post-commit -t pre-push
14
+
15
+ test:
16
+ $(VPYTHON) -m pytest
17
+
18
+ clean: .pytest_cache dist $(PACKAGE).egg-info
19
+ rm -rf .pytest_cache dist/* $(PACKAGE).egg-info $(PACKAGE)/__pycache__ dist/__pycache__
20
+
21
+ build:
22
+ $(VPYTHON) -m build
23
+ twine: build dist
24
+ $(VPYTHON) -m twine upload dist/* --skip-existing
25
+
26
+ patch:
27
+ git tag `$(VPYTHON) -m setuptools_scm --strip-dev`; git push --tags --prune -f
@@ -0,0 +1,47 @@
1
+ [project]
2
+ name = "xync-client"
3
+ requires-python = ">=3.12"
4
+ authors = [
5
+ {name = "Mike Artemiev", email = "mixartemev@gmail.com"},
6
+ ]
7
+ dynamic = ["version"]
8
+
9
+ dependencies = [
10
+ "asynchuobi",
11
+ "python-binance",
12
+ "pybit",
13
+ "pyotp",
14
+ "pyrogram",
15
+ "python-okx",
16
+ "xn-client",
17
+ "xync-schema"
18
+ ]
19
+
20
+ [project.optional-dependencies]
21
+ dev = [
22
+ "build",
23
+ "python-dotenv",
24
+ "pytest-asyncio",
25
+ "twine",
26
+ ]
27
+
28
+ [project.urls]
29
+ Homepage = "https://gitlab.com/XyncNet/client"
30
+ Repository = "https://gitlab.com/XyncNet/client"
31
+
32
+ [tool.setuptools]
33
+ packages = ["xync_client"]
34
+
35
+ [build-system]
36
+ requires = ["setuptools>=64", "setuptools-scm[toml]>=8"]
37
+ build-backend = "setuptools.build_meta"
38
+ [tool.setuptools_scm]
39
+ version_scheme = "python-simplified-semver" # if "feature" in `branch_name` SEMVER_MINOR++ else SEMVER_PATCH++
40
+ local_scheme = "no-local-version"
41
+
42
+ [tool.ruff]
43
+ line-length = 120
44
+
45
+ [tool.pytest.ini_options]
46
+ asyncio_mode = "auto"
47
+ asyncio_default_fixture_loop_scope = "class" # , "session", "module", "package", "function"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
File without changes
@@ -0,0 +1,8 @@
1
+ from xync_client.Binance.web import Public
2
+
3
+
4
+ async def test_cur_filter():
5
+ bn = Public()
6
+ for cur in "RUB", "AZN", "GEL":
7
+ resp = await bn.get_pms_and_country_for_cur(cur)
8
+ assert len(resp[0]) and len(resp[1]), "No data"
@@ -0,0 +1,83 @@
1
+ from datetime import datetime
2
+ from uuid import uuid4
3
+ from pybit.unified_trading import HTTP
4
+
5
+ from xync_client.Bybit.web_earn import BybitEarn, type_map
6
+ from xync_client.loader import BYT, BYKEY, BYSEC
7
+
8
+ client = HTTP(
9
+ testnet=False,
10
+ api_key=BYKEY,
11
+ api_secret=BYSEC,
12
+ )
13
+
14
+
15
+ async def test_get_home_products():
16
+ bbt = BybitEarn(BYT)
17
+ for pt in type_map:
18
+ resp = await bbt.get_home_earn_products(pt.value)
19
+ assert len(resp[pt.name]), "No home products"
20
+
21
+
22
+ async def test_get_coins():
23
+ bbt = BybitEarn(BYT)
24
+ resp = await bbt.get_coins()
25
+ assert resp, "No coins"
26
+
27
+
28
+ async def test_get_eth():
29
+ bbt = BybitEarn(BYT)
30
+ resp = await bbt.get_product_detail()
31
+ assert resp, "No eth"
32
+
33
+
34
+ def test_get_rate():
35
+ resp = client.get_tickers(category="spot", symbol="TONUSDT")
36
+ assert float(resp["result"]["list"][0]["lastPrice"]) > 0
37
+
38
+
39
+ def test_send_coin_internal():
40
+ coin = "USDT"
41
+ old_sender_balance = client.get_coins_balance(
42
+ accountType="FUND",
43
+ coin=coin,
44
+ )["result"]["balance"][0]
45
+ # sender_id = 23477628
46
+ # receiver_id = 138687729
47
+ receiver_id = 69798104
48
+ sent_amount = 24.9266
49
+ assert float(old_sender_balance["transferBalance"]) >= sent_amount, "sender have not enough money"
50
+
51
+ trans_sent_id = client.withdraw(
52
+ coin=coin,
53
+ # chain=None,
54
+ address=str(receiver_id),
55
+ amount=str(sent_amount),
56
+ timestamp=int(datetime.now().timestamp() * 1000),
57
+ forceChain=2,
58
+ accountType="FUND",
59
+ )["result"]
60
+ new_sender_balance = client.get_coins_balance(
61
+ accountType="FUND",
62
+ coin=coin,
63
+ )["result"]["balance"][0]
64
+ assert (
65
+ trans_sent_id
66
+ and float(new_sender_balance["walletBalance"]) == float(old_sender_balance["walletBalance"]) - sent_amount
67
+ ), "transfer failed"
68
+
69
+
70
+ def test_send_coin_subaccount():
71
+ sender_id = 23477628
72
+ receiver_id = 69798104
73
+ sent_amount = 15.5
74
+ sent = client.create_universal_transfer( # its only for subaccount transfers
75
+ transferId=str(uuid4()),
76
+ coin="USDT",
77
+ amount=str(sent_amount),
78
+ fromMemberId=sender_id,
79
+ toMemberId=receiver_id,
80
+ fromAccountType="FUND",
81
+ toAccountType="FUND",
82
+ )["result"]
83
+ assert sent, "transfer failed"
@@ -0,0 +1,193 @@
1
+ from time import sleep
2
+
3
+ import pytest
4
+ from tortoise import Tortoise, connections
5
+ from tortoise.backends.asyncpg import AsyncpgDBClient
6
+ from xync_schema import models
7
+ from xync_schema.models import TestEx, ExAction, Pmcur
8
+
9
+ from xync_client.Bybit.web_p2p import BybitP2P, NoMakerException, AdsStatus
10
+ from xync_client.loader import BYTP2P, DSN
11
+
12
+ bybit_p2p = BybitP2P(headers={"cookie": "secure-token=" + BYTP2P})
13
+
14
+
15
+ @pytest.fixture(scope="module")
16
+ async def dbc() -> AsyncpgDBClient:
17
+ await Tortoise.init(db_url=DSN, modules={"models": [models]})
18
+ cn: AsyncpgDBClient = connections.get("default")
19
+ yield cn
20
+ await cn.close()
21
+
22
+
23
+ # получение валют (1)
24
+ async def test_get_currencies(dbc):
25
+ currencies = bybit_p2p.get_currencies()
26
+ Pmcur.update_or_create(
27
+ {},
28
+ )
29
+ ok = True if len(currencies) > 0 else False
30
+ await TestEx.update_or_create({"ok": ok}, ex_id=10, action=ExAction.all_curs_taker)
31
+ assert ok, "No currencies found"
32
+
33
+
34
+ # получение не тестовых монет торгуемых на p2p (2)
35
+ async def test_get_coins(dbc):
36
+ result_get_coins = bybit_p2p.get_coins()
37
+ ok = (
38
+ True
39
+ if len([c for c in result_get_coins["result"] if c["tokenType"] == "CHAIN_TOKEN" and not c["isTest"]]) > 0
40
+ else False
41
+ )
42
+ await TestEx.update_or_create({"ok": ok}, ex_id=10, action=ExAction.all_coins)
43
+ assert ok, "No coins found"
44
+
45
+
46
+ # получение платежных методов (3)
47
+ async def test_get_payment_methods(dbc):
48
+ result_get_payment_methods = bybit_p2p.get_payment_methods()
49
+ ok = True if len(result_get_payment_methods["result"]["paymentConfigVo"]) > 0 else False
50
+ await TestEx.update_or_create({"ok": ok}, ex_id=10, action=ExAction.all_pms)
51
+ assert ok, "No payment method found"
52
+
53
+
54
+ # получение первого объявления на покупку USDT за рубли (покупка - "side": "1", продажа - "side": "0") (4)
55
+ async def test_get_best_price(dbc):
56
+ all_ads = bybit_p2p.get_ads("USDT", "RUB")
57
+ ok1 = True if bybit_p2p.get_rate(all_ads) > 0 else False # "Ad's price USDT/RUB no found no Payeer, no Advcash"
58
+ ok2 = True if len(all_ads) > 0 else False
59
+ await TestEx.update_or_create({"ok": ok1 and ok2}, ex_id=10, action=ExAction.all_ads)
60
+ assert ok2, "Ad's price USDT/RUB no found"
61
+
62
+
63
+ # получение платежных методов залогиненного юзера (5)
64
+ async def test_get_user_pay_methods(dbc):
65
+ result_get_user_pay_methods = bybit_p2p.get_user_pay_methods()
66
+ ok = True if len(result_get_user_pay_methods) > 0 else False
67
+ await TestEx.update_or_create({"ok": ok}, ex_id=10, action=ExAction.fiats)
68
+ assert ok, "No payment method requisites found"
69
+
70
+
71
+ # создание моего платежного реквизита (fiat) (6)
72
+ async def test_create_user_payment_methods(dbc):
73
+ result = bybit_p2p.create_payment_method(379, "ЕЛЕНА АРТЕМЬЕВА", "42454342536453")
74
+ ok = True if result["ret_msg"] == "SUCCESS" else False
75
+ await TestEx.update_or_create({"ok": ok}, ex_id=10, action=ExAction.fiat_new)
76
+ assert ok, "Fiat isn't created: " + result["ret_msg"]
77
+
78
+
79
+ # редактирование моего платежного реквизита (fiat) (7)
80
+ async def test_update_user_payment_methods(dbc):
81
+ result = bybit_p2p.update_payment_method("ЕЛЕНА АРТЕМЬЕВА", "424543425364532")
82
+ if result["ret_msg"] != "SUCCESS":
83
+ print("Wrong 2fa on Fiat updating, wait 10 secs and retry..")
84
+ sleep(10)
85
+ return await test_update_user_payment_methods(dbc)
86
+ await TestEx.update_or_create({"ok": True}, ex_id=10, action=ExAction.fiat_upd)
87
+ assert True, "Fiat isn't updated: " + result["ret_msg"]
88
+
89
+
90
+ # удаление моего платежного реквизита (fiat) (8)
91
+ async def test_delete_user_payment_methods(dbc):
92
+ last_fiat = bybit_p2p.get_payment_method()
93
+ result = bybit_p2p.delete_payment_method(last_fiat["id"])
94
+ if result["ret_msg"] != "SUCCESS":
95
+ print("Wrong 2fa on Fiat deleting, wait 10 secs and retry..")
96
+ sleep(10)
97
+ return await test_delete_user_payment_methods(dbc)
98
+ await TestEx.update_or_create({"ok": True}, ex_id=10, action=ExAction.fiat_del)
99
+ assert True, "Fiat isn't deleted: " + result["ret_msg"]
100
+
101
+
102
+ # получение списка объявлений залогиненного юзера (9)
103
+ async def test_get_user_ads(dbc):
104
+ result_get_user_ads = bybit_p2p.get_user_ads()
105
+ ok = True if len(result_get_user_ads) >= 0 else False
106
+ await TestEx.update_or_create({"ok": ok}, ex_id=10, action=ExAction.my_ads)
107
+ assert ok, "No ads found"
108
+
109
+
110
+ # создание/редактирование/удаление объявления (10,11,12)
111
+ async def test_delete_ad(dbc):
112
+ try:
113
+ token = bybit_p2p.get_security_token_create()
114
+ bybit_p2p.post_create_ad(token)
115
+ token = bybit_p2p.get_security_token_update()
116
+ bybit_p2p.post_update_ad(token)
117
+ result_delete_ad = bybit_p2p.delete_ad(bybit_p2p.last_ad_id[0])
118
+ except NoMakerException as e:
119
+ print(e.args[0]["ret_msg"])
120
+ result_delete_ad = e.args[0]
121
+ ok = True if result_delete_ad["ret_msg"] == "SUCCESS" else False
122
+ await TestEx.update_or_create({"ok": ok}, ex_id=10, action=ExAction.ad_new)
123
+ await TestEx.update_or_create({"ok": ok}, ex_id=10, action=ExAction.ad_upd)
124
+ await TestEx.update_or_create({"ok": ok}, ex_id=10, action=ExAction.ad_del)
125
+ assert ok, "Ad isn't deleted"
126
+
127
+
128
+ async def _switch_ad(new_status: AdsStatus, dbc):
129
+ result = bybit_p2p.switch_ads(new_status)
130
+ ok = True if result["ret_msg"] == "SUCCESS" else False
131
+ action = {AdsStatus.REST: ExAction.ad_off, AdsStatus.WORKING: ExAction.ad_on}[new_status]
132
+ await TestEx.update_or_create({"ok": ok}, ex_id=10, action=action)
133
+ return ok
134
+
135
+
136
+ # выключение/включение объявления (13,14)
137
+ async def test_on_off_ads(dbc):
138
+ old_status = AdsStatus[bybit_p2p.online_ads()]
139
+ new_status = AdsStatus(int(not bool(old_status.name)))
140
+ ok = await _switch_ad(new_status, dbc)
141
+ assert ok, "Ads no " + new_status.name
142
+ # возвращаем как было:
143
+ ok = await _switch_ad(old_status, dbc)
144
+ assert ok, "Ads no " + old_status.name
145
+
146
+
147
+ # старт заявки (тейкером 17)
148
+ async def test_create_order_taker():
149
+ ads = bybit_p2p.get_ads("USDT", "RUB", payment=["51"])
150
+ ad = ads[0]
151
+ # get_order_info = bybit_p2p.get_order_info(ad["id"])
152
+ result = bybit_p2p.create_order_taker(
153
+ ad["id"], "USDT", "RUB", False, ad["minAmount"], float(ad["minAmount"]) / float(ad["price"]), ad["price"]
154
+ )
155
+ ok = True if result["ret_msg"] == "SUCCESS" else False
156
+ await TestEx.update_or_create({"ok": ok}, ex_id=10, action=ExAction.take_ad)
157
+
158
+
159
+ # сообщения чата (тейкером 21)
160
+ async def test_get_chat_msgs(dbc):
161
+ msgs = bybit_p2p.get_chat_msg("1832490804709646336")
162
+ assert len(msgs) > 0, "No have msgs"
163
+
164
+
165
+ async def test_user_block(dbc):
166
+ bu = bybit_p2p.block_user("146246740")
167
+ assert bu["result"], "User don't block"
168
+ ubu = bybit_p2p.unblock_user("146246740")
169
+ assert ubu["result"], "User don't unblock"
170
+
171
+
172
+ # поставить отзыв (27)
173
+ async def test_user_review_post(dbc):
174
+ result = bybit_p2p.user_review_post("1831422797854318592")
175
+ assert result["ret_msg"] == "SUCCESS", "Review post failed"
176
+
177
+
178
+ # получшение заявок по всем ордерам за заданное время, статус, направление, монета (32)
179
+ async def test_get_orders_done(dbc):
180
+ result = bybit_p2p.get_orders_done(1717189200000, 1722545999999, 50, 1, "USDT")
181
+ assert result["ret_msg"] == "SUCCESS", "No orders done"
182
+
183
+
184
+ # получшение заявок по активным ордерам за заданное время, статус, направление, монета (32)
185
+ async def test_get_orders_active(dbc):
186
+ result = bybit_p2p.get_orders_active(1717189200000, 1722545999999, 50, 1, "USDT")
187
+ assert result["ret_msg"] == "SUCCESS", "No active orders"
188
+
189
+
190
+ # 33
191
+ async def test_get_order_info(dbc):
192
+ get_order_info = bybit_p2p.get_order_info("1819108572048125952")
193
+ assert get_order_info, "No order info"
@@ -0,0 +1,38 @@
1
+ from xync_client.Gate.premarket import Priv
2
+ from xync_client.loader import GATE_UID, GATE_PVER
3
+
4
+
5
+ async def test_get_premarket_ads():
6
+ gate = Priv(GATE_UID, GATE_PVER)
7
+ resp = await gate.get_premarket_ads()
8
+ assert len(resp), "No premarket ads"
9
+
10
+
11
+ async def test_get_my_premarket_ads():
12
+ gate = Priv(GATE_UID, GATE_PVER)
13
+ resp = await gate.get_my_premarket_ads()
14
+ assert len(resp), "No my premarket ads"
15
+
16
+
17
+ async def test_create_premarket_ad():
18
+ gate = Priv(GATE_UID, GATE_PVER)
19
+ resp = await gate.post_premarket_ad(0.649, 5)
20
+ assert resp, "Premarket ad not created"
21
+
22
+
23
+ async def test_delate_premarket_ad():
24
+ gate = Priv(GATE_UID, GATE_PVER)
25
+ resp = await gate.del_premarket_ad(62089)
26
+ assert resp, "Premarket ad not delated"
27
+
28
+
29
+ async def test_set_premarket_ads():
30
+ gate = Priv(GATE_UID, GATE_PVER)
31
+ my_ads = await gate.get_my_premarket_ads()
32
+ my_ids = [ad["order_id"] for ad in my_ads]
33
+ resp = await gate.get_premarket_ads()
34
+ for ad in resp:
35
+ if ad["order_id"] in my_ids:
36
+ pass
37
+
38
+ assert len(resp), "No premarket ads"
File without changes