xync-client 0.0.164__py3-none-any.whl → 0.0.172__py3-none-any.whl
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.
- xync_client/Abc/Agent.py +154 -22
- xync_client/Abc/Ex.py +107 -127
- xync_client/Abc/Order.py +16 -17
- xync_client/Abc/xtype.py +139 -65
- xync_client/BingX/agent.py +1 -1
- xync_client/BitGet/agent.py +1 -3
- xync_client/Bybit/agent.py +72 -321
- xync_client/Bybit/etype/ad.py +79 -58
- xync_client/Bybit/etype/cred.py +25 -3
- xync_client/Bybit/etype/order.py +150 -95
- xync_client/Bybit/ex.py +24 -12
- xync_client/Bybit/{InAgent.py → inAgent.py} +5 -10
- xync_client/Bybit/order.py +33 -16
- xync_client/Htx/agent.py +9 -9
- xync_client/Htx/etype/ad.py +2 -4
- xync_client/Htx/etype/test.py +4 -4
- xync_client/Htx/ex.py +35 -3
- xync_client/Mexc/agent.py +6 -6
- xync_client/Mexc/ex.py +2 -2
- xync_client/TgWallet/agent.py +21 -21
- xync_client/TgWallet/ex.py +11 -11
- xync_client/TgWallet/pyd.py +5 -5
- xync_client/pm_unifier.py +3 -2
- {xync_client-0.0.164.dist-info → xync_client-0.0.172.dist-info}/METADATA +1 -1
- {xync_client-0.0.164.dist-info → xync_client-0.0.172.dist-info}/RECORD +27 -27
- {xync_client-0.0.164.dist-info → xync_client-0.0.172.dist-info}/WHEEL +0 -0
- {xync_client-0.0.164.dist-info → xync_client-0.0.172.dist-info}/top_level.txt +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from asyncio import create_task
|
|
2
|
-
from bybit_p2p import P2P
|
|
3
2
|
from pyro_client.client.file import FileClient
|
|
4
3
|
from xync_bot import XyncBot
|
|
4
|
+
from xync_client.Abc.InAgent import BaseInAgentClient
|
|
5
5
|
from xync_schema.models import Agent
|
|
6
6
|
|
|
7
7
|
from xync_client.Bybit.agent import AgentClient
|
|
@@ -9,16 +9,11 @@ from xync_client.Bybit.ex import ExClient
|
|
|
9
9
|
|
|
10
10
|
from xync_schema import models
|
|
11
11
|
|
|
12
|
-
from xync_client.Bybit.etype.order import
|
|
13
|
-
OrderItem,
|
|
14
|
-
)
|
|
12
|
+
from xync_client.Bybit.etype.order import OrderItem
|
|
15
13
|
|
|
16
14
|
|
|
17
|
-
class InAgentClient(
|
|
18
|
-
|
|
19
|
-
agent: models.Agent
|
|
20
|
-
api: P2P
|
|
21
|
-
ex_client: ExClient
|
|
15
|
+
class InAgentClient(BaseInAgentClient):
|
|
16
|
+
agent_client: AgentClient
|
|
22
17
|
|
|
23
18
|
orders: dict[int, models.Order] = {}
|
|
24
19
|
|
|
@@ -33,4 +28,4 @@ class InAgentClient(AgentClient):
|
|
|
33
28
|
self.orders = {o.exid: o for o in await models.Order.filter(exid__in=po.keys())}
|
|
34
29
|
for oid in po.keys() - self.orders.keys():
|
|
35
30
|
fo = self.api.get_order_details(orderId=oid)
|
|
36
|
-
self.orders[oid] = await self.
|
|
31
|
+
self.orders[oid] = await self.order_save(fo)
|
xync_client/Bybit/order.py
CHANGED
|
@@ -1,28 +1,45 @@
|
|
|
1
|
-
from
|
|
2
|
-
|
|
1
|
+
from asyncio import sleep
|
|
2
|
+
|
|
3
|
+
from bybit_p2p._exceptions import FailedRequestError
|
|
4
|
+
from xync_client.Bybit.agent import AgentClient
|
|
3
5
|
|
|
4
6
|
from xync_client.Abc.Order import BaseOrderClient
|
|
5
7
|
|
|
6
8
|
|
|
7
9
|
class OrderClient(BaseOrderClient):
|
|
8
|
-
|
|
9
|
-
async def mark_payed(self, payterm: PaymentTerm = None, receipt: bytes = None):
|
|
10
|
-
if payterm:
|
|
11
|
-
pt = str(payterm.paymentType)
|
|
12
|
-
pid = payterm.id
|
|
13
|
-
else:
|
|
14
|
-
pmx = await PmEx.get(pm__pmcurs__id=self.order.cred.pmcur_id, ex=self.agent_client.ex_client.ex)
|
|
15
|
-
pt = pmx.exid
|
|
16
|
-
cdx = await CredEx.get(cred_id=self.order.cred_id, ex=self.agent_client.ex_client.ex)
|
|
17
|
-
pid = str(cdx.exid)
|
|
18
|
-
self.agent_client.api.mark_as_paid(orderId=str(self.order.exid), paymentType=pt, paymentId=pid)
|
|
10
|
+
agent_client: AgentClient
|
|
19
11
|
|
|
20
|
-
#
|
|
21
|
-
async def
|
|
12
|
+
# 5: Перевод сделки в состояние "оплачено", c отправкой чека
|
|
13
|
+
async def _mark_payed(self, credex_exid: int = None, pmex_exid: int | str = None, receipt: bytes = None):
|
|
14
|
+
params = dict(orderId=str(self.order.exid), paymentType=str(pmex_exid), paymentId=str(credex_exid))
|
|
15
|
+
try:
|
|
16
|
+
self.agent_client.api.mark_as_paid(**params)
|
|
17
|
+
except FailedRequestError as e:
|
|
18
|
+
if e.status_code == 912100202: # Server error, please try again later
|
|
19
|
+
await sleep(5, self.agent_client.api.mark_as_paid(**params))
|
|
20
|
+
else:
|
|
21
|
+
raise e
|
|
22
22
|
|
|
23
23
|
# 7: Подтвердить получение оплаты
|
|
24
24
|
async def confirm(self):
|
|
25
|
-
|
|
25
|
+
try:
|
|
26
|
+
self.agent_client.api.release_assets(orderId=str(self.order.exid))
|
|
27
|
+
except FailedRequestError as e:
|
|
28
|
+
if e.status_code == 912100202: # Server error, please try again later
|
|
29
|
+
await sleep(5, self.agent_client.api.release_assets(orderId=str(self.order.exid)))
|
|
30
|
+
else:
|
|
31
|
+
raise e
|
|
32
|
+
|
|
33
|
+
# 6: Отмена одобренной сделки
|
|
34
|
+
async def cancel(self) -> bool: ...
|
|
35
|
+
|
|
36
|
+
# 6: Запрос отмены (оплаченная контрагентом продажа)
|
|
37
|
+
async def cancel_request(self) -> bool: ...
|
|
38
|
+
|
|
39
|
+
# 6: Одобрение запроса на отмену (оплаченная мной покупка)
|
|
40
|
+
async def cancel_accept(self):
|
|
41
|
+
data = {"orderId": self.order.exid, "examineResult": "PASS"}
|
|
42
|
+
await self.agent_client._post("/x-api/fiat/otc/order/buyer/examine/sellerCancelOrderApply", data)
|
|
26
43
|
|
|
27
44
|
# 9, 10: Подать аппеляцию cо скриншотом/видео/файлом
|
|
28
45
|
async def start_appeal(self, file) -> bool: ...
|
xync_client/Htx/agent.py
CHANGED
|
@@ -9,7 +9,7 @@ from x_client import df_hdrs
|
|
|
9
9
|
from x_client.aiohttp import Client
|
|
10
10
|
from xync_bot import XyncBot
|
|
11
11
|
|
|
12
|
-
from xync_client.Abc.xtype import
|
|
12
|
+
from xync_client.Abc.xtype import AdUpdReq, GetAdsReq
|
|
13
13
|
from xync_client.Htx.etype.order import OrderItem, OrderFull
|
|
14
14
|
from xync_client.loader import NET_TOKEN, PAY_TOKEN, TORM
|
|
15
15
|
|
|
@@ -47,9 +47,9 @@ class AgentClient(BaseAgentClient):
|
|
|
47
47
|
await self.agent.save(update_fields=["auth"])
|
|
48
48
|
self.session.headers["Token"] = resp["data"]
|
|
49
49
|
|
|
50
|
-
async def
|
|
50
|
+
async def get_creds(self) -> list[test.BaseCredEpyd]:
|
|
51
51
|
resp = await self._get("/-/x/otc/v1/user/receipt-account")
|
|
52
|
-
return [test.
|
|
52
|
+
return [test.BaseCredEpyd(**cred) for cred in resp["data"]]
|
|
53
53
|
|
|
54
54
|
async def cred_del(self, cred_id: int) -> int:
|
|
55
55
|
data = {"id": str(cred_id), "password": self.actor.agent.auth["password"]}
|
|
@@ -161,7 +161,7 @@ class AgentClient(BaseAgentClient):
|
|
|
161
161
|
async def fiat_del(self, fiat_id: int) -> bool:
|
|
162
162
|
pass
|
|
163
163
|
|
|
164
|
-
async def
|
|
164
|
+
async def get_my_ads(self) -> list[dict]:
|
|
165
165
|
res = await self._get(url_my_ads)
|
|
166
166
|
ads: [] = res["data"]
|
|
167
167
|
if (pages := res["totalPage"]) > 1:
|
|
@@ -184,7 +184,7 @@ class AgentClient(BaseAgentClient):
|
|
|
184
184
|
) -> models.Ad:
|
|
185
185
|
pass
|
|
186
186
|
|
|
187
|
-
async def x2e_req_ad_upd(self, xreq:
|
|
187
|
+
async def x2e_req_ad_upd(self, xreq: AdUpdReq) -> ad.AdsUpd:
|
|
188
188
|
creds = [
|
|
189
189
|
ad.TradeRule(
|
|
190
190
|
content="Payment method-%s",
|
|
@@ -331,10 +331,10 @@ async def _test():
|
|
|
331
331
|
# _ = await cl.cred_del(16984748)
|
|
332
332
|
|
|
333
333
|
while True:
|
|
334
|
-
breq =
|
|
335
|
-
sreq =
|
|
336
|
-
breq_upd =
|
|
337
|
-
sreq_upd =
|
|
334
|
+
breq = GetAdsReq(coin_id=1, cur_id=1, is_sell=False, pm_ids=[366])
|
|
335
|
+
sreq = GetAdsReq(coin_id=1, cur_id=1, is_sell=True, pm_ids=[366])
|
|
336
|
+
breq_upd = AdUpdReq(id=1185713, price=87.01, **{**breq.model_dump(), "amount": 100000.01})
|
|
337
|
+
sreq_upd = AdUpdReq(id=1188929, price=98.99, **{**sreq.model_dump(), "amount": 200000.01})
|
|
338
338
|
|
|
339
339
|
bads: list[ad.Resp] = await cl.ex_client.ads(breq)
|
|
340
340
|
sads: list[ad.Resp] = await cl.ex_client.ads(sreq)
|
xync_client/Htx/etype/ad.py
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
from typing import Literal
|
|
2
|
-
|
|
3
2
|
from pydantic import BaseModel, RootModel
|
|
4
|
-
from xync_schema.xtype import BaseAd
|
|
5
3
|
|
|
6
|
-
from xync_client.Abc.xtype import
|
|
4
|
+
from xync_client.Abc.xtype import BaseAd
|
|
7
5
|
|
|
8
6
|
|
|
9
7
|
class TradeRule(BaseModel):
|
|
@@ -21,7 +19,7 @@ class TradeRule(BaseModel):
|
|
|
21
19
|
TradeRulesV2 = RootModel[list[TradeRule]]
|
|
22
20
|
|
|
23
21
|
|
|
24
|
-
class AdsUpd(
|
|
22
|
+
class AdsUpd(BaseAd):
|
|
25
23
|
tradeType: int
|
|
26
24
|
coinId: int
|
|
27
25
|
currency: int
|
xync_client/Htx/etype/test.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
from pydantic import BaseModel, Field
|
|
2
|
-
from xync_client.Abc.xtype import
|
|
2
|
+
from xync_client.Abc.xtype import BaseCredEx
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
class ModelField(BaseModel):
|
|
@@ -15,7 +15,7 @@ class ModelField(BaseModel):
|
|
|
15
15
|
value: str | None
|
|
16
16
|
|
|
17
17
|
|
|
18
|
-
class
|
|
18
|
+
class BaseCredEpyd(BaseCredEx):
|
|
19
19
|
id: int
|
|
20
20
|
uid: int
|
|
21
21
|
userName: str
|
|
@@ -34,13 +34,13 @@ class CredEpyd(CredExOut):
|
|
|
34
34
|
payMethodName: str
|
|
35
35
|
|
|
36
36
|
|
|
37
|
-
class
|
|
37
|
+
class BaseCredExId(BaseCredEx):
|
|
38
38
|
id: int = Field(validation_alias="bankId")
|
|
39
39
|
|
|
40
40
|
|
|
41
41
|
class Result(BaseModel):
|
|
42
42
|
code: int
|
|
43
|
-
data:
|
|
43
|
+
data: BaseCredExId
|
|
44
44
|
extend: str | None = None
|
|
45
45
|
message: str
|
|
46
46
|
success: bool
|
xync_client/Htx/ex.py
CHANGED
|
@@ -9,7 +9,7 @@ from xync_schema.models import Ex, Cur
|
|
|
9
9
|
from xync_schema.enums import PmType
|
|
10
10
|
|
|
11
11
|
from xync_client.Abc.Ex import BaseExClient
|
|
12
|
-
from xync_client.Abc.xtype import PmEx, MapOfIdsList,
|
|
12
|
+
from xync_client.Abc.xtype import PmEx, MapOfIdsList, GetAdsReq
|
|
13
13
|
from xync_client.Htx.etype import pm, Country, ad
|
|
14
14
|
from xync_client.loader import NET_TOKEN
|
|
15
15
|
from xync_client.loader import TORM
|
|
@@ -42,7 +42,7 @@ class ExClient(BaseExClient):
|
|
|
42
42
|
pair[rcurs[cur["name"]]] += [coen]
|
|
43
43
|
return tuple(pairs.values())
|
|
44
44
|
|
|
45
|
-
async def x2e_req_ads(self, xreq:
|
|
45
|
+
async def x2e_req_ads(self, xreq: GetAdsReq) -> ad.AdsReq:
|
|
46
46
|
coin_id, _ = await self.x2e_coin(xreq.coin_id)
|
|
47
47
|
cur_id, _, __ = await self.x2e_cur(xreq.cur_id)
|
|
48
48
|
ereq = ad.AdsReq(
|
|
@@ -106,7 +106,39 @@ class ExClient(BaseExClient):
|
|
|
106
106
|
# 22: Список платежных методов по каждой валюте
|
|
107
107
|
async def cur_pms_map(self) -> dict[int, set[int]]:
|
|
108
108
|
res = await self.data
|
|
109
|
-
wrong_pms = {
|
|
109
|
+
wrong_pms = {
|
|
110
|
+
4,
|
|
111
|
+
34,
|
|
112
|
+
498,
|
|
113
|
+
548,
|
|
114
|
+
20009,
|
|
115
|
+
20010,
|
|
116
|
+
10015,
|
|
117
|
+
20005,
|
|
118
|
+
20008,
|
|
119
|
+
10000,
|
|
120
|
+
10001,
|
|
121
|
+
10002,
|
|
122
|
+
10004,
|
|
123
|
+
20001,
|
|
124
|
+
20002,
|
|
125
|
+
20003,
|
|
126
|
+
20004,
|
|
127
|
+
20005,
|
|
128
|
+
20006,
|
|
129
|
+
20007,
|
|
130
|
+
10003,
|
|
131
|
+
10005,
|
|
132
|
+
10006,
|
|
133
|
+
10007,
|
|
134
|
+
10008,
|
|
135
|
+
10009,
|
|
136
|
+
10010,
|
|
137
|
+
10011,
|
|
138
|
+
10012,
|
|
139
|
+
10013,
|
|
140
|
+
10014,
|
|
141
|
+
} # , 212, 239, 363 # these ids not exist in pms
|
|
110
142
|
return {c["currencyId"]: set(c["supportPayments"]) - wrong_pms for c in res["currency"] if c["supportPayments"]}
|
|
111
143
|
|
|
112
144
|
# 23: Список торгуемых монет
|
xync_client/Mexc/agent.py
CHANGED
|
@@ -13,7 +13,7 @@ from xync_bot import XyncBot
|
|
|
13
13
|
from xync_client.Mexc.api import MEXCP2PApiClient
|
|
14
14
|
from xync_client.Mexc.etype import ad
|
|
15
15
|
|
|
16
|
-
from xync_client.Abc.xtype import
|
|
16
|
+
from xync_client.Abc.xtype import GetAdsReq, AdUpdReq
|
|
17
17
|
from xync_client.Bybit.etype.order import TakeAdReq
|
|
18
18
|
from xync_client.Mexc.etype.order import OrderDetail
|
|
19
19
|
|
|
@@ -114,7 +114,7 @@ class AgentClient(BaseAgentClient):
|
|
|
114
114
|
res = await self._post("/api/platform/p2p/api/order/deal?mhash=" + auth["mhash"], data=auth | data, hdrs=hdrs)
|
|
115
115
|
return res["data"]
|
|
116
116
|
|
|
117
|
-
async def x2e_req_ad_upd(self, xreq:
|
|
117
|
+
async def x2e_req_ad_upd(self, xreq: AdUpdReq) -> ad.AdUpd:
|
|
118
118
|
coin_id, coin_scale = await self.ex_client.x2e_coin(xreq.coin_id)
|
|
119
119
|
cur_id, cur_scale, minimum = await self.ex_client.x2e_cur(xreq.cur_id)
|
|
120
120
|
ereq = ad.AdUpd(
|
|
@@ -170,12 +170,12 @@ async def main():
|
|
|
170
170
|
while True:
|
|
171
171
|
bceil = 106
|
|
172
172
|
sceil = 124.98
|
|
173
|
-
breq =
|
|
174
|
-
sreq =
|
|
175
|
-
breq_upd =
|
|
173
|
+
breq = GetAdsReq(coin_id=1, cur_id=1, is_sell=False, pm_ids=[366])
|
|
174
|
+
sreq = GetAdsReq(coin_id=1, cur_id=1, is_sell=True, pm_ids=[366])
|
|
175
|
+
breq_upd = AdUpdReq(
|
|
176
176
|
id="a1574183931501582340", price=87, **{**breq.model_dump(), "amount": 11000.01}, max_amount=4370
|
|
177
177
|
) # + 1 cent
|
|
178
|
-
sreq_upd =
|
|
178
|
+
sreq_upd = AdUpdReq(id="a1594624084590445568", price=150, **{**sreq.model_dump(), "amount": 30000.01})
|
|
179
179
|
|
|
180
180
|
await sleep(5)
|
|
181
181
|
bads: list[ad.Ad] = await cl.ex_client.ads(breq)
|
xync_client/Mexc/ex.py
CHANGED
|
@@ -6,7 +6,7 @@ import requests
|
|
|
6
6
|
from xync_client.loader import TORM, NET_TOKEN
|
|
7
7
|
|
|
8
8
|
from xync_client.Abc.Ex import BaseExClient
|
|
9
|
-
from xync_client.Abc.xtype import PmEx, MapOfIdsList,
|
|
9
|
+
from xync_client.Abc.xtype import PmEx, MapOfIdsList, GetAdsReq
|
|
10
10
|
from xync_client.Mexc.etype import pm, ad
|
|
11
11
|
|
|
12
12
|
from xync_schema import xtype
|
|
@@ -77,7 +77,7 @@ class ExClient(BaseExClient):
|
|
|
77
77
|
self.pm_x2e[xid] = (await models.PmEx.get(**fltr)).exid
|
|
78
78
|
return self.pm_x2e[xid]
|
|
79
79
|
|
|
80
|
-
async def x2e_req_ads(self, xreq:
|
|
80
|
+
async def x2e_req_ads(self, xreq: GetAdsReq) -> ad.AdsReq:
|
|
81
81
|
coin_id, _ = await self.x2e_coin(xreq.coin_id)
|
|
82
82
|
cur_id, _, __ = await self.x2e_cur(xreq.cur_id)
|
|
83
83
|
ereq = ad.AdsReq(
|
xync_client/TgWallet/agent.py
CHANGED
|
@@ -10,7 +10,7 @@ from xync_client.TgWallet.ex import ExClient
|
|
|
10
10
|
from xync_schema import models
|
|
11
11
|
|
|
12
12
|
from xync_client.TgWallet.pyd import (
|
|
13
|
-
|
|
13
|
+
BaseCredEpyd,
|
|
14
14
|
Attrs,
|
|
15
15
|
AttrsV2,
|
|
16
16
|
OneAdTakerMakerSale,
|
|
@@ -36,7 +36,7 @@ from xync_schema.enums import AdStatus, UserStatus, OrderStatus
|
|
|
36
36
|
|
|
37
37
|
from xync_client.Abc.Base import ListOfDicts
|
|
38
38
|
from xync_client.TgWallet.auth import AuthClient
|
|
39
|
-
from xync_schema.xtype import
|
|
39
|
+
from xync_schema.xtype import BaseAd, AdBuy, AdSale, OrderIn
|
|
40
40
|
|
|
41
41
|
from xync_client.Abc.Agent import BaseAgentClient
|
|
42
42
|
|
|
@@ -110,21 +110,21 @@ class AgentClient(BaseAgentClient, AuthClient):
|
|
|
110
110
|
offerId=base_req.ad_id, type="SALE" if base_req.is_sell else "BUY", paymentDetailsId=credex.exid
|
|
111
111
|
)
|
|
112
112
|
ad = await models.Ad.get(exid=base_req.ad_id).prefetch_related(
|
|
113
|
-
"direction__pairex__pair__cur" if base_req.
|
|
113
|
+
"direction__pairex__pair__cur" if base_req.amount else "direction__pairex__pair__coin"
|
|
114
114
|
)
|
|
115
115
|
amount = AvailableAmountVolume(
|
|
116
116
|
currencyCode=ad.direction.pairex.pair.cur.ticker
|
|
117
|
-
if base_req.
|
|
117
|
+
if base_req.amount
|
|
118
118
|
else ad.direction.pairex.pair.coin.ticker,
|
|
119
|
-
amount=str(base_req.
|
|
119
|
+
amount=str(base_req.amount if base_req.amount else base_req.quantity),
|
|
120
120
|
)
|
|
121
121
|
req = (
|
|
122
122
|
OrderAmountReq(**common.model_dump(), amount=amount)
|
|
123
|
-
if base_req.
|
|
123
|
+
if base_req.amount
|
|
124
124
|
else OrderVolumeReq(**common.model_dump(), volume=amount)
|
|
125
125
|
)
|
|
126
126
|
request = await self._post(
|
|
127
|
-
f"/p2p/public-api/v2/offer/order/create-by-{'amount' if base_req.
|
|
127
|
+
f"/p2p/public-api/v2/offer/order/create-by-{'amount' if base_req.amount else 'volume'}",
|
|
128
128
|
req.model_dump(exclude_none=True),
|
|
129
129
|
)
|
|
130
130
|
if r := request.get("data"):
|
|
@@ -170,8 +170,8 @@ class AgentClient(BaseAgentClient, AuthClient):
|
|
|
170
170
|
|
|
171
171
|
# # # CREDS # # #
|
|
172
172
|
@staticmethod
|
|
173
|
-
def fiat_args2ex_pyd(exid: int | str, cur: str, detail: str, name: str, typ: str, extra=None) ->
|
|
174
|
-
cred =
|
|
173
|
+
def fiat_args2ex_pyd(exid: int | str, cur: str, detail: str, name: str, typ: str, extra=None) -> BaseCredEpyd:
|
|
174
|
+
cred = BaseCredEpyd(
|
|
175
175
|
paymentMethodCode=exid,
|
|
176
176
|
currencyCode=cur,
|
|
177
177
|
name=name,
|
|
@@ -201,11 +201,11 @@ class AgentClient(BaseAgentClient, AuthClient):
|
|
|
201
201
|
}
|
|
202
202
|
|
|
203
203
|
# 25: Список реквизитов моих платежных методов
|
|
204
|
-
async def
|
|
204
|
+
async def get_creds(self) -> list[BaseCredEpyd]:
|
|
205
205
|
resp = await self._post("/p2p/public-api/v3/payment-details/get/by-user-id")
|
|
206
|
-
return [
|
|
206
|
+
return [BaseCredEpyd(**cred) for cred in resp["data"]]
|
|
207
207
|
|
|
208
|
-
async def cred_epyd2db(self, cred:
|
|
208
|
+
async def cred_epyd2db(self, cred: BaseCredEpyd) -> models.CredEx:
|
|
209
209
|
if not (pmex := await models.PmEx.get_or_none(exid=cred.paymentMethod.code, ex=self.ex_client.ex)):
|
|
210
210
|
raise HTTPException(f"No PmEx {cred.paymentMethod.code} on ex#{self.ex_client.ex.name}", 404)
|
|
211
211
|
if not (pmcur := await models.PmCur.get_or_none(cur__ticker=cred.currency, pm_id=pmex.pm_id)):
|
|
@@ -229,8 +229,8 @@ class AgentClient(BaseAgentClient, AuthClient):
|
|
|
229
229
|
return credex_db
|
|
230
230
|
|
|
231
231
|
# 25: Список реквизитов моих платежных методов
|
|
232
|
-
async def
|
|
233
|
-
creds_epyd: list[
|
|
232
|
+
async def load_creds(self) -> list[models.CredEx]:
|
|
233
|
+
creds_epyd: list[BaseCredEpyd] = await self.creds()
|
|
234
234
|
credexs: list[models.CredEx] = [await self.cred_epyd2db(f) for f in creds_epyd]
|
|
235
235
|
return credexs
|
|
236
236
|
|
|
@@ -272,7 +272,7 @@ class AgentClient(BaseAgentClient, AuthClient):
|
|
|
272
272
|
else:
|
|
273
273
|
hdrs = {}
|
|
274
274
|
add_cred = await self._post("/p2p/public-api/v3/payment-details/create", cred_new, headers=hdrs)
|
|
275
|
-
cred_epyd =
|
|
275
|
+
cred_epyd = BaseCredEpyd(**add_cred["data"])
|
|
276
276
|
return await self.cred_epyd2db(cred_epyd)
|
|
277
277
|
|
|
278
278
|
# 27: Редактирование реквизита моего платежного метода
|
|
@@ -298,7 +298,7 @@ class AgentClient(BaseAgentClient, AuthClient):
|
|
|
298
298
|
"x-wallet-device-serial": self.actor.agent.auth["ds"],
|
|
299
299
|
}
|
|
300
300
|
edit_cred = await self._post("/p2p/public-api/v3/payment-details/edit", cred_upd, headers=hdrs)
|
|
301
|
-
cred_epyd =
|
|
301
|
+
cred_epyd = BaseCredEpyd(**edit_cred["data"])
|
|
302
302
|
return await self.cred_epyd2db(cred_epyd)
|
|
303
303
|
|
|
304
304
|
# 28: Удаление реквизита моего платежного метода
|
|
@@ -310,19 +310,19 @@ class AgentClient(BaseAgentClient, AuthClient):
|
|
|
310
310
|
else:
|
|
311
311
|
logging.error(res)
|
|
312
312
|
|
|
313
|
-
async def ad_epyd2pydin(self, ad_: OneAdTakerMakerSale | OneAdMakerBuy | OneAdTakerBuy) ->
|
|
314
|
-
ad_in:
|
|
313
|
+
async def ad_epyd2pydin(self, ad_: OneAdTakerMakerSale | OneAdMakerBuy | OneAdTakerBuy) -> AdBuy | AdSale:
|
|
314
|
+
ad_in: BaseAd = await self.ex_client.ad_common_epyd2pydin(ad_)
|
|
315
315
|
ad_in.maker_id = self.actor.id
|
|
316
316
|
if isinstance(ad_, _PmsTrait):
|
|
317
|
-
return
|
|
317
|
+
return AdBuy(
|
|
318
318
|
**ad_in.model_dump(),
|
|
319
319
|
pmexs_=await models.PmEx.filter(ex=self.ex_client.ex, exid__in=[p.code for p in ad_.paymentMethods]),
|
|
320
320
|
)
|
|
321
321
|
credsexs: list[models.CredEx] = [await self.cred_epyd2db(c) for c in ad_.paymentDetails]
|
|
322
|
-
return
|
|
322
|
+
return AdSale(**ad_in.model_dump(), credexs_=credsexs)
|
|
323
323
|
|
|
324
324
|
# 29: Список моих объявлений
|
|
325
|
-
async def
|
|
325
|
+
async def get_my_ads(self, status: AdStatus = None) -> list[AdMakerBuy | AdMakerSale]:
|
|
326
326
|
def model(ad: dict) -> (AdMakerBuy | AdMakerSale).__class__:
|
|
327
327
|
return AdMakerSale if ad["type"] == "SALE" else AdMakerBuy
|
|
328
328
|
|
xync_client/TgWallet/ex.py
CHANGED
|
@@ -4,7 +4,7 @@ from pyro_client.client.file import FileClient
|
|
|
4
4
|
from x_model import init_db
|
|
5
5
|
from xync_schema import xtype
|
|
6
6
|
from xync_schema import models
|
|
7
|
-
from xync_schema.xtype import
|
|
7
|
+
from xync_schema.xtype import AdBuy
|
|
8
8
|
|
|
9
9
|
from xync_client.Abc.xtype import PmEx
|
|
10
10
|
from xync_client.TgWallet.pyd import (
|
|
@@ -124,30 +124,30 @@ class ExClient(BaseExClient, AuthClient):
|
|
|
124
124
|
ads = await self._post("/p2p/public-api/v2/offer/depth-of-market/", params, "data")
|
|
125
125
|
return [AdTakerSaleBuy(**ad) for ad in ads]
|
|
126
126
|
|
|
127
|
-
async def ad_common_epyd2pydin(self, ad: _BaseAd) -> xtype.
|
|
127
|
+
async def ad_common_epyd2pydin(self, ad: _BaseAd) -> xtype.BaseAd:
|
|
128
128
|
coin = await models.Coin.get_or_create_by_name(ad.price.baseCurrencyCode)
|
|
129
129
|
cur = await models.Cur.get_or_create_by_name(ad.price.quoteCurrencyCode)
|
|
130
130
|
pair, _ = await models.Pair.get_or_create(coin=coin, cur=cur)
|
|
131
131
|
pairex, _ = await models.PairEx.get_or_create(pair=pair, ex=self.ex)
|
|
132
132
|
dr, _ = await models.Direction.get_or_create(pairex=pairex, sell=ad.is_sell)
|
|
133
|
-
return xtype.
|
|
133
|
+
return xtype.BaseAd(
|
|
134
134
|
id=ad.id,
|
|
135
135
|
price=ad.price.value,
|
|
136
136
|
min_fiat=ad.orderAmountLimits.min,
|
|
137
137
|
amount=float(ad.availableVolume.amount) * float(ad.price.estimated),
|
|
138
138
|
max_fiat=ad.orderAmountLimits.max,
|
|
139
|
-
|
|
139
|
+
pair_side_id=dr.id,
|
|
140
140
|
detail=getattr(ad, "comment", None),
|
|
141
141
|
)
|
|
142
142
|
|
|
143
|
-
async def ad_taker_epyd2pydin(self, ad: _TakerOne) -> xtype.
|
|
144
|
-
adx: xtype.
|
|
143
|
+
async def ad_taker_epyd2pydin(self, ad: _TakerOne) -> xtype.AdBuy:
|
|
144
|
+
adx: xtype.BaseAd = await self.ad_common_epyd2pydin(ad)
|
|
145
145
|
act_unq = dict(ex=self.ex, exid=ad.user.userId)
|
|
146
146
|
if not (actor := await models.Actor.get_or_none(**act_unq)):
|
|
147
147
|
actor = await models.Actor.create(**act_unq, name=ad.user.nickname, person=await models.Person.create())
|
|
148
148
|
adx.maker = actor
|
|
149
149
|
pms = ad.paymentMethods if isinstance(ad, _PmsTrait) else [pd.paymentMethod for pd in ad.paymentDetails]
|
|
150
|
-
return xtype.
|
|
150
|
+
return xtype.AdBuy(
|
|
151
151
|
**adx.model_dump(by_alias=True),
|
|
152
152
|
pms_=await models.Pm.filter(pmexs__ex=self.ex, pmexs__exid__in=[p.code for p in pms]),
|
|
153
153
|
)
|
|
@@ -167,14 +167,14 @@ async def _test():
|
|
|
167
167
|
# get ads list
|
|
168
168
|
ads: list[AdTakerSaleBuy] = await cl.ads("TON", "RUB", True)
|
|
169
169
|
# prepare ad list items for saving
|
|
170
|
-
ads_pydin: list[xtype.
|
|
170
|
+
ads_pydin: list[xtype.BaseAd] = [await cl.ad_taker_epyd2pydin(adp) for adp in ads]
|
|
171
171
|
# list items save
|
|
172
172
|
_ads_db = [await cl.ad_pydin2db(adi) for adi in ads_pydin]
|
|
173
173
|
|
|
174
174
|
# get ad fulls
|
|
175
175
|
ads_pyd: list[_TakerOne] = [await cl.ad(ad.exid) for ad in ads]
|
|
176
176
|
# prepare ad fulls for saving
|
|
177
|
-
ads_pydin: list[
|
|
177
|
+
ads_pydin: list[AdBuy] = [await cl.ad_taker_epyd2pydin(adp) for adp in ads_pyd]
|
|
178
178
|
# full ones save
|
|
179
179
|
_ads_db = [await sleep(0.1, await cl.ad_pydin2db(adi)) for adi in ads_pydin]
|
|
180
180
|
|
|
@@ -182,14 +182,14 @@ async def _test():
|
|
|
182
182
|
# get ads list
|
|
183
183
|
ads: list[AdTakerSaleBuy] = await cl.ads("TON", "RUB", False)
|
|
184
184
|
# prepare ad list items for saving
|
|
185
|
-
ads_pydin: list[xtype.
|
|
185
|
+
ads_pydin: list[xtype.BaseAd] = [await cl.ad_taker_epyd2pydin(adp) for adp in ads]
|
|
186
186
|
# list items save
|
|
187
187
|
_ads_db = [await cl.ad_pydin2db(adi) for adi in ads_pydin]
|
|
188
188
|
|
|
189
189
|
# get ad fulls
|
|
190
190
|
ads_pyd = [await cl.ad(ad.exid) for ad in ads]
|
|
191
191
|
# prepare ad fulls for saving
|
|
192
|
-
ads_pydin: list[
|
|
192
|
+
ads_pydin: list[AdBuy] = [await cl.ad_taker_epyd2pydin(adp) for adp in ads_pyd]
|
|
193
193
|
# full ones save
|
|
194
194
|
_ads_db = [await cl.ad_pydin2db(adi) for adi in ads_pydin]
|
|
195
195
|
|
xync_client/TgWallet/pyd.py
CHANGED
|
@@ -2,7 +2,7 @@ from typing import Literal
|
|
|
2
2
|
from pydantic import BaseModel, computed_field
|
|
3
3
|
from xync_schema.xtype import BaseAd
|
|
4
4
|
|
|
5
|
-
from xync_client.Abc.xtype import
|
|
5
|
+
from xync_client.Abc.xtype import BaseCredEx
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
# Модели для вложенных структур
|
|
@@ -126,7 +126,7 @@ class CredEpydUpd(CredEpydNew):
|
|
|
126
126
|
id: int
|
|
127
127
|
|
|
128
128
|
|
|
129
|
-
class
|
|
129
|
+
class BaseCredEpyd(BaseCredEx):
|
|
130
130
|
id: int
|
|
131
131
|
userId: int
|
|
132
132
|
paymentMethod: PmEpydRoot
|
|
@@ -194,7 +194,7 @@ class AdTakerSaleBuy(_BaseAd, _PmsTrait, _UserTrait):
|
|
|
194
194
|
|
|
195
195
|
|
|
196
196
|
class OneAdTakerMakerSale(_TakerOne):
|
|
197
|
-
paymentDetails: list[
|
|
197
|
+
paymentDetails: list[BaseCredEpyd]
|
|
198
198
|
fee: Fee
|
|
199
199
|
|
|
200
200
|
|
|
@@ -208,7 +208,7 @@ class OneAdMakerBuy(_BaseAd, _OneTrait, _PmsTrait): ...
|
|
|
208
208
|
|
|
209
209
|
|
|
210
210
|
class AdMakerSale(_BaseAd, _StatusTrait):
|
|
211
|
-
paymentDetails: list[
|
|
211
|
+
paymentDetails: list[BaseCredEpyd]
|
|
212
212
|
|
|
213
213
|
|
|
214
214
|
# # #
|
|
@@ -278,7 +278,7 @@ class OrderEpyd(BaseModel):
|
|
|
278
278
|
offerType: AdType
|
|
279
279
|
isExpress: bool
|
|
280
280
|
price: Price
|
|
281
|
-
paymentDetails:
|
|
281
|
+
paymentDetails: BaseCredEpyd
|
|
282
282
|
volume: AvailableAmountVolume
|
|
283
283
|
amount: AvailableAmountVolume
|
|
284
284
|
feeVolume: AvailableAmountVolume
|
xync_client/pm_unifier.py
CHANGED
|
@@ -17,7 +17,7 @@ class PmUnifier:
|
|
|
17
17
|
pms: dict[str, PmUni] = {} # {origin: normalized}
|
|
18
18
|
|
|
19
19
|
re_bank = [
|
|
20
|
-
r"^bank (?!(of |transfer))|(?<!(to|the)\s) bank$",
|
|
20
|
+
r"^bank (?!(of |transfer))|(?<!( to|the)\s) bank$",
|
|
21
21
|
r" banka$",
|
|
22
22
|
r" bankas$",
|
|
23
23
|
r" bankasi$",
|
|
@@ -124,7 +124,8 @@ class PmUnifier:
|
|
|
124
124
|
|
|
125
125
|
def bank(self, name: str):
|
|
126
126
|
for r in self.re_bank:
|
|
127
|
-
|
|
127
|
+
match = re.search(r, self.pms[name].norm)
|
|
128
|
+
if match and match.group() != self.pms[name].norm:
|
|
128
129
|
self.pms[name].norm = self.pms[name].norm.replace(match.group(), "")
|
|
129
130
|
self.pms[name].bank = True
|
|
130
131
|
self.clear(name)
|