xync-client 0.0.150__tar.gz → 0.0.151__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.151}/PKG-INFO +1 -1
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Abc/Agent.py +1 -15
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Abc/xtype.py +1 -1
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Bybit/InAgent.py +5 -5
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Bybit/agent.py +58 -50
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Bybit/etype/order.py +5 -5
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Htx/agent.py +2 -2
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Mexc/agent.py +6 -5
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Pms/Volet/__init__.py +1 -1
- {xync_client-0.0.150 → xync_client-0.0.151/xync_client.egg-info}/PKG-INFO +1 -1
- {xync_client-0.0.150 → xync_client-0.0.151}/.env.sample +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/.gitignore +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/.pre-commit-config.yaml +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/README.md +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/__init__.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/makefile +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/pyproject.toml +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/setup.cfg +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/tests/TestAgent.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/tests/TestAsset.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/tests/TestEx.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/tests/TestOrder.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/tests/_todo_refact/Binance/test_binance.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/tests/_todo_refact/Bybit/test_bybit.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/tests/_todo_refact/Bybit/test_bybit_p2p.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/tests/_todo_refact/Gate/test_gate.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/tests/_todo_refact/Wallet/test_agent.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/tests/_todo_refact/Wallet/test_ex.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/tests/_todo_refact/__init__.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/tests/_todo_refact/_test_ex.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Abc/AdLoader.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Abc/Asset.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Abc/Auth.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Abc/BaseTest.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Abc/Ex.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Abc/Exception.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Abc/HasAbotUid.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Abc/InAgent.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Abc/Order.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Abc/PmAgent.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Binance/__init__.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Binance/binance_async.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Binance/earn_api.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Binance/etype/ad.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Binance/etype/pm.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Binance/ex.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Binance/exceptions.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Binance/sapi.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Binance/web_c2c.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/BingX/__init__.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/BingX/agent.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/BingX/base.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/BingX/etype/ad.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/BingX/etype/pm.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/BingX/ex.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/BingX/req.mjs +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/BingX/sign.js +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/BitGet/__init__.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/BitGet/agent.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/BitGet/etype/ad.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/BitGet/ex.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/BitPapa/ex.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Bybit/etype/ad.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Bybit/etype/cred.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Bybit/ex.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Bybit/order.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Bybit/web_earn.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Bybit/web_p2p.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Bybit/ws.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Gate/etype/ad.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Gate/ex.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Gate/premarket.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Gmail/__init__.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Htx/earn.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Htx/etype/__init__.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Htx/etype/ad.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Htx/etype/cred.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Htx/etype/pm.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Htx/etype/test.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Htx/ex.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/KuCoin/etype/ad.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/KuCoin/etype/pm.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/KuCoin/ex.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/KuCoin/web.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Mexc/etype/ad.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Mexc/etype/pm.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Mexc/ex.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Okx/etype/ad.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Okx/etype/pm.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Okx/ex.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Pms/.gitignore +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Pms/Alfa/__init__.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Pms/Alfa/state.json +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Pms/MTS/__init__.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Pms/Ozon/__init__.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Pms/Payeer/.gitignore +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Pms/Payeer/__init__.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Pms/Payeer/api.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Pms/Payeer/login.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Pms/Sber/__init__.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Pms/Sber/utils.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Pms/Tinkoff/__init__.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Pms/Volet/_todo_req/req.mjs +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Pms/Volet/_todo_req/req.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Pms/Volet/api.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Pms/Volet/pl.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Pms/Xync/__main__.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Pms/Xync/ed.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/Pms/Yandex/__init__.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/TgWallet/agent.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/TgWallet/asset.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/TgWallet/auth.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/TgWallet/ex.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/TgWallet/inAgent.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/TgWallet/order.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/TgWallet/pyd.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/TgWallet/pyro.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/TgWallet/web.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/__init__.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/details.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/loader.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client/pm_unifier.py +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client.egg-info/SOURCES.txt +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client.egg-info/dependency_links.txt +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client.egg-info/requires.txt +0 -0
- {xync_client-0.0.150 → xync_client-0.0.151}/xync_client.egg-info/top_level.txt +0 -0
|
@@ -134,21 +134,7 @@ class BaseAgentClient(HttpClient):
|
|
|
134
134
|
async def my_assets(self) -> dict: ...
|
|
135
135
|
|
|
136
136
|
@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)
|
|
137
|
+
async def take_ad(self, req: TakeAdReq): ...
|
|
152
138
|
|
|
153
139
|
# Сохранение объявления (с Pm/Cred-ами) в бд
|
|
154
140
|
# async def ad_pydin2db(self, ad_pydin: AdSaleIn | AdBuyIn) -> Ad:
|
|
@@ -335,7 +335,7 @@ class InAgentClient(BaseInAgentClient):
|
|
|
335
335
|
pma, cur = await self.get_pma_by_pmex(order_db)
|
|
336
336
|
async with in_transaction():
|
|
337
337
|
# отмечаем ордер на бирже "оплачен"
|
|
338
|
-
pmex = await models.PmEx.get(pm_id=order_db.cred.pmcur.
|
|
338
|
+
pmex = await models.PmEx.get(pm_id=order_db.cred.pmcur.pmex_exid, ex=self.agent_client.actor.ex)
|
|
339
339
|
credex = await models.CredEx.get(cred=order_db.cred, ex=self.agent_client.actor.ex)
|
|
340
340
|
self.agent_client.api.mark_as_paid(
|
|
341
341
|
orderId=str(order_db.exid),
|
|
@@ -385,20 +385,20 @@ class InAgentClient(BaseInAgentClient):
|
|
|
385
385
|
exid__in=[ptl.id for ptl in order.paymentTermList],
|
|
386
386
|
cred__person=self.agent_client.actor.person,
|
|
387
387
|
).prefetch_related("cred__pmcur__cur")
|
|
388
|
-
pmas = [pma for cdx in cdxs if (pma := self.pmacs.get(cdx.cred.pmcur.
|
|
388
|
+
pmas = [pma for cdx in cdxs if (pma := self.pmacs.get(cdx.cred.pmcur.pmex_exid))]
|
|
389
389
|
if not len(pmas):
|
|
390
390
|
# raise ValueError(order.paymentTermList, f"No pm_agents for {order.paymentTermList[0].paymentType}")
|
|
391
391
|
return None
|
|
392
392
|
elif len(pmas) > 1:
|
|
393
|
-
logging.error(order.paymentTermList, f">1 pm_agents for {cdxs[0].cred.pmcur.
|
|
393
|
+
logging.error(order.paymentTermList, f">1 pm_agents for {cdxs[0].cred.pmcur.pmex_exid}")
|
|
394
394
|
else:
|
|
395
395
|
return pmas[0], cdxs[0]
|
|
396
396
|
|
|
397
397
|
async def get_pma_by_pmex(self, order_db: models.Order) -> tuple[PmAgentClient, str]:
|
|
398
|
-
pma = self.pmacs.get(order_db.cred.pmcur.
|
|
398
|
+
pma = self.pmacs.get(order_db.cred.pmcur.pmex_exid)
|
|
399
399
|
if pma:
|
|
400
400
|
return pma, order_db.cred.pmcur.cur.ticker
|
|
401
|
-
logging.error(f"No pm_agents for {order_db.cred.pmcur.
|
|
401
|
+
logging.error(f"No pm_agents for {order_db.cred.pmcur.pmex_exid}")
|
|
402
402
|
|
|
403
403
|
@staticmethod
|
|
404
404
|
def listen(data: dict | None):
|
|
@@ -22,6 +22,7 @@ from tortoise.expressions import Q
|
|
|
22
22
|
from tortoise.functions import Count
|
|
23
23
|
from tortoise.signals import post_save
|
|
24
24
|
from urllib3.exceptions import ReadTimeoutError
|
|
25
|
+
from x_client import df_hdrs
|
|
25
26
|
from x_model import init_db
|
|
26
27
|
from x_model.func import ArrayAgg
|
|
27
28
|
from xync_bot import XyncBot
|
|
@@ -54,10 +55,8 @@ class NoMakerException(Exception):
|
|
|
54
55
|
|
|
55
56
|
|
|
56
57
|
class AgentClient(BaseAgentClient): # Bybit client
|
|
57
|
-
headers = {
|
|
58
|
-
|
|
59
|
-
"Cookie": ";",
|
|
60
|
-
}
|
|
58
|
+
headers = df_hdrs | {"accept-language": "ru-RU"}
|
|
59
|
+
sec_hdrs: dict[str, str]
|
|
61
60
|
# rewrite token for public methods
|
|
62
61
|
api: P2P
|
|
63
62
|
last_ad_id: list[str] = []
|
|
@@ -91,6 +90,11 @@ class AgentClient(BaseAgentClient): # Bybit client
|
|
|
91
90
|
|
|
92
91
|
def __init__(self, agent: Agent, fbot: FileClient, bbot: XyncBot, **kwargs):
|
|
93
92
|
super().__init__(agent, fbot, bbot, **kwargs)
|
|
93
|
+
self.sec_hdrs = {
|
|
94
|
+
"accept-language": "ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7",
|
|
95
|
+
"gdfp": agent.auth["Risktoken"],
|
|
96
|
+
"tx-id": agent.auth["Risktoken"],
|
|
97
|
+
}
|
|
94
98
|
self.api = P2P(testnet=False, api_key=agent.auth["key"], api_secret=agent.auth["sec"])
|
|
95
99
|
self.hist: dict | None = None
|
|
96
100
|
self.completed_orders: list[int] | None = None
|
|
@@ -268,46 +272,29 @@ class AgentClient(BaseAgentClient): # Bybit client
|
|
|
268
272
|
return security_risk_token
|
|
269
273
|
|
|
270
274
|
async def _check_2fa(self, risk_token) -> int:
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
{"risk_token": risk_token},
|
|
274
|
-
hdrs={
|
|
275
|
-
# "Accept-Language": "ru,en;q=0.9",
|
|
276
|
-
},
|
|
277
|
-
)
|
|
275
|
+
data = {"risk_token": risk_token}
|
|
276
|
+
res = await self._post("/x-api/user/public/risk/components", data, hdrs=self.sec_hdrs)
|
|
278
277
|
if res["ret_msg"] != "success":
|
|
279
278
|
raise HTTPException("get")
|
|
280
279
|
cres = sorted(res["result"]["component_list"], key=lambda c: c["component_id"], reverse=True)
|
|
281
|
-
# cres = [{"component_id": "payment_password_verify"}]
|
|
282
280
|
vdata = {
|
|
283
281
|
"risk_token": risk_token,
|
|
284
282
|
"component_list": {c["component_id"]: await self.__get_2fa(c["component_id"], risk_token) for c in cres},
|
|
285
283
|
}
|
|
286
|
-
res = await self._post(
|
|
287
|
-
|
|
288
|
-
vdata,
|
|
289
|
-
hdrs={
|
|
290
|
-
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36",
|
|
291
|
-
"accept-language": "ru,en;q=0.9",
|
|
292
|
-
# "accept-language": "ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7",
|
|
293
|
-
"accept-encoding": "gzip, deflate, br, zstd",
|
|
294
|
-
"accept": "application/json",
|
|
295
|
-
},
|
|
296
|
-
)
|
|
297
|
-
if res["ret_msg"] != "success":
|
|
284
|
+
res = await self._post("/x-api/user/public/risk/verify", vdata, hdrs=self.sec_hdrs)
|
|
285
|
+
if er_code := res["ret_code"] or res["result"]["ret_code"]: # если код не 0, значит ошибка
|
|
298
286
|
logging.error("Wrong 2fa, wait 5 secs and retry..")
|
|
299
287
|
await sleep(5)
|
|
300
|
-
await self._check_2fa(risk_token)
|
|
301
|
-
return
|
|
288
|
+
return await self._check_2fa(risk_token)
|
|
289
|
+
return er_code
|
|
302
290
|
|
|
303
291
|
async def __get_2fa(
|
|
304
292
|
self, typ: Literal["google2fa", "email_verify", "payment_password_verify", "phone_verify"], rt: str = None
|
|
305
293
|
):
|
|
306
294
|
res = {"ret_msg": "success"}
|
|
307
295
|
if typ != "google2fa":
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
res = await self._post("/x-api/user/public/risk/send/code", {"risk_token": rt, "component_id": typ})
|
|
296
|
+
data = {"risk_token": rt, "component_id": typ}
|
|
297
|
+
res = await self._post("/x-api/user/public/risk/send/code", data, hdrs=self.sec_hdrs)
|
|
311
298
|
if res["ret_msg"] == "success":
|
|
312
299
|
if typ == "google2fa":
|
|
313
300
|
bybit_secret = self.agent.auth["2fa"]
|
|
@@ -381,36 +368,33 @@ class AgentClient(BaseAgentClient): # Bybit client
|
|
|
381
368
|
res = res["result"]
|
|
382
369
|
return PreOrderResp.model_validate(res)
|
|
383
370
|
|
|
384
|
-
async def
|
|
371
|
+
async def _order_request(self, bor: BaseOrderReq) -> OrderResp:
|
|
372
|
+
por: PreOrderResp = await self.__preorder_request(bor.ad_id)
|
|
385
373
|
req = OrderRequest(
|
|
386
374
|
itemId=por.id,
|
|
387
|
-
tokenId=
|
|
388
|
-
currencyId=
|
|
389
|
-
side="1" if
|
|
390
|
-
amount=f"{
|
|
375
|
+
tokenId=bor.coin_exid,
|
|
376
|
+
currencyId=bor.cur_exid,
|
|
377
|
+
side="1" if bor.is_sell else "0",
|
|
378
|
+
amount=f"{bor.fiat_amount:.2f}".rstrip("0").rstrip("."),
|
|
391
379
|
curPrice=por.curPrice,
|
|
392
|
-
quantity=str(round(
|
|
380
|
+
quantity=str(round(bor.fiat_amount / float(por.price), bor.coin_scale)),
|
|
393
381
|
flag="amount",
|
|
394
382
|
# online="0"
|
|
395
383
|
)
|
|
396
|
-
if
|
|
384
|
+
if bor.is_sell:
|
|
397
385
|
credex = await models.CredEx.get(
|
|
398
386
|
cred__person_id=self.actor.person_id,
|
|
399
|
-
cred__pmcur__pm__pmexs__exid=por.payments[0],
|
|
387
|
+
cred__pmcur__pm__pmexs__exid=[pp for pp in por.payments if pp == bor.pmex_exid][0], # bor.pmex_exid
|
|
400
388
|
cred__pmcur__pm__pmexs__ex_id=self.ex_client.ex.id,
|
|
401
|
-
cred__pmcur__cur__ticker=
|
|
389
|
+
cred__pmcur__cur__ticker=bor.cur_exid,
|
|
402
390
|
)
|
|
403
|
-
req = OrderSellRequest(**req.model_dump(), paymentType=
|
|
404
|
-
return req
|
|
405
|
-
|
|
406
|
-
async def _order_request(self, bor: BaseOrderReq) -> OrderResp:
|
|
407
|
-
por: PreOrderResp = await self.__preorder_request(bor.ad_id)
|
|
408
|
-
req: OrderRequest | OrderSellRequest = await self.__order_request_build(por, bor)
|
|
391
|
+
req = OrderSellRequest(**req.model_dump(), paymentType=bor.pmex_exid, paymentId=str(credex.exid))
|
|
409
392
|
# вот непосредственно сам запрос на ордер
|
|
410
393
|
return await self.__order_create(req, bor)
|
|
411
394
|
|
|
412
395
|
async def __order_create(self, req: OrderRequest | OrderSellRequest, bor: BaseOrderReq) -> OrderResp:
|
|
413
|
-
|
|
396
|
+
hdrs = {"Risktoken": self.sec_hdrs["gdfp"]}
|
|
397
|
+
res: dict = await self._post("/x-api/fiat/otc/order/create", json=req.model_dump(), hdrs=hdrs)
|
|
414
398
|
if res["ret_code"] == 0:
|
|
415
399
|
resp = OrderResp.model_validate(res["result"])
|
|
416
400
|
elif res["ret_code"] == 10001:
|
|
@@ -972,9 +956,25 @@ class AgentClient(BaseAgentClient): # Bybit client
|
|
|
972
956
|
bc, sc = mdl + mdl * (perc / 2), mdl - mdl * (perc / 2)
|
|
973
957
|
return (bc, sc), hp, vmf, zplace
|
|
974
958
|
|
|
975
|
-
async def
|
|
959
|
+
async def take_ad(self, req: TakeAdReq):
|
|
960
|
+
if req.price and req.is_sell and req.cur_:
|
|
961
|
+
... # todo call the get_ad_details() only if lack of data
|
|
976
962
|
res = self.api.get_ad_details(itemId=req.ad_id)["result"]
|
|
977
963
|
ad: Ad = Ad.model_validate(res)
|
|
964
|
+
pmexs = await models.PmEx.filter(ex_id=self.actor.ex_id, pm_id=req.pm_id)
|
|
965
|
+
if len(pmexs) > 1:
|
|
966
|
+
pmexs = [p for p in pmexs if p.exid in ad.payments]
|
|
967
|
+
# if ad.side: # продажа, я (тейкер) покупатель
|
|
968
|
+
# pmexs = await models.PmEx.filter(ex_id=self.actor.ex_id, pm_id=req.pm_id)
|
|
969
|
+
# if len(pmexs) > 1:
|
|
970
|
+
# pmexs = [p for p in pmexs if p.name.endswith(f" ({ad.currencyId})")]
|
|
971
|
+
# else:
|
|
972
|
+
# pmexs = await models.CredEx.filter(
|
|
973
|
+
# ex_id=self.actor.ex_id, cred__person_id=self.actor.person_id,
|
|
974
|
+
# cred__pmcur__pm_id=req.pm_id, cred__pmcur__cur__ticker=ad.currencyId
|
|
975
|
+
# )
|
|
976
|
+
# req.pm_id = pmexs[0].exid
|
|
977
|
+
# req.quantity = round(req.amount / float(ad.price) - 0.00005, 4) # todo: to get the scale from coinEx
|
|
978
978
|
|
|
979
979
|
bor = BaseOrderReq(
|
|
980
980
|
ad_id=str(ad.id),
|
|
@@ -983,7 +983,7 @@ class AgentClient(BaseAgentClient): # Bybit client
|
|
|
983
983
|
cur_exid=ad.currencyId,
|
|
984
984
|
coin_exid=ad.tokenId,
|
|
985
985
|
coin_scale=ad.symbolInfo.token.scale,
|
|
986
|
-
|
|
986
|
+
pmex_exid=pmexs[0].exid,
|
|
987
987
|
)
|
|
988
988
|
resp: OrderResp = await self._order_request(bor)
|
|
989
989
|
return resp
|
|
@@ -1115,14 +1115,22 @@ async def main():
|
|
|
1115
1115
|
...
|
|
1116
1116
|
|
|
1117
1117
|
agent = (
|
|
1118
|
-
await models.Agent.filter(actor__ex_id=4, auth__isnull=False, active=True)
|
|
1119
|
-
.prefetch_related(
|
|
1118
|
+
await models.Agent.filter(actor__ex_id=4, auth__isnull=False, active=True, actor__person__user__id=2)
|
|
1119
|
+
.prefetch_related(
|
|
1120
|
+
"actor__ex",
|
|
1121
|
+
"actor__person__user__gmail",
|
|
1122
|
+
"actor__my_ads__my_ad__race",
|
|
1123
|
+
"actor__my_ads__pair_side__pair__cur",
|
|
1124
|
+
"actor__my_ads__pms",
|
|
1125
|
+
)
|
|
1120
1126
|
.first()
|
|
1121
1127
|
)
|
|
1122
1128
|
filebot = FileClient(NET_TOKEN)
|
|
1123
|
-
await filebot.start()
|
|
1129
|
+
# await filebot.start()
|
|
1124
1130
|
# b.add_handler(MessageHandler(cond_start_handler, command("cond")))
|
|
1125
1131
|
cl: AgentClient = agent.client(filebot, XyncBot(PAY_TOKEN, cn))
|
|
1132
|
+
req = TakeAdReq(ad_id=1955696985964089344, amount=504, pm_id=128)
|
|
1133
|
+
await cl.take_ad(req)
|
|
1126
1134
|
|
|
1127
1135
|
# await cl.ex_client.set_pairs()
|
|
1128
1136
|
# await cl.ex_client.set_pms()
|
|
@@ -47,9 +47,9 @@ class StatusApi(IntEnum):
|
|
|
47
47
|
class TakeAdReq(BaseModel):
|
|
48
48
|
ad_id: int | str
|
|
49
49
|
amount: float
|
|
50
|
-
quantity: float = None
|
|
51
|
-
is_sell: bool
|
|
52
|
-
price: float
|
|
50
|
+
quantity: float | None = None
|
|
51
|
+
is_sell: bool | None = None
|
|
52
|
+
price: float | None = None
|
|
53
53
|
pm_id: int | str = None
|
|
54
54
|
cur_: str | None = None
|
|
55
55
|
|
|
@@ -106,8 +106,8 @@ class OrderResp(BaseModel):
|
|
|
106
106
|
confirmId: str = ""
|
|
107
107
|
success: bool
|
|
108
108
|
securityRiskToken: str = ""
|
|
109
|
-
riskTokenType: Literal["challenge"] =
|
|
110
|
-
riskVersion: Literal["1", "2"] =
|
|
109
|
+
riskTokenType: Literal["challenge", ""] = ""
|
|
110
|
+
riskVersion: Literal["1", "2", ""] = ""
|
|
111
111
|
needSecurityRisk: bool
|
|
112
112
|
isBulkOrder: bool
|
|
113
113
|
confirmed: str = None
|
|
@@ -46,7 +46,7 @@ class AgentClient(BaseAgentClient):
|
|
|
46
46
|
|
|
47
47
|
async def cred_new(self, cred: models.Cred) -> models.CredEx:
|
|
48
48
|
pmcur = await cred.pmcur
|
|
49
|
-
exid = str(await models.PmEx.get(pm_id=pmcur.
|
|
49
|
+
exid = str(await models.PmEx.get(pm_id=pmcur.pmex_exid, ex=self.ex_client.ex).values_list("exid", flat=True))
|
|
50
50
|
field_map = {
|
|
51
51
|
"payee": "name",
|
|
52
52
|
"bank": "extra",
|
|
@@ -71,7 +71,7 @@ class AgentClient(BaseAgentClient):
|
|
|
71
71
|
|
|
72
72
|
async def cred_upd(self, cred: models.Cred, exid: int) -> models.CredEx:
|
|
73
73
|
pmcur = await cred.pmcur
|
|
74
|
-
_exid = str(await models.PmEx.get(pm_id=pmcur.
|
|
74
|
+
_exid = str(await models.PmEx.get(pm_id=pmcur.pmex_exid, ex=self.ex_client.ex).values_list("exid", flat=True))
|
|
75
75
|
field_map = {
|
|
76
76
|
"payee": "name",
|
|
77
77
|
"bank": "extra",
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
from asyncio import run
|
|
2
|
+
from hashlib import md5
|
|
2
3
|
from uuid import uuid4
|
|
3
4
|
|
|
4
5
|
from pyro_client.client.file import FileClient
|
|
@@ -24,11 +25,11 @@ class AgentClient(BaseAgentClient):
|
|
|
24
25
|
self.i = 33 if self.i > 9998 else self.i + 2
|
|
25
26
|
hdrs = self.headers | {"trochilus-trace-id": f"{uuid4()}-{self.i:04d}"}
|
|
26
27
|
auth = {
|
|
27
|
-
"p0": "
|
|
28
|
-
"k0": "
|
|
29
|
-
"chash": "
|
|
30
|
-
"mtoken": "
|
|
31
|
-
"mhash": "
|
|
28
|
+
"p0": self.actor.agent.auth["p0"],
|
|
29
|
+
"k0": self.actor.agent.auth["k0"],
|
|
30
|
+
"chash": self.actor.agent.auth["chash"],
|
|
31
|
+
"mtoken": self.actor.agent.auth["deviceId"],
|
|
32
|
+
"mhash": md5(self.actor.agent.auth["deviceId"].encode()).hexdigest(),
|
|
32
33
|
}
|
|
33
34
|
data = {
|
|
34
35
|
"scene": "TRADE_BUY",
|
|
@@ -273,7 +273,7 @@ async def _test():
|
|
|
273
273
|
pma = await models.PmAgent.get(
|
|
274
274
|
active=True,
|
|
275
275
|
auth__isnull=False,
|
|
276
|
-
pm_id=o.cred.pmcur.
|
|
276
|
+
pm_id=o.cred.pmcur.pmex_exid,
|
|
277
277
|
user__person__actors=o.ad.maker_id,
|
|
278
278
|
user__status=UserStatus.ACTIVE,
|
|
279
279
|
).prefetch_related("pm", "user__gmail", "user__username__session")
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|