xync-client 0.0.150__tar.gz → 0.0.152__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.
Potentially problematic release.
This version of xync-client might be problematic. Click here for more details.
- {xync_client-0.0.150/xync_client.egg-info → xync_client-0.0.152}/PKG-INFO +1 -1
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Abc/AdLoader.py +4 -13
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Abc/Agent.py +19 -17
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Abc/Ex.py +2 -1
- xync_client-0.0.152/xync_client/Abc/InAgent.py +10 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Abc/xtype.py +1 -1
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Bybit/InAgent.py +38 -41
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Bybit/agent.py +124 -101
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Bybit/etype/ad.py +10 -55
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Bybit/etype/cred.py +28 -9
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Bybit/etype/order.py +7 -43
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Bybit/ex.py +12 -1
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Htx/agent.py +2 -2
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Mexc/agent.py +6 -5
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Pms/Volet/__init__.py +1 -1
- {xync_client-0.0.150 → xync_client-0.0.152/xync_client.egg-info}/PKG-INFO +1 -1
- xync_client-0.0.150/xync_client/Abc/InAgent.py +0 -23
- {xync_client-0.0.150 → xync_client-0.0.152}/.env.sample +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/.gitignore +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/.pre-commit-config.yaml +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/README.md +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/__init__.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/makefile +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/pyproject.toml +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/setup.cfg +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/tests/TestAgent.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/tests/TestAsset.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/tests/TestEx.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/tests/TestOrder.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/tests/_todo_refact/Binance/test_binance.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/tests/_todo_refact/Bybit/test_bybit.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/tests/_todo_refact/Bybit/test_bybit_p2p.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/tests/_todo_refact/Gate/test_gate.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/tests/_todo_refact/Wallet/test_agent.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/tests/_todo_refact/Wallet/test_ex.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/tests/_todo_refact/__init__.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/tests/_todo_refact/_test_ex.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Abc/Asset.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Abc/Auth.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Abc/BaseTest.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Abc/Exception.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Abc/HasAbotUid.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Abc/Order.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Abc/PmAgent.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Binance/__init__.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Binance/binance_async.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Binance/earn_api.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Binance/etype/ad.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Binance/etype/pm.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Binance/ex.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Binance/exceptions.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Binance/sapi.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Binance/web_c2c.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/BingX/__init__.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/BingX/agent.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/BingX/base.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/BingX/etype/ad.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/BingX/etype/pm.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/BingX/ex.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/BingX/req.mjs +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/BingX/sign.js +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/BitGet/__init__.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/BitGet/agent.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/BitGet/etype/ad.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/BitGet/ex.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/BitPapa/ex.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Bybit/order.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Bybit/web_earn.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Bybit/web_p2p.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Bybit/ws.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Gate/etype/ad.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Gate/ex.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Gate/premarket.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Gmail/__init__.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Htx/earn.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Htx/etype/__init__.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Htx/etype/ad.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Htx/etype/cred.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Htx/etype/pm.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Htx/etype/test.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Htx/ex.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/KuCoin/etype/ad.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/KuCoin/etype/pm.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/KuCoin/ex.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/KuCoin/web.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Mexc/etype/ad.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Mexc/etype/pm.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Mexc/ex.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Okx/etype/ad.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Okx/etype/pm.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Okx/ex.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Pms/.gitignore +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Pms/Alfa/__init__.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Pms/Alfa/state.json +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Pms/MTS/__init__.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Pms/Ozon/__init__.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Pms/Payeer/.gitignore +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Pms/Payeer/__init__.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Pms/Payeer/api.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Pms/Payeer/login.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Pms/Sber/__init__.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Pms/Sber/utils.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Pms/Tinkoff/__init__.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Pms/Volet/_todo_req/req.mjs +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Pms/Volet/_todo_req/req.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Pms/Volet/api.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Pms/Volet/pl.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Pms/Xync/__main__.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Pms/Xync/ed.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/Pms/Yandex/__init__.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/TgWallet/agent.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/TgWallet/asset.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/TgWallet/auth.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/TgWallet/ex.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/TgWallet/inAgent.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/TgWallet/order.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/TgWallet/pyd.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/TgWallet/pyro.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/TgWallet/web.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/__init__.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/details.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/loader.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client/pm_unifier.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client.egg-info/SOURCES.txt +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client.egg-info/dependency_links.txt +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client.egg-info/requires.txt +0 -0
- {xync_client-0.0.150 → xync_client-0.0.152}/xync_client.egg-info/top_level.txt +0 -0
|
@@ -57,7 +57,6 @@ class AdLoader:
|
|
|
57
57
|
coinex: models.CoinEx = None,
|
|
58
58
|
curex: models.CurEx = None,
|
|
59
59
|
rname: str = None,
|
|
60
|
-
pms_from_cond: bool = False,
|
|
61
60
|
) -> models.Ad:
|
|
62
61
|
if not maker:
|
|
63
62
|
if not (maker := await models.Actor.get_or_none(exid=pad.userId, ex=self.ex)):
|
|
@@ -87,13 +86,13 @@ class AdLoader:
|
|
|
87
86
|
price=int(float(pad.price) * cur_scale),
|
|
88
87
|
premium=int(float(pad.premium) * 100),
|
|
89
88
|
cond_id=cid,
|
|
89
|
+
status=self.ad_status(ad_upd.status),
|
|
90
90
|
)
|
|
91
91
|
try:
|
|
92
92
|
ad_db, _ = await models.Ad.update_or_create(**df_unq)
|
|
93
93
|
except OperationalError as e:
|
|
94
94
|
raise e
|
|
95
|
-
|
|
96
|
-
await ad_db.pms.add(*(await models.Pm.filter(pmexs__ex=self.ex, pmexs__exid__in=pad.payments)))
|
|
95
|
+
await ad_db.pms.add(*(await models.Pm.filter(pmexs__ex=self.ex, pmexs__exid__in=pad.payments)))
|
|
97
96
|
return ad_db
|
|
98
97
|
|
|
99
98
|
async def cond_load( # todo: refact from Bybit Ad format to universal
|
|
@@ -120,13 +119,7 @@ class AdLoader:
|
|
|
120
119
|
# if not len((old_cond := await Cond.get(id=old_cid).prefetch_related('ads')).ads):
|
|
121
120
|
# await old_cond.delete()
|
|
122
121
|
# logging.warning(f"Cond#{old_cid} deleted!")
|
|
123
|
-
return (
|
|
124
|
-
ad_db
|
|
125
|
-
or force
|
|
126
|
-
and await self.ad_load(
|
|
127
|
-
ad, cid, ps, coinex=coinex, curex=curex, rname=rname, pms_from_cond=pms_from_cond
|
|
128
|
-
)
|
|
129
|
-
), False
|
|
122
|
+
return (ad_db or force and await self.ad_load(ad, cid, ps, coinex=coinex, curex=curex, rname=rname)), False
|
|
130
123
|
# если эта объява в таким ид уже есть в бд, но с другим условием (или без), а текущего условия еще нет в бд
|
|
131
124
|
if ad_db:
|
|
132
125
|
await ad_db.fetch_related("cond__ads", "maker")
|
|
@@ -154,9 +147,7 @@ class AdLoader:
|
|
|
154
147
|
return ad_db, False
|
|
155
148
|
|
|
156
149
|
cond = await self.cond_new(cleaned, {int(ad.userId)})
|
|
157
|
-
ad_db = await self.ad_load(
|
|
158
|
-
ad, cond.id, ps, coinex=coinex, curex=curex, rname=rname, pms_from_cond=pms_from_cond
|
|
159
|
-
)
|
|
150
|
+
ad_db = await self.ad_load(ad, cond.id, ps, coinex=coinex, curex=curex, rname=rname)
|
|
160
151
|
ad_db.cond = cond
|
|
161
152
|
return ad_db, True
|
|
162
153
|
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
from abc import abstractmethod
|
|
2
|
+
from asyncio.tasks import gather
|
|
2
3
|
|
|
3
4
|
from pydantic import BaseModel
|
|
4
5
|
from pyro_client.client.file import FileClient
|
|
5
6
|
from x_client import df_hdrs
|
|
6
7
|
from x_client.aiohttp import Client as HttpClient
|
|
7
8
|
from xync_bot import XyncBot
|
|
9
|
+
from xync_client.Abc.InAgent import BaseInAgentClient
|
|
10
|
+
|
|
8
11
|
from xync_client.Bybit.etype.order import TakeAdReq
|
|
9
12
|
from xync_schema import models
|
|
10
13
|
from xync_schema.models import OrderStatus, Coin, Cur, Ad, AdStatus, Actor, Agent
|
|
@@ -15,13 +18,14 @@ from xync_client.Abc.xtype import CredExOut, BaseOrderReq, BaseAdUpdate
|
|
|
15
18
|
from xync_client.Gmail import GmClient
|
|
16
19
|
|
|
17
20
|
|
|
18
|
-
class BaseAgentClient(HttpClient):
|
|
21
|
+
class BaseAgentClient(HttpClient, BaseInAgentClient):
|
|
19
22
|
bbot: XyncBot
|
|
20
23
|
fbot: FileClient
|
|
21
24
|
|
|
22
25
|
def __init__(
|
|
23
26
|
self,
|
|
24
27
|
agent: Agent,
|
|
28
|
+
ex_client: BaseExClient,
|
|
25
29
|
fbot: FileClient,
|
|
26
30
|
bbot: XyncBot,
|
|
27
31
|
headers: dict[str, str] = df_hdrs,
|
|
@@ -32,8 +36,20 @@ class BaseAgentClient(HttpClient):
|
|
|
32
36
|
self.agent: Agent = agent
|
|
33
37
|
self.actor: Actor = agent.actor
|
|
34
38
|
self.gmail = GmClient(agent.actor.person.user)
|
|
39
|
+
self.ex_client: BaseExClient = ex_client
|
|
35
40
|
super().__init__(self.actor.ex.host_p2p, headers, cookies)
|
|
36
|
-
|
|
41
|
+
|
|
42
|
+
async def start(self):
|
|
43
|
+
tasks = []
|
|
44
|
+
if not self.is_started:
|
|
45
|
+
if self.agent.status & 1: # race
|
|
46
|
+
tasks.append(self.start_race())
|
|
47
|
+
if self.agent.status & 2: # in agent
|
|
48
|
+
tasks.append(self.start_listen())
|
|
49
|
+
if self.agent.status & 4: # for further
|
|
50
|
+
...
|
|
51
|
+
self.is_started = True
|
|
52
|
+
return await gather(*tasks)
|
|
37
53
|
|
|
38
54
|
# 0: Получшение ордеров в статусе status, по монете coin, в валюте coin, в направлении is_sell: bool
|
|
39
55
|
@abstractmethod
|
|
@@ -134,21 +150,7 @@ class BaseAgentClient(HttpClient):
|
|
|
134
150
|
async def my_assets(self) -> dict: ...
|
|
135
151
|
|
|
136
152
|
@abstractmethod
|
|
137
|
-
async def
|
|
138
|
-
|
|
139
|
-
async def take_ad(self, req: TakeAdReq):
|
|
140
|
-
if req.is_sell:
|
|
141
|
-
fltr = dict(ex_id=self.actor.ex_id, cred__pmcur__pm_id=req.pm_id, cred__person_id=self.actor.person.id)
|
|
142
|
-
if req.cur_:
|
|
143
|
-
fltr |= dict(cred__pmcur__cur__ticker=req.cur_)
|
|
144
|
-
pmexs = await models.CredEx.filter(**fltr)
|
|
145
|
-
else:
|
|
146
|
-
pmexs = await models.PmEx.filter(ex_id=self.actor.ex_id, pm_id=req.pm_id)
|
|
147
|
-
if len(pmexs) > 1:
|
|
148
|
-
pmexs = [p for p in pmexs if p.name.endswith(f" ({req.cur_})")]
|
|
149
|
-
req.pm_id = pmexs[0].exid
|
|
150
|
-
req.quantity = round(req.amount / req.price, 4) # todo: to get the scale from coinEx
|
|
151
|
-
return await self._take_ad(req)
|
|
153
|
+
async def take_ad(self, req: TakeAdReq): ...
|
|
152
154
|
|
|
153
155
|
# Сохранение объявления (с Pm/Cred-ами) в бд
|
|
154
156
|
# async def ad_pydin2db(self, ad_pydin: AdSaleIn | AdBuyIn) -> Ad:
|
|
@@ -17,6 +17,7 @@ from xync_client.pm_unifier import PmUnifier, PmUni
|
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
class BaseExClient(HttpClient, AdLoader):
|
|
20
|
+
host: str = None
|
|
20
21
|
cur_map: dict[int, str] = {}
|
|
21
22
|
unifier_class: type = PmUnifier
|
|
22
23
|
logo_pre_url: str
|
|
@@ -34,7 +35,7 @@ class BaseExClient(HttpClient, AdLoader):
|
|
|
34
35
|
):
|
|
35
36
|
self.ex = ex
|
|
36
37
|
self.bot = bot
|
|
37
|
-
super().__init__(getattr(ex, attr), headers, cookies, proxy and proxy.str())
|
|
38
|
+
super().__init__(self.host or getattr(ex, attr), headers, cookies, proxy and proxy.str())
|
|
38
39
|
|
|
39
40
|
@abstractmethod
|
|
40
41
|
def pm_type_map(self, typ: models.PmEx) -> str: ...
|
|
@@ -9,6 +9,7 @@ import websockets
|
|
|
9
9
|
from asyncio import run, sleep
|
|
10
10
|
from decimal import Decimal
|
|
11
11
|
|
|
12
|
+
from bybit_p2p import P2P
|
|
12
13
|
from playwright.async_api import async_playwright
|
|
13
14
|
from pydantic import ValidationError
|
|
14
15
|
from pyro_client.client.file import FileClient
|
|
@@ -16,6 +17,7 @@ from tortoise.exceptions import IntegrityError
|
|
|
16
17
|
from tortoise.timezone import now
|
|
17
18
|
from tortoise.transactions import in_transaction
|
|
18
19
|
from xync_bot import XyncBot
|
|
20
|
+
from xync_client.Bybit.ex import ExClient
|
|
19
21
|
|
|
20
22
|
from xync_client.Abc.PmAgent import PmAgentClient
|
|
21
23
|
from xync_schema import models
|
|
@@ -32,16 +34,17 @@ from xync_client.Bybit.etype.order import (
|
|
|
32
34
|
)
|
|
33
35
|
from xync_client.loader import NET_TOKEN, PAY_TOKEN
|
|
34
36
|
from xync_client.Abc.InAgent import BaseInAgentClient
|
|
35
|
-
from xync_client.Bybit.agent import AgentClient
|
|
36
37
|
|
|
37
38
|
|
|
38
39
|
class InAgentClient(BaseInAgentClient):
|
|
39
|
-
|
|
40
|
+
actor: models.Actor
|
|
41
|
+
api: P2P
|
|
42
|
+
ex_client: ExClient
|
|
40
43
|
|
|
41
44
|
async def start_listen(self):
|
|
42
|
-
t = await self.
|
|
45
|
+
t = await self.ott()
|
|
43
46
|
ts = int(float(t["time_now"]) * 1000)
|
|
44
|
-
await self.ws_prv(self.
|
|
47
|
+
await self.ws_prv(self.actor.agent.auth["deviceId"], t["result"], ts)
|
|
45
48
|
|
|
46
49
|
# 3N: [T] - Уведомление об одобрении запроса на сделку
|
|
47
50
|
async def request_accepted_notify(self) -> int: ... # id
|
|
@@ -87,11 +90,11 @@ class InAgentClient(BaseInAgentClient):
|
|
|
87
90
|
except ValidationError as e:
|
|
88
91
|
logging.error(e)
|
|
89
92
|
logging.error(data["data"])
|
|
90
|
-
order = self.
|
|
93
|
+
order = self.api.get_order_details(orderId=upd.id)
|
|
91
94
|
order = OrderFull.model_validate(order["result"])
|
|
92
95
|
order_db = await models.Order.get_or_none(
|
|
93
96
|
exid=order.id, ad__exid=order.itemId
|
|
94
|
-
) or await self.
|
|
97
|
+
) or await self.create_order(order)
|
|
95
98
|
match upd.status:
|
|
96
99
|
case StatusApi.created:
|
|
97
100
|
logging.info(f"Order {order.id} created at {order.createDate}")
|
|
@@ -136,7 +139,7 @@ class InAgentClient(BaseInAgentClient):
|
|
|
136
139
|
continue
|
|
137
140
|
|
|
138
141
|
# если висят незавершенные продажи с такой же суммой
|
|
139
|
-
pos = (await self.
|
|
142
|
+
pos = (await self.get_orders_active(1))["result"]
|
|
140
143
|
pos = [
|
|
141
144
|
o
|
|
142
145
|
for o in pos.get("items", [])
|
|
@@ -146,14 +149,14 @@ class InAgentClient(BaseInAgentClient):
|
|
|
146
149
|
and int(order.createDate)
|
|
147
150
|
< int(o["createDate"]) + 15 * 60 * 1000
|
|
148
151
|
# get full_order from o, and cred or pm from full_order:
|
|
149
|
-
and self.
|
|
150
|
-
"
|
|
151
|
-
][
|
|
152
|
+
and self.api.get_order_details(orderId=o["id"])["result"][
|
|
153
|
+
"paymentTermList"
|
|
154
|
+
][0]["accountNo"]
|
|
152
155
|
== order.paymentTermList[0].accountNo
|
|
153
156
|
)
|
|
154
157
|
]
|
|
155
158
|
curex = await models.CurEx.get(
|
|
156
|
-
cur__ticker=order.currencyId, ex=self.
|
|
159
|
+
cur__ticker=order.currencyId, ex=self.ex_client.ex
|
|
157
160
|
)
|
|
158
161
|
pos_db = await models.Order.filter(
|
|
159
162
|
exid__not=order.id,
|
|
@@ -163,16 +166,16 @@ class InAgentClient(BaseInAgentClient):
|
|
|
163
166
|
created_at__gt=now() - timedelta(minutes=15),
|
|
164
167
|
)
|
|
165
168
|
if pos or pos_db:
|
|
166
|
-
await self.
|
|
169
|
+
await self.ex_client.bot.send(
|
|
167
170
|
f"[Duplicate amount!]"
|
|
168
171
|
f"(https://www.bybit.com/ru-RU/p2p/orderList/{order.id})",
|
|
169
|
-
self.
|
|
172
|
+
self.actor.person.user.username_id,
|
|
170
173
|
)
|
|
171
174
|
logging.warning("Duplicate amount!")
|
|
172
175
|
continue
|
|
173
176
|
|
|
174
177
|
# !!! ОТПРАВЛЯЕМ ДЕНЬГИ !!!
|
|
175
|
-
self.
|
|
178
|
+
self.api.release_assets(orderId=upd.id)
|
|
176
179
|
logging.info(
|
|
177
180
|
f"Order {order.id} created, paid before #{tid}:{am} at {order.createDate}, and RELEASED at {now()}"
|
|
178
181
|
)
|
|
@@ -236,14 +239,14 @@ class InAgentClient(BaseInAgentClient):
|
|
|
236
239
|
case "RECEIVE":
|
|
237
240
|
upd = Receive.model_validate(data["data"])
|
|
238
241
|
if order_db := await models.Order.get_or_none(
|
|
239
|
-
exid=upd.orderId, ad__maker__ex=self.
|
|
242
|
+
exid=upd.orderId, ad__maker__ex=self.actor.ex
|
|
240
243
|
).prefetch_related("ad__pair_side__pair", "cred__pmcur__cur"):
|
|
241
|
-
im_taker = order_db.taker_id == self.
|
|
244
|
+
im_taker = order_db.taker_id == self.actor.id
|
|
242
245
|
im_buyer = order_db.ad.pair_side.is_sell == im_taker
|
|
243
246
|
if order_db.ad.auto_msg != upd.message and upd.roleType == "user":
|
|
244
247
|
msg, _ = await models.Msg.update_or_create(
|
|
245
248
|
{
|
|
246
|
-
"to_maker": upd.userId == self.
|
|
249
|
+
"to_maker": upd.userId == self.actor.exid and im_taker,
|
|
247
250
|
"sent_at": datetime.fromtimestamp(float(upd.createDate) / 1000),
|
|
248
251
|
},
|
|
249
252
|
txt=upd.message,
|
|
@@ -262,7 +265,7 @@ class InAgentClient(BaseInAgentClient):
|
|
|
262
265
|
if upd.orderStatus in (
|
|
263
266
|
StatusApi.wait_for_buyer,
|
|
264
267
|
): # todo: тут приходит ордер.статус=10, хотя покупатель еще не нажал оплачено
|
|
265
|
-
order = self.
|
|
268
|
+
order = self.api.get_order_details(orderId=upd.orderId)["result"]
|
|
266
269
|
order = OrderFull.model_validate(order)
|
|
267
270
|
|
|
268
271
|
case "CLEAR":
|
|
@@ -295,15 +298,13 @@ class InAgentClient(BaseInAgentClient):
|
|
|
295
298
|
async def money_upd(self, order_db: models.Order):
|
|
296
299
|
# обновляем остаток монеты
|
|
297
300
|
await order_db.fetch_related("ad__pair_side__pair", "cred", "transfer")
|
|
298
|
-
ass = await models.Asset.get(
|
|
299
|
-
addr__coin_id=order_db.ad.pair_side.pair.coin_id, addr__actor=self.agent_client.actor
|
|
300
|
-
)
|
|
301
|
+
ass = await models.Asset.get(addr__coin_id=order_db.ad.pair_side.pair.coin_id, addr__actor=self.actor)
|
|
301
302
|
# обновляем остаток валюты
|
|
302
303
|
fiat = await models.Fiat.get(
|
|
303
|
-
cred__person_id=self.
|
|
304
|
+
cred__person_id=self.actor.person_id, cred__pmcur_id=order_db.cred.pmcur_id
|
|
304
305
|
).prefetch_related("cred__pmcur__pm")
|
|
305
306
|
fee = round(order_db.amount * (fiat.cred.pmcur.pm.fee or 0) * 0.0001)
|
|
306
|
-
im_seller = order_db.ad.pair_side.is_sell == (_im_maker := order_db.ad.maker_id == self.
|
|
307
|
+
im_seller = order_db.ad.pair_side.is_sell == (_im_maker := order_db.ad.maker_id == self.actor.id)
|
|
307
308
|
# k = int(im_seller) * 2 - 1 # im_seller: 1, im_buyer: -1
|
|
308
309
|
if order_db.status == OrderStatus.created:
|
|
309
310
|
if im_seller:
|
|
@@ -335,9 +336,9 @@ class InAgentClient(BaseInAgentClient):
|
|
|
335
336
|
pma, cur = await self.get_pma_by_pmex(order_db)
|
|
336
337
|
async with in_transaction():
|
|
337
338
|
# отмечаем ордер на бирже "оплачен"
|
|
338
|
-
pmex = await models.PmEx.get(pm_id=order_db.cred.pmcur.
|
|
339
|
-
credex = await models.CredEx.get(cred=order_db.cred, ex=self.
|
|
340
|
-
self.
|
|
339
|
+
pmex = await models.PmEx.get(pm_id=order_db.cred.pmcur.pmex_exid, ex=self.actor.ex)
|
|
340
|
+
credex = await models.CredEx.get(cred=order_db.cred, ex=self.actor.ex)
|
|
341
|
+
self.api.mark_as_paid(
|
|
341
342
|
orderId=str(order_db.exid),
|
|
342
343
|
paymentType=pmex.exid, # pmex.exid
|
|
343
344
|
paymentId=str(credex.exid), # credex.exid
|
|
@@ -346,7 +347,7 @@ class InAgentClient(BaseInAgentClient):
|
|
|
346
347
|
if t := await models.Transfer.get_or_none(order=order_db, amount=order_db.amount):
|
|
347
348
|
await pma.bot.send(
|
|
348
349
|
f"Order# {order_db.exid}: Double send {fmt_am}{cur} to {order_db.cred.detail} #{t.pmid}!",
|
|
349
|
-
self.
|
|
350
|
+
self.actor.person.user.username_id,
|
|
350
351
|
)
|
|
351
352
|
raise Exception(
|
|
352
353
|
f"Order# {order_db.exid}: Double send {fmt_am}{cur} to {order_db.cred.detail} #{t.pmid}!"
|
|
@@ -367,38 +368,34 @@ class InAgentClient(BaseInAgentClient):
|
|
|
367
368
|
|
|
368
369
|
async def send_receipt(self, oexid: str, tid: int) -> tuple[PmAgentClient | None, models.CredEx] | None:
|
|
369
370
|
try:
|
|
370
|
-
if res := self.
|
|
371
|
+
if res := self.api.upload_chat_file(upload_file=f"tmp/{tid}.png").get("result"):
|
|
371
372
|
await sleep(0.5)
|
|
372
|
-
self.
|
|
373
|
-
orderId=oexid, contentType="pic", message=res["url"], msgUuid=uuid4().hex
|
|
374
|
-
)
|
|
373
|
+
self.api.send_chat_message(orderId=oexid, contentType="pic", message=res["url"], msgUuid=uuid4().hex)
|
|
375
374
|
except Exception as e:
|
|
376
375
|
logging.error(e)
|
|
377
376
|
await sleep(0.5)
|
|
378
|
-
self.
|
|
379
|
-
orderId=oexid, contentType="str", message=f"#{tid}", msgUuid=uuid4().hex
|
|
380
|
-
)
|
|
377
|
+
self.api.send_chat_message(orderId=oexid, contentType="str", message=f"#{tid}", msgUuid=uuid4().hex)
|
|
381
378
|
|
|
382
379
|
async def get_pma_by_cdex(self, order: OrderFull) -> tuple[PmAgentClient | None, models.CredEx] | None:
|
|
383
380
|
cdxs = await models.CredEx.filter(
|
|
384
|
-
ex=self.
|
|
381
|
+
ex=self.ex_client.ex,
|
|
385
382
|
exid__in=[ptl.id for ptl in order.paymentTermList],
|
|
386
|
-
cred__person=self.
|
|
383
|
+
cred__person=self.actor.person,
|
|
387
384
|
).prefetch_related("cred__pmcur__cur")
|
|
388
|
-
pmas = [pma for cdx in cdxs if (pma := self.pmacs.get(cdx.cred.pmcur.
|
|
385
|
+
pmas = [pma for cdx in cdxs if (pma := self.pmacs.get(cdx.cred.pmcur.pmex_exid))]
|
|
389
386
|
if not len(pmas):
|
|
390
387
|
# raise ValueError(order.paymentTermList, f"No pm_agents for {order.paymentTermList[0].paymentType}")
|
|
391
388
|
return None
|
|
392
389
|
elif len(pmas) > 1:
|
|
393
|
-
logging.error(order.paymentTermList, f">1 pm_agents for {cdxs[0].cred.pmcur.
|
|
390
|
+
logging.error(order.paymentTermList, f">1 pm_agents for {cdxs[0].cred.pmcur.pmex_exid}")
|
|
394
391
|
else:
|
|
395
392
|
return pmas[0], cdxs[0]
|
|
396
393
|
|
|
397
394
|
async def get_pma_by_pmex(self, order_db: models.Order) -> tuple[PmAgentClient, str]:
|
|
398
|
-
pma = self.pmacs.get(order_db.cred.pmcur.
|
|
395
|
+
pma = self.pmacs.get(order_db.cred.pmcur.pmex_exid)
|
|
399
396
|
if pma:
|
|
400
397
|
return pma, order_db.cred.pmcur.cur.ticker
|
|
401
|
-
logging.error(f"No pm_agents for {order_db.cred.pmcur.
|
|
398
|
+
logging.error(f"No pm_agents for {order_db.cred.pmcur.pmex_exid}")
|
|
402
399
|
|
|
403
400
|
@staticmethod
|
|
404
401
|
def listen(data: dict | None):
|
|
@@ -445,7 +442,7 @@ async def main():
|
|
|
445
442
|
except Exception as e:
|
|
446
443
|
await b.send("😱Bybit InAgent CRASHED!!!😱", agent.actor.person.user.username_id)
|
|
447
444
|
await b.send(f"```\n{''.join(traceback.format_exception(e))}\n```", agent.actor.person.user.username_id)
|
|
448
|
-
await cl.
|
|
445
|
+
await cl.close()
|
|
449
446
|
|
|
450
447
|
|
|
451
448
|
if __name__ == "__main__":
|