xync-schema 0.6.69__py3-none-any.whl → 0.6.71__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_schema/models.py CHANGED
@@ -1,7 +1,5 @@
1
1
  import sys
2
2
  from datetime import datetime
3
-
4
- from pydantic import BaseModel as PydModel
5
3
  from tortoise import fields
6
4
  from tortoise.queryset import QuerySet
7
5
  from tortoise import Model as BaseModel
@@ -26,7 +24,7 @@ from xync_schema.enums import ExType, AdStatus, AssetType, OrderStatus, ExAction
26
24
  class Cur(Model):
27
25
  id = fields.SmallIntField(True)
28
26
  ticker: str = fields.CharField(3, unique=True)
29
- rate: float | None = fields.FloatField(default=0)
27
+ rate: float | None = fields.FloatField(default=0, null=True)
30
28
  # country: str | None = fields.CharField(63, null=True)
31
29
 
32
30
  pms: fields.ManyToManyRelation["Pm"] = fields.ManyToManyField("models.Pm", through="pmcur")
@@ -84,11 +82,11 @@ class Ex(Model):
84
82
  class PydanticMeta(Model.PydanticMeta):
85
83
  include = "name", "logo"
86
84
 
87
- def client(self):
85
+ def client(self, agent: "Agent" = None):
88
86
  module_name = f"xync_client.{self.name}.ex"
89
87
  __import__(module_name)
90
88
  client = sys.modules[module_name].ExClient
91
- return client(self)
89
+ return client(self, agent)
92
90
 
93
91
 
94
92
  class Curex(BaseModel):
@@ -96,6 +94,7 @@ class Curex(BaseModel):
96
94
  ex: fields.ForeignKeyRelation[Ex] = fields.ForeignKeyField("models.Ex")
97
95
  exid: str = fields.CharField(31)
98
96
  minimum: float = fields.FloatField(null=True)
97
+ rounding_scale: int = fields.SmallIntField(null=True)
99
98
  # countries: fields.ManyToManyRelation[Country] = fields.ManyToManyField(
100
99
  # "models.Country", through="curexcountry", backward_key="curexs"
101
100
  # )
@@ -189,36 +188,46 @@ class User(Model, TsTrait, UserInfoTrait):
189
188
  # computed = ["balance"]
190
189
 
191
190
 
192
- class Agent(Model):
191
+ class Contragent(Model):
193
192
  exid: int = fields.BigIntField()
194
- ex: fields.ForeignKeyRelation[Ex] = fields.ForeignKeyField("models.Ex", related_name="agents")
195
- auth: dict[str, str] = fields.JSONField(null=True)
196
- user: fields.ForeignKeyNullableRelation[User] = fields.ForeignKeyField(
197
- "models.User", related_name="agents", null=True
198
- )
199
- user_id: int
193
+ name: int = fields.CharField(63)
194
+ ex: fields.ForeignKeyRelation[Ex] = fields.ForeignKeyField("models.Ex", related_name="contragents")
195
+ ex_id: int
200
196
  updated_at: datetime | None = DatetimeSecField(auto_now=True)
201
197
 
198
+ agent: fields.BackwardOneToOneRelation["Agent"]
199
+ taken_orders: fields.BackwardFKRelation["Order"]
200
+ my_ads: fields.BackwardFKRelation["Ad"]
201
+
202
+ class Meta:
203
+ table_description = "Agents"
204
+ unique_together = (("ex", "exid"),)
205
+
206
+
207
+ class Agent(Model):
208
+ auth: dict[str, str] = fields.JSONField(null=True)
209
+ contragent: fields.OneToOneRelation[Contragent] = fields.OneToOneField("models.Contragent", "agent")
210
+ contragent_id: int
211
+ user: fields.ForeignKeyRelation[User] = fields.ForeignKeyField("models.User", related_name="agents")
212
+ user_id: int
202
213
  assets: fields.ReverseRelation["Asset"]
203
- orders: fields.ReverseRelation["Order"]
204
- ads: fields.ReverseRelation["Ad"]
205
214
 
206
- _name = {"exid"}
215
+ _name = {"contragent__name"}
207
216
 
208
217
  def balance(self) -> int:
209
218
  return sum(asset.free * (asset.coin.rate or 0) for asset in self.assets)
210
219
 
211
220
  class Meta:
212
221
  table_description = "Agents"
213
- unique_together = (("ex", "user"),)
222
+ unique_together = (("contragent", "user"),)
214
223
 
215
224
  class PydanticMeta(Model.PydanticMeta):
216
225
  # max_recursion = 3
217
- include = "id", "ex", "assets", "auth", "updated_at"
226
+ include = "id", "contragent__ex", "assets", "auth", "updated_at"
218
227
  computed = ["balance"]
219
228
 
220
229
  def client(self):
221
- module_name = f"xync_client.{self.ex.name}.agent"
230
+ module_name = f"xync_client.{self.contragent.ex.name}.agent"
222
231
  __import__(module_name)
223
232
  client = sys.modules[module_name].AgentClient
224
233
  return client(self)
@@ -232,7 +241,7 @@ class Agent(Model):
232
241
  # return client(self)
233
242
 
234
243
  def asset_client(self):
235
- module_name = f"xync_client.{self.ex.name}.asset"
244
+ module_name = f"xync_client.{self.contragent.ex.name}.asset"
236
245
  __import__(module_name)
237
246
  client = sys.modules[module_name].AssetClient
238
247
  return client(self)
@@ -248,6 +257,16 @@ class Adpm(Model):
248
257
  table_description = "P2P Advertisements - Payment methods"
249
258
 
250
259
 
260
+ # class AdCred(Model):
261
+ # ad: fields.ForeignKeyRelation["Ad"] = fields.ForeignKeyField("models.Ad")
262
+ # cred: fields.ForeignKeyRelation["Cred"] = fields.ForeignKeyField("models.Cred")
263
+ #
264
+ # _name = {"ad__id", "cred__id"}
265
+ #
266
+ # class Meta:
267
+ # table_description = "P2P Advertisements - Payment details"
268
+
269
+
251
270
  class Ad(Model, TsTrait):
252
271
  id: int = fields.BigIntField(True)
253
272
  direction: fields.ForeignKeyRelation[Direction] = fields.ForeignKeyField("models.Direction", related_name="ads")
@@ -258,10 +277,11 @@ class Ad(Model, TsTrait):
258
277
  auto_msg: str | None = fields.CharField(255, null=True)
259
278
  status: AdStatus = fields.IntEnumField(AdStatus, defaut=AdStatus.active)
260
279
 
261
- agent: fields.ForeignKeyRelation[Agent] = fields.ForeignKeyField("models.Agent", "ads")
262
- agent_id: int
280
+ maker: fields.ForeignKeyRelation[Contragent] = fields.ForeignKeyField("models.Contragent", "my_ads")
281
+ maker_id: int
263
282
 
264
283
  pms: fields.ManyToManyRelation["Pm"] = fields.ManyToManyField("models.Pm", through="adpm") # only root pms
284
+ creds: fields.ManyToManyRelation["Cred"] = fields.ManyToManyField("models.Cred", through="adcred")
265
285
  orders: fields.ReverseRelation["Order"]
266
286
 
267
287
  _icon = "ad"
@@ -270,17 +290,17 @@ class Ad(Model, TsTrait):
270
290
  class Meta:
271
291
  table_description = "P2P Advertisements"
272
292
 
273
- def epyds(self) -> tuple[PydModel, PydModel, PydModel, PydModel, PydModel, PydModel]:
274
- module_name = f"xync_client.{self.agent.ex.name}.pyd"
275
- __import__(module_name)
276
- return (
277
- sys.modules[module_name].AdEpyd,
278
- sys.modules[module_name].AdFullEpyd,
279
- sys.modules[module_name].MyAdEpydPurchase,
280
- sys.modules[module_name].MyAdInEpydPurchase,
281
- sys.modules[module_name].MyAdEpydSale,
282
- sys.modules[module_name].MyAdInEpydSale,
283
- )
293
+ # def epyds(self) -> tuple[PydModel, PydModel, PydModel, PydModel, PydModel, PydModel]:
294
+ # module_name = f"xync_client.{self.maker.ex.name}.pyd"
295
+ # __import__(module_name)
296
+ # return (
297
+ # sys.modules[module_name].AdEpyd,
298
+ # sys.modules[module_name].AdFullEpyd,
299
+ # sys.modules[module_name].MyAdEpydPurchase,
300
+ # sys.modules[module_name].MyAdInEpydPurchase,
301
+ # sys.modules[module_name].MyAdEpydSale,
302
+ # sys.modules[module_name].MyAdInEpydSale,
303
+ # )
284
304
 
285
305
 
286
306
  class Pm(Model):
@@ -317,7 +337,7 @@ class Pmcur(Model): # for fiat with no exs tie
317
337
  cur: fields.ForeignKeyRelation[Cur] = fields.ForeignKeyField("models.Cur")
318
338
  cur_id: int
319
339
 
320
- fiats: fields.BackwardFKRelation["Fiat"]
340
+ creds: fields.BackwardFKRelation["Cred"]
321
341
  exs: fields.ManyToManyRelation[Ex]
322
342
 
323
343
  class Meta:
@@ -356,49 +376,61 @@ class PmexBank(BaseModel): # banks for SBP
356
376
  class FiatBank(BaseModel): # banks for SBP
357
377
  pmexbank: fields.ForeignKeyRelation[PmexBank] = fields.ForeignKeyField("models.PmexBank", "fiatbanks")
358
378
  pmexbank_id: int
359
- fiat: fields.ForeignKeyRelation["Fiat"] = fields.ForeignKeyField("models.Fiat", "fiatbanks")
360
- fiat_id: int
379
+ cred: fields.ForeignKeyRelation["Cred"] = fields.ForeignKeyField("models.Cred", "credbanks")
380
+ cred_id: int
361
381
 
362
382
  class Meta:
363
- unique_together = (("fiat_id", "pmexbank_id"),)
383
+ unique_together = (("cred_id", "pmexbank_id"),)
364
384
 
365
385
 
366
- class Pmcurex(BaseModel): # existence pm in ex for exact cur, with "blocked" flag
367
- pmcur: fields.ForeignKeyRelation[Pmcur] = fields.ForeignKeyField("models.Pmcur")
368
- pmcur_id: int
369
- ex: fields.ForeignKeyRelation[Ex] = fields.ForeignKeyField("models.Ex")
370
- ex_id: int
371
- blocked: bool = fields.BooleanField(default=False)
372
-
373
- # class Meta:
374
- # unique_together = (("ex_id", "pmcur_id"),)
386
+ # class Pmcurex(BaseModel): # existence pm in ex for exact cur, with "blocked" flag
387
+ # pmcur: fields.ForeignKeyRelation[Pmcur] = fields.ForeignKeyField("models.Pmcur")
388
+ # pmcur_id: int
389
+ # ex: fields.ForeignKeyRelation[Ex] = fields.ForeignKeyField("models.Ex")
390
+ # ex_id: int
391
+ # blocked: bool = fields.BooleanField(default=False) # todo: move to cureex or pmex?
392
+ #
393
+ # # class Meta:
394
+ # # unique_together = (("ex_id", "pmcur_id"),)
375
395
 
376
396
 
377
- class Fiat(Model):
378
- id: int = fields.BigIntField(True)
397
+ class Cred(Model):
398
+ exid: int = fields.BigIntField()
379
399
  pmcur: fields.ForeignKeyRelation[Pmcur] = fields.ForeignKeyField("models.Pmcur")
380
400
  pmcur_id: int
381
401
  # country: fields.ForeignKeyRelation[Country] = fields.ForeignKeyField("models.Country", related_name="fiats")
382
402
  # country_id: int
383
403
  detail: str = fields.CharField(127)
384
404
  name: str | None = fields.CharField(127, null=True)
385
- user: fields.ForeignKeyRelation[User] = fields.ForeignKeyField("models.User", "fiats")
386
- user_id: int
387
- amount: float | None = fields.FloatField(default=0)
388
- target: float | None = fields.FloatField(default=None, null=True)
405
+ contragent: fields.ForeignKeyRelation[Contragent] = fields.ForeignKeyField("models.Contragent", "creds")
406
+ contragent_id: int
407
+
408
+ fiat: fields.BackwardOneToOneRelation["Fiat"]
409
+ ads: fields.BackwardFKRelation[Ad]
410
+ orders: fields.BackwardFKRelation["Order"]
411
+
412
+ _name = {"exid"}
413
+
414
+ class Meta:
415
+ table_description = "Currency accounts"
416
+ unique_together = (("pmcur_id", "detail"), ("contragent", "exid"))
389
417
 
390
- exs: fields.ManyToManyRelation[Ex] = fields.ManyToManyField("models.Ex", through="fiatex", related_name="fiats")
391
- orders: fields.ReverseRelation["Order"]
392
418
 
393
- # _name = {"pmcur__pm__name", "pmcur__cur__ticker", "amount"}
419
+ class Fiat(Model):
420
+ cred: fields.OneToOneRelation[Cred] = fields.OneToOneField("models.Cred", "fiat")
421
+ cred_id: int
422
+ # user: fields.ForeignKeyRelation[User] = fields.ForeignKeyField("models.User", "fiats")
423
+ # user_id: int # cred.contragent.agent.user_id
424
+ amount: float | None = fields.FloatField(default=0)
425
+ target: float | None = fields.FloatField(default=None, null=True)
394
426
 
395
427
  class Meta:
396
- table_description = "Currency accounts balance"
428
+ table_description = "Currency balances"
397
429
 
398
430
  class PydanticMeta(Model.PydanticMeta):
399
431
  # max_recursion: int = 2
400
432
  backward_relations = False
401
- include = "id", "pmcur", "detail", "name", "amount"
433
+ include = "id", "cred__pmcur", "cred__detail", "cred__name", "amount"
402
434
 
403
435
  @staticmethod
404
436
  def epyd(ex: Ex):
@@ -407,18 +439,6 @@ class Fiat(Model):
407
439
  return sys.modules[module_name].FiatEpyd
408
440
 
409
441
 
410
- class Fiatex(BaseModel): # existence pm in ex with no cur tie
411
- fiat: fields.ForeignKeyRelation[Fiat] = fields.ForeignKeyField("models.Fiat", "fiatexs")
412
- fiat_id: int
413
- ex: fields.ForeignKeyRelation[Ex] = fields.ForeignKeyField("models.Ex", "fiatexs")
414
- ex_id: int
415
- exid: int = fields.BigIntField()
416
-
417
- class Meta:
418
- table_description = "Fiat on Ex"
419
- unique_together = (("fiat_id", "ex_id"), ("ex_id", "exid"))
420
-
421
-
422
442
  class Limit(Model):
423
443
  pmcur: fields.ForeignKeyRelation[Pmcur] = fields.ForeignKeyField("models.Pmcur")
424
444
  pmcur_id: int
@@ -468,9 +488,9 @@ class Order(Model):
468
488
  ad: fields.ForeignKeyRelation[Ad] = fields.ForeignKeyField("models.Ad", related_name="ads")
469
489
  ad_id: int
470
490
  amount: float = fields.FloatField()
471
- fiat: fields.ForeignKeyRelation[Fiat] = fields.ForeignKeyField("models.Fiat", related_name="orders", null=True)
472
- fiat_id: int | None
473
- taker: fields.ForeignKeyRelation[Agent] = fields.ForeignKeyField("models.Agent", "orders")
491
+ cred: fields.ForeignKeyRelation[Cred] = fields.ForeignKeyField("models.Cred", related_name="orders", null=True)
492
+ cred_id: int | None
493
+ taker: fields.ForeignKeyRelation[Contragent] = fields.ForeignKeyField("models.Contragent", "taken_orders")
474
494
  taker_id: int
475
495
  maker_topic: int = fields.IntField()
476
496
  taker_topic: int = fields.IntField()
@@ -482,10 +502,7 @@ class Order(Model):
482
502
 
483
503
  msgs: fields.BackwardFKRelation["Msg"]
484
504
 
485
- _name = {"fiat__pmcur__pm__name"}
486
-
487
- def repr(self):
488
- return f"{self.fiat.pmcur.pm.name}/{self.fiat_id}:{self.amount:.3g} {self.status.name}"
505
+ _name = {"cred__pmcur__pm__name"}
489
506
 
490
507
  async def client(self):
491
508
  if isinstance(self.ad, QuerySet):
@@ -497,7 +514,7 @@ class Order(Model):
497
514
  elif isinstance(self.ad.agent, Agent) and isinstance(self.ad.agent.ex, QuerySet):
498
515
  # noinspection PyTypeChecker
499
516
  self.ad.agent.ex = await self.ad.agent.ex
500
- client = sys.modules[f"xync_client.{self.ad.agent.ex.name}.order"].Client
517
+ client = sys.modules[f"xync_client.{self.ad.maker.ex.name}.order"].Client
501
518
  return client(self)
502
519
 
503
520
  # def epyd(self): # todo: for who?
xync_schema/pydantic.py CHANGED
@@ -3,7 +3,23 @@ from datetime import datetime
3
3
  from pydantic import BaseModel, model_validator
4
4
 
5
5
  from xync_schema.enums import AdStatus, PmType
6
- from xync_schema.models import Fiat, Agent, Direction, Pm, Pmcur, User
6
+ from xync_schema.models import Fiat, Agent, Direction, Pmcur, User, Ex
7
+
8
+
9
+ class _CurCoin(BaseModel):
10
+ exid: int | str
11
+ ticker: str
12
+ rate: float | None = None
13
+
14
+
15
+ class CoinEpyd(_CurCoin):
16
+ p2p: bool = True
17
+ minimum: float | None = None
18
+
19
+
20
+ class CurEpyd(_CurCoin):
21
+ rounding_scale: int | None = None
22
+ minimum: int | None = None
7
23
 
8
24
 
9
25
  class PmexBankPyd(BaseModel):
@@ -65,7 +81,7 @@ class FiatPydIn(BaseModel):
65
81
  def check_at_least_one_field(cls, values):
66
82
  if (values.get("pmcur") or values.get("pmcur_id")) and (values.get("user") or values.get("user_id")):
67
83
  return values
68
- raise ValueError("pmcur_id or pmcur is required")
84
+ raise ValueError("pmcur(_id) and user(_id) is required")
69
85
 
70
86
  def args(self) -> tuple[dict, dict]:
71
87
  unq: tuple[str, ...] = "id", "user_id", "user", "pmcur_id", "pmcur"
@@ -74,11 +90,23 @@ class FiatPydIn(BaseModel):
74
90
  return {k: getattr(self, k) for k in df if d.get(k)}, {k: getattr(self, k) for k in unq if d.get(k)}
75
91
 
76
92
 
77
- # class FiatexPyd(BaseModel):
78
- # id: int | None = None
79
- # exid: str
80
- # ex_id: int
81
- # fiat_id: int
93
+ class FiatexPydIn(BaseModel):
94
+ id: int | None = None
95
+ exid: str
96
+ ex: Ex | None = None
97
+ ex_id: int | None = None
98
+ fiat: Fiat | None = None
99
+ fiat_id: int | None = None
100
+
101
+ class Config:
102
+ arbitrary_types_allowed = True
103
+
104
+ @classmethod
105
+ @model_validator(mode="before")
106
+ def check_at_least_one_field(cls, values):
107
+ if (values.get("ex") or values.get("ex_id")) and (values.get("fiat") or values.get("fiat_id")):
108
+ return values
109
+ raise ValueError("ex(_id) and fiat(_id) is required")
82
110
 
83
111
 
84
112
  class BaseAd(BaseModel):
@@ -96,7 +124,8 @@ class AdPydIn(BaseAd):
96
124
  direction_id: int | None = None
97
125
  agent: Agent | None = None
98
126
  direction: Direction | None = None
99
- payMeths: list[Pm]
127
+ pms_: list | None = None
128
+ fiats_: list | None = None
100
129
 
101
130
  class Config:
102
131
  arbitrary_types_allowed = True
@@ -104,9 +133,12 @@ class AdPydIn(BaseAd):
104
133
  @classmethod
105
134
  @model_validator(mode="before")
106
135
  def check_at_least_one_field(cls, values):
107
- if (values.get("agent") or values.get("agent_id")) and (values.get("direction") or values.get("direction_id")):
136
+ agent = values.get("agent") or values.get("agent_id")
137
+ direction = values.get("direction") or values.get("direction_id")
138
+ pms_or_fiats = values.get("pms_") or values.get("fiats_")
139
+ if agent and direction and pms_or_fiats:
108
140
  return values
109
- raise ValueError("pmcur_id or pmcur is required")
141
+ raise ValueError("(pms or fiats) and agent(_id) and direction(_id) is required")
110
142
 
111
143
 
112
144
  class OrderPyd(BaseModel):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: xync-schema
3
- Version: 0.6.69
3
+ Version: 0.6.71
4
4
  Summary: XyncNet project database model schema
5
5
  Author-email: Mike Artemiev <mixartemev@gmail.com>
6
6
  License: EULA
@@ -0,0 +1,8 @@
1
+ xync_schema/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ xync_schema/enums.py,sha256=zPdnf6J--qaBoyin_qXO3z_UnfpiHGXVHKs9v3ug1Qk,12428
3
+ xync_schema/models.py,sha256=w3TOlAK9ESN0tOMb7Zbb6XK1PpsxT2j5Ck0qAY-ig3s,25512
4
+ xync_schema/pydantic.py,sha256=2Gupluj7SfQs276mWH1SDzkxyOcst3naxlB4sULeU7U,4046
5
+ xync_schema-0.6.71.dist-info/METADATA,sha256=xM-nC9Wbz15BWmejIJqIDrSQFLVNYwzNjAQlXBAiXhQ,3985
6
+ xync_schema-0.6.71.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
7
+ xync_schema-0.6.71.dist-info/top_level.txt,sha256=jN8IBDfVY8b85Byyk8v0Gyj_0yLB8FO56WV4EvcXWY4,12
8
+ xync_schema-0.6.71.dist-info/RECORD,,
@@ -1,8 +0,0 @@
1
- xync_schema/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- xync_schema/enums.py,sha256=zPdnf6J--qaBoyin_qXO3z_UnfpiHGXVHKs9v3ug1Qk,12428
3
- xync_schema/models.py,sha256=_IzK9e4H6lXl8VMjyl0m-Ir7RfrCHAc2JM0RZiWJxBA,24722
4
- xync_schema/pydantic.py,sha256=B2neARFVzQUkrzbkWKoNLvyUScq2TLaMAZTUgawh8ew,3142
5
- xync_schema-0.6.69.dist-info/METADATA,sha256=-3CtP6GunNW70ZewZmcc5YOKDBXAI9D7NWhxtpGI8PE,3985
6
- xync_schema-0.6.69.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
7
- xync_schema-0.6.69.dist-info/top_level.txt,sha256=jN8IBDfVY8b85Byyk8v0Gyj_0yLB8FO56WV4EvcXWY4,12
8
- xync_schema-0.6.69.dist-info/RECORD,,