xync-client 0.0.164__py3-none-any.whl → 0.0.179.dev4__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.
@@ -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(AgentClient):
18
- actor: models.Actor
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.create_order_db(fo)
31
+ self.orders[oid] = await self.order_save(fo)
@@ -1,28 +1,48 @@
1
- from xync_client.Bybit.etype.cred import PaymentTerm
2
- from xync_schema.models import CredEx, PmEx
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
- # 5: Перевод сделки в состояние "оплачено", c отправкой чека
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
- # 6: Отмена одобренной сделки
21
- async def cancel_order(self) -> bool: ...
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
- self.agent_client.api.release_assets(orderId=str(self.order.exid))
25
+ try:
26
+ res = 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)
30
+ res = self.agent_client.api.release_assets(orderId=str(self.order.exid))
31
+ else:
32
+ raise e
33
+ return res
34
+
35
+ # 6: Отмена одобренной сделки
36
+ async def cancel(self) -> bool: ...
37
+
38
+ # 6: Запрос отмены (оплаченная контрагентом продажа)
39
+ async def cancel_request(self) -> bool: ...
40
+
41
+ # 6: Одобрение запроса на отмену (оплаченная мной покупка)
42
+ async def cancel_accept(self) -> bool:
43
+ data = {"orderId": str(self.order.exid), "examineResult": "PASS"}
44
+ res = await self.agent_client._post("/x-api/fiat/otc/order/buyer/examine/sellerCancelOrderApply", data)
45
+ return res["ret_code"] == 0
26
46
 
27
47
  # 9, 10: Подать аппеляцию cо скриншотом/видео/файлом
28
48
  async def start_appeal(self, file) -> bool: ...
@@ -33,6 +53,12 @@ class OrderClient(BaseOrderClient):
33
53
  # 15: Отмена аппеляции
34
54
  async def cancel_appeal(self) -> bool: ...
35
55
 
56
+ async def appeal_accept(self) -> bool:
57
+ data = {"orderId": str(self.order.exid)}
58
+ # Принять аппеляцию: я покупатель, прожал оплачено, продавец оспорил, я согл, ордер отменился
59
+ res = await self.agent_client._post("/x-api/fiat/otc/order/cancelAfterCustomerNegotiation", data)
60
+ return res["ret_code"] == 0
61
+
36
62
  # 16: Отправка сообщения юзеру в чат по ордеру с приложенным файлом
37
63
  async def send_order_msg(self, msg: str, file=None) -> bool: ...
38
64
 
xync_client/Gate/ex.py CHANGED
@@ -94,11 +94,11 @@ async def main():
94
94
  _ = await init_db(TORM, True)
95
95
  gt = await Ex.get(name="Gate")
96
96
  async with FileClient(NET_TOKEN) as b:
97
- cl = ExClient(gt, b)
97
+ cl = ExClient(gt)
98
98
  await cl.set_pairs()
99
99
  pms = await cl.set_coins()
100
100
  pms = await cl.cur_pms_map()
101
- pms = await cl.set_pms()
101
+ pms = await cl.set_pms(b)
102
102
  pms = await cl.set_coins()
103
103
  pms = await cl.set_curs()
104
104
  _ads = await cl.ads("USDT", "RUB", True, ["payeer"], 1000)
xync_client/Htx/agent.py CHANGED
@@ -4,14 +4,12 @@ from time import time
4
4
  from urllib.parse import quote
5
5
 
6
6
  from aiohttp import ClientResponse
7
- from pyro_client.client.file import FileClient
8
7
  from x_client import df_hdrs
9
8
  from x_client.aiohttp import Client
10
- from xync_bot import XyncBot
11
9
 
12
- from xync_client.Abc.xtype import AdUpd, GetAds
10
+ from xync_client.Abc.xtype import AdUpdReq, GetAdsReq
13
11
  from xync_client.Htx.etype.order import OrderItem, OrderFull
14
- from xync_client.loader import NET_TOKEN, PAY_TOKEN, TORM
12
+ from xync_client.loader import TORM
15
13
 
16
14
  from xync_schema.enums import AdStatus, PmType, OrderStatus
17
15
  from xync_schema import models
@@ -47,9 +45,9 @@ class AgentClient(BaseAgentClient):
47
45
  await self.agent.save(update_fields=["auth"])
48
46
  self.session.headers["Token"] = resp["data"]
49
47
 
50
- async def creds(self) -> list[test.CredEpyd]:
48
+ async def get_creds(self) -> list[test.BaseCredEpyd]:
51
49
  resp = await self._get("/-/x/otc/v1/user/receipt-account")
52
- return [test.CredEpyd(**cred) for cred in resp["data"]]
50
+ return [test.BaseCredEpyd(**cred) for cred in resp["data"]]
53
51
 
54
52
  async def cred_del(self, cred_id: int) -> int:
55
53
  data = {"id": str(cred_id), "password": self.actor.agent.auth["password"]}
@@ -161,7 +159,7 @@ class AgentClient(BaseAgentClient):
161
159
  async def fiat_del(self, fiat_id: int) -> bool:
162
160
  pass
163
161
 
164
- async def my_ads(self) -> list[dict]:
162
+ async def get_my_ads(self) -> list[dict]:
165
163
  res = await self._get(url_my_ads)
166
164
  ads: [] = res["data"]
167
165
  if (pages := res["totalPage"]) > 1:
@@ -184,7 +182,7 @@ class AgentClient(BaseAgentClient):
184
182
  ) -> models.Ad:
185
183
  pass
186
184
 
187
- async def x2e_req_ad_upd(self, xreq: AdUpd) -> ad.AdsUpd:
185
+ async def x2e_req_ad_upd(self, xreq: AdUpdReq) -> ad.AdsUpd:
188
186
  creds = [
189
187
  ad.TradeRule(
190
188
  content="Payment method-%s",
@@ -309,10 +307,9 @@ class AgentClient(BaseAgentClient):
309
307
  async def _test():
310
308
  from x_model import init_db
311
309
 
312
- cn = await init_db(TORM, True)
310
+ _cn = await init_db(TORM, True)
313
311
  ex = await models.Ex[9]
314
- filebot = FileClient(NET_TOKEN)
315
- ecl = ex.client(filebot)
312
+ ecl = ex.client()
316
313
  agent = (
317
314
  await models.Agent.filter(actor__ex=ex, auth__isnull=False)
318
315
  .prefetch_related(
@@ -324,17 +321,17 @@ async def _test():
324
321
  )
325
322
  .first()
326
323
  )
327
- cl: AgentClient = agent.client(ecl, filebot, XyncBot(PAY_TOKEN, cn))
324
+ cl: AgentClient = agent.client(ecl)
328
325
  # cred = await models.Cred[89]
329
326
  # _ = await cl.cred_new(cred)
330
327
  # _creds = await cl.creds()
331
328
  # _ = await cl.cred_del(16984748)
332
329
 
333
330
  while True:
334
- breq = GetAds(coin_id=1, cur_id=1, is_sell=False, pm_ids=[366])
335
- sreq = GetAds(coin_id=1, cur_id=1, is_sell=True, pm_ids=[366])
336
- breq_upd = AdUpd(id=1185713, price=87.01, **{**breq.model_dump(), "amount": 100000.01})
337
- sreq_upd = AdUpd(id=1188929, price=98.99, **{**sreq.model_dump(), "amount": 200000.01})
331
+ breq = GetAdsReq(coin_id=1, cur_id=1, is_sell=False, pm_ids=[366])
332
+ sreq = GetAdsReq(coin_id=1, cur_id=1, is_sell=True, pm_ids=[366])
333
+ breq_upd = AdUpdReq(id=1185713, price=87.01, **{**breq.model_dump(), "amount": 100000.01})
334
+ sreq_upd = AdUpdReq(id=1188929, price=98.99, **{**sreq.model_dump(), "amount": 200000.01})
338
335
 
339
336
  bads: list[ad.Resp] = await cl.ex_client.ads(breq)
340
337
  sads: list[ad.Resp] = await cl.ex_client.ads(sreq)
@@ -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 BaseAdUpdate
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(BaseAdUpdate):
22
+ class AdsUpd(BaseAd):
25
23
  tradeType: int
26
24
  coinId: int
27
25
  currency: int
@@ -1,5 +1,5 @@
1
1
  from pydantic import BaseModel, Field
2
- from xync_client.Abc.xtype import CredExOut
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 CredEpyd(CredExOut):
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 CredExId(CredExOut):
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: CredExId
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, GetAds
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: GetAds) -> ad.AdsReq:
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 = {4, 34, 498, 548, 20009, 20010} # , 212, 239, 363 # these ids not exist in 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: Список торгуемых монет
@@ -156,9 +188,9 @@ async def main():
156
188
  ex = await Ex.get(name="Htx")
157
189
  async with FileClient(NET_TOKEN) as b:
158
190
  b: FileClient
159
- cl = ExClient(ex, b)
191
+ cl = ExClient(ex)
160
192
  await cl.set_curs()
161
- await cl.set_pms()
193
+ await cl.set_pms(b)
162
194
  await cl.set_coins()
163
195
  await cl.set_pairs()
164
196
  # _pms = await cl.pms()
xync_client/KuCoin/ex.py CHANGED
@@ -81,8 +81,8 @@ async def main():
81
81
  _ = await init_db(TORM, True)
82
82
  bg = await models.Ex.get(name="KuCoin")
83
83
  async with FileClient(NET_TOKEN) as b:
84
- cl: ExClient = bg.client(b)
85
- await cl.set_pms()
84
+ cl = ExClient(bg)
85
+ await cl.set_pms(b)
86
86
  await cl.set_coins()
87
87
  await cl.set_pairs()
88
88
 
xync_client/Mexc/agent.py CHANGED
@@ -7,17 +7,16 @@ from uuid import uuid4
7
7
 
8
8
  import websockets
9
9
  from blackboxprotobuf import protobuf_to_json
10
- from pyro_client.client.file import FileClient
11
10
  from xync_bot import XyncBot
12
11
 
13
12
  from xync_client.Mexc.api import MEXCP2PApiClient
14
13
  from xync_client.Mexc.etype import ad
15
14
 
16
- from xync_client.Abc.xtype import GetAds, AdUpd
15
+ from xync_client.Abc.xtype import GetAdsReq, AdUpdReq
17
16
  from xync_client.Bybit.etype.order import TakeAdReq
18
17
  from xync_client.Mexc.etype.order import OrderDetail
19
18
 
20
- from xync_client.loader import PAY_TOKEN, NET_TOKEN
19
+ from xync_client.loader import PAY_TOKEN
21
20
  from xync_schema import models
22
21
  from xync_schema.enums import UserStatus, AgentStatus
23
22
 
@@ -114,7 +113,7 @@ class AgentClient(BaseAgentClient):
114
113
  res = await self._post("/api/platform/p2p/api/order/deal?mhash=" + auth["mhash"], data=auth | data, hdrs=hdrs)
115
114
  return res["data"]
116
115
 
117
- async def x2e_req_ad_upd(self, xreq: AdUpd) -> ad.AdUpd:
116
+ async def x2e_req_ad_upd(self, xreq: AdUpdReq) -> ad.AdUpd:
118
117
  coin_id, coin_scale = await self.ex_client.x2e_coin(xreq.coin_id)
119
118
  cur_id, cur_scale, minimum = await self.ex_client.x2e_cur(xreq.cur_id)
120
119
  ereq = ad.AdUpd(
@@ -161,27 +160,26 @@ async def main():
161
160
  .first()
162
161
  )
163
162
  bbot = XyncBot(PAY_TOKEN, cn)
164
- fbot = FileClient(NET_TOKEN)
165
- ecl = ex.client(fbot)
166
- cl: AgentClient = agent.client(ecl, fbot, bbot)
163
+ ecl = ex.client()
164
+ cl: AgentClient = agent.client(ecl)
167
165
  cl.api = MEXCP2PApiClient(agent.auth["key"], agent.auth["sec"])
168
166
  create_task(cl.ws_prv())
169
167
 
170
168
  while True:
171
169
  bceil = 106
172
170
  sceil = 124.98
173
- breq = GetAds(coin_id=1, cur_id=1, is_sell=False, pm_ids=[366])
174
- sreq = GetAds(coin_id=1, cur_id=1, is_sell=True, pm_ids=[366])
175
- breq_upd = AdUpd(
171
+ breq = GetAdsReq(coin_id=1, cur_id=1, is_sell=False, pm_ids=[366])
172
+ sreq = GetAdsReq(coin_id=1, cur_id=1, is_sell=True, pm_ids=[366])
173
+ breq_upd = AdUpdReq(
176
174
  id="a1574183931501582340", price=87, **{**breq.model_dump(), "amount": 11000.01}, max_amount=4370
177
175
  ) # + 1 cent
178
- sreq_upd = AdUpd(id="a1594624084590445568", price=150, **{**sreq.model_dump(), "amount": 30000.01})
176
+ sreq_upd = AdUpdReq(id="a1594624084590445568", price=150, **{**sreq.model_dump(), "amount": 30000.01})
179
177
 
180
178
  await sleep(5)
181
179
  bads: list[ad.Ad] = await cl.ex_client.ads(breq)
182
180
  if bads[0].price >= sceil:
183
181
  bad: ad.Ad = bads.pop(0)
184
- await cl.bbot.send(
182
+ await bbot.send(
185
183
  193017646,
186
184
  f"price: {bad.price}\nnick: {bad.merchant.nickName}\nmax:{bad.maxPayLimit}"
187
185
  f"\nqty: {bad.availableQuantity} [{bad.minTradeLimit}-{bad.maxTradeLimit}]",
@@ -219,7 +217,7 @@ async def main():
219
217
  sads: list[ad.Ad] = await cl.ex_client.ads(sreq)
220
218
  if sads[0].price <= bceil:
221
219
  sad: ad.Ad = sads.pop(0)
222
- await cl.bbot.send(
220
+ await bbot.send(
223
221
  193017646,
224
222
  f"price: {sad.price}\nnick: {sad.merchant.nickName}\nmax:{sad.maxPayLimit}"
225
223
  f"\nqty: {sad.availableQuantity} [{sad.minTradeLimit}-{sad.maxTradeLimit}]",
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, GetAds
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: GetAds) -> ad.AdsReq:
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(
@@ -101,11 +101,11 @@ class ExClient(BaseExClient):
101
101
 
102
102
  async def main():
103
103
  _ = await init_db(TORM)
104
- async with FileClient(NET_TOKEN) as b:
104
+ async with FileClient(NET_TOKEN):
105
105
  ex = await Ex.get(name="Mexc")
106
- cl: ExClient = ex.client(b)
106
+ cl = ExClient(ex)
107
107
  # await ex.curexs.filter(cur__ticker="EUR")
108
- # await cl.set_pms()
108
+ # await cl.set_pms(b)
109
109
  # await cl.set_coinexs()
110
110
  coinex = await models.CoinEx.get(ex=cl.ex, coin_id=1)
111
111
  _ads = await cl.ads(coinex.exid, "RUB", True, ["5"])
xync_client/Okx/agent.py CHANGED
@@ -1,13 +1,9 @@
1
- from pyro_client.client.file import FileClient
2
- from xync_bot import XyncBot
3
-
4
1
  from xync_client.Abc.Agent import BaseAgentClient
5
2
  from asyncio import run
6
3
  from x_model import init_db
7
4
  from xync_schema.models import Agent, Ex
8
5
 
9
6
  from xync_client.Okx.ex import ExClient
10
- from xync_client.loader import NET_TOKEN, PAY_TOKEN
11
7
 
12
8
 
13
9
  class AgentClient(BaseAgentClient):
@@ -22,13 +18,11 @@ class AgentClient(BaseAgentClient):
22
18
  async def main():
23
19
  from xync_client.loader import TORM
24
20
 
25
- cn = await init_db(TORM)
21
+ _cn = await init_db(TORM)
26
22
  ex = await Ex.get(name="Okx")
27
23
  agent = await Agent.get(actor__ex=ex).prefetch_related("actor__ex", "actor__person__user__gmail")
28
- fbot = FileClient(NET_TOKEN)
29
- ecl: ExClient = ex.client(fbot)
30
- abot = XyncBot(PAY_TOKEN, cn)
31
- cl = agent.client(ecl, fbot, abot)
24
+ ecl: ExClient = ex.client()
25
+ cl = agent.client(ecl)
32
26
 
33
27
  _fiats = await cl.my_fiats()
34
28
 
xync_client/Okx/ex.py CHANGED
@@ -102,16 +102,17 @@ class ExClient(BaseExClient):
102
102
  async def main():
103
103
  _ = await init_db(TORM)
104
104
  bg = await models.Ex.get(name="Okx")
105
- cl = ExClient(bg, FileClient(NET_TOKEN))
106
- await cl.ads("USDT", "EUR", True)
107
- # curs = await cl.curs()
108
- # coins = await cl.coins()
109
- await cl.pms()
110
- await cl.cur_pms_map()
111
- await cl.pairs()
112
- await cl.set_coins()
113
- await cl.set_pms()
114
- await cl.close()
105
+ async with FileClient(NET_TOKEN) as b:
106
+ cl = ExClient(bg)
107
+ await cl.ads("USDT", "EUR", True)
108
+ # curs = await cl.curs()
109
+ # coins = await cl.coins()
110
+ await cl.pms()
111
+ await cl.cur_pms_map()
112
+ await cl.pairs()
113
+ await cl.set_coins()
114
+ await cl.set_pms(b)
115
+ await cl.close()
115
116
 
116
117
 
117
118
  if __name__ == "__main__":
@@ -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
- CredEpyd,
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 BaseAdIn, AdBuyIn, AdSaleIn, OrderIn
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.fiat_amount else "direction__pairex__pair__coin"
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.fiat_amount
117
+ if base_req.amount
118
118
  else ad.direction.pairex.pair.coin.ticker,
119
- amount=str(base_req.fiat_amount if base_req.fiat_amount else base_req.asset_amount),
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.fiat_amount
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.fiat_amount else 'volume'}",
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) -> CredEpyd:
174
- cred = CredEpyd(
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 creds(self) -> list[CredEpyd]:
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 [CredEpyd(**cred) for cred in resp["data"]]
206
+ return [BaseCredEpyd(**cred) for cred in resp["data"]]
207
207
 
208
- async def cred_epyd2db(self, cred: CredEpyd) -> models.CredEx:
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 set_creds(self) -> list[models.CredEx]:
233
- creds_epyd: list[CredEpyd] = await self.creds()
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 = CredEpyd(**add_cred["data"])
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 = CredEpyd(**edit_cred["data"])
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) -> AdBuyIn | AdSaleIn:
314
- ad_in: BaseAdIn = await self.ex_client.ad_common_epyd2pydin(ad_)
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 AdBuyIn(
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 AdSaleIn(**ad_in.model_dump(), credexs_=credsexs)
322
+ return AdSale(**ad_in.model_dump(), credexs_=credsexs)
323
323
 
324
324
  # 29: Список моих объявлений
325
- async def my_ads(self, status: AdStatus = None) -> list[AdMakerBuy | AdMakerSale]:
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