xync-schema 0.6.70__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 +87 -81
- xync_schema/pydantic.py +10 -2
- {xync_schema-0.6.70.dist-info → xync_schema-0.6.71.dist-info}/METADATA +1 -1
- xync_schema-0.6.71.dist-info/RECORD +8 -0
- xync_schema-0.6.70.dist-info/RECORD +0 -8
- {xync_schema-0.6.70.dist-info → xync_schema-0.6.71.dist-info}/WHEEL +0 -0
- {xync_schema-0.6.70.dist-info → xync_schema-0.6.71.dist-info}/top_level.txt +0 -0
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
|
|
@@ -190,36 +188,46 @@ class User(Model, TsTrait, UserInfoTrait):
|
|
|
190
188
|
# computed = ["balance"]
|
|
191
189
|
|
|
192
190
|
|
|
193
|
-
class
|
|
191
|
+
class Contragent(Model):
|
|
194
192
|
exid: int = fields.BigIntField()
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
"models.User", related_name="agents", null=True
|
|
199
|
-
)
|
|
200
|
-
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
|
|
201
196
|
updated_at: datetime | None = DatetimeSecField(auto_now=True)
|
|
202
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
|
|
203
213
|
assets: fields.ReverseRelation["Asset"]
|
|
204
|
-
orders: fields.ReverseRelation["Order"]
|
|
205
|
-
ads: fields.ReverseRelation["Ad"]
|
|
206
214
|
|
|
207
|
-
_name = {"
|
|
215
|
+
_name = {"contragent__name"}
|
|
208
216
|
|
|
209
217
|
def balance(self) -> int:
|
|
210
218
|
return sum(asset.free * (asset.coin.rate or 0) for asset in self.assets)
|
|
211
219
|
|
|
212
220
|
class Meta:
|
|
213
221
|
table_description = "Agents"
|
|
214
|
-
unique_together = (("
|
|
222
|
+
unique_together = (("contragent", "user"),)
|
|
215
223
|
|
|
216
224
|
class PydanticMeta(Model.PydanticMeta):
|
|
217
225
|
# max_recursion = 3
|
|
218
|
-
include = "id", "
|
|
226
|
+
include = "id", "contragent__ex", "assets", "auth", "updated_at"
|
|
219
227
|
computed = ["balance"]
|
|
220
228
|
|
|
221
229
|
def client(self):
|
|
222
|
-
module_name = f"xync_client.{self.ex.name}.agent"
|
|
230
|
+
module_name = f"xync_client.{self.contragent.ex.name}.agent"
|
|
223
231
|
__import__(module_name)
|
|
224
232
|
client = sys.modules[module_name].AgentClient
|
|
225
233
|
return client(self)
|
|
@@ -233,7 +241,7 @@ class Agent(Model):
|
|
|
233
241
|
# return client(self)
|
|
234
242
|
|
|
235
243
|
def asset_client(self):
|
|
236
|
-
module_name = f"xync_client.{self.ex.name}.asset"
|
|
244
|
+
module_name = f"xync_client.{self.contragent.ex.name}.asset"
|
|
237
245
|
__import__(module_name)
|
|
238
246
|
client = sys.modules[module_name].AssetClient
|
|
239
247
|
return client(self)
|
|
@@ -249,14 +257,14 @@ class Adpm(Model):
|
|
|
249
257
|
table_description = "P2P Advertisements - Payment methods"
|
|
250
258
|
|
|
251
259
|
|
|
252
|
-
class
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
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"
|
|
260
268
|
|
|
261
269
|
|
|
262
270
|
class Ad(Model, TsTrait):
|
|
@@ -269,10 +277,11 @@ class Ad(Model, TsTrait):
|
|
|
269
277
|
auto_msg: str | None = fields.CharField(255, null=True)
|
|
270
278
|
status: AdStatus = fields.IntEnumField(AdStatus, defaut=AdStatus.active)
|
|
271
279
|
|
|
272
|
-
|
|
273
|
-
|
|
280
|
+
maker: fields.ForeignKeyRelation[Contragent] = fields.ForeignKeyField("models.Contragent", "my_ads")
|
|
281
|
+
maker_id: int
|
|
274
282
|
|
|
275
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")
|
|
276
285
|
orders: fields.ReverseRelation["Order"]
|
|
277
286
|
|
|
278
287
|
_icon = "ad"
|
|
@@ -281,17 +290,17 @@ class Ad(Model, TsTrait):
|
|
|
281
290
|
class Meta:
|
|
282
291
|
table_description = "P2P Advertisements"
|
|
283
292
|
|
|
284
|
-
def epyds(self) -> tuple[PydModel, PydModel, PydModel, PydModel, PydModel, PydModel]:
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
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
|
+
# )
|
|
295
304
|
|
|
296
305
|
|
|
297
306
|
class Pm(Model):
|
|
@@ -328,7 +337,7 @@ class Pmcur(Model): # for fiat with no exs tie
|
|
|
328
337
|
cur: fields.ForeignKeyRelation[Cur] = fields.ForeignKeyField("models.Cur")
|
|
329
338
|
cur_id: int
|
|
330
339
|
|
|
331
|
-
|
|
340
|
+
creds: fields.BackwardFKRelation["Cred"]
|
|
332
341
|
exs: fields.ManyToManyRelation[Ex]
|
|
333
342
|
|
|
334
343
|
class Meta:
|
|
@@ -367,49 +376,61 @@ class PmexBank(BaseModel): # banks for SBP
|
|
|
367
376
|
class FiatBank(BaseModel): # banks for SBP
|
|
368
377
|
pmexbank: fields.ForeignKeyRelation[PmexBank] = fields.ForeignKeyField("models.PmexBank", "fiatbanks")
|
|
369
378
|
pmexbank_id: int
|
|
370
|
-
|
|
371
|
-
|
|
379
|
+
cred: fields.ForeignKeyRelation["Cred"] = fields.ForeignKeyField("models.Cred", "credbanks")
|
|
380
|
+
cred_id: int
|
|
372
381
|
|
|
373
382
|
class Meta:
|
|
374
|
-
unique_together = (("
|
|
383
|
+
unique_together = (("cred_id", "pmexbank_id"),)
|
|
375
384
|
|
|
376
385
|
|
|
377
|
-
class Pmcurex(BaseModel): # existence pm in ex for exact cur, with "blocked" flag
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
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"),)
|
|
386
395
|
|
|
387
396
|
|
|
388
|
-
class
|
|
389
|
-
|
|
397
|
+
class Cred(Model):
|
|
398
|
+
exid: int = fields.BigIntField()
|
|
390
399
|
pmcur: fields.ForeignKeyRelation[Pmcur] = fields.ForeignKeyField("models.Pmcur")
|
|
391
400
|
pmcur_id: int
|
|
392
401
|
# country: fields.ForeignKeyRelation[Country] = fields.ForeignKeyField("models.Country", related_name="fiats")
|
|
393
402
|
# country_id: int
|
|
394
403
|
detail: str = fields.CharField(127)
|
|
395
404
|
name: str | None = fields.CharField(127, null=True)
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
amount: float | None = fields.FloatField(default=0)
|
|
399
|
-
target: float | None = fields.FloatField(default=None, null=True)
|
|
405
|
+
contragent: fields.ForeignKeyRelation[Contragent] = fields.ForeignKeyField("models.Contragent", "creds")
|
|
406
|
+
contragent_id: int
|
|
400
407
|
|
|
401
|
-
|
|
402
|
-
|
|
408
|
+
fiat: fields.BackwardOneToOneRelation["Fiat"]
|
|
409
|
+
ads: fields.BackwardFKRelation[Ad]
|
|
410
|
+
orders: fields.BackwardFKRelation["Order"]
|
|
403
411
|
|
|
404
|
-
|
|
412
|
+
_name = {"exid"}
|
|
405
413
|
|
|
406
414
|
class Meta:
|
|
407
|
-
table_description = "Currency accounts
|
|
415
|
+
table_description = "Currency accounts"
|
|
416
|
+
unique_together = (("pmcur_id", "detail"), ("contragent", "exid"))
|
|
417
|
+
|
|
418
|
+
|
|
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)
|
|
426
|
+
|
|
427
|
+
class Meta:
|
|
428
|
+
table_description = "Currency balances"
|
|
408
429
|
|
|
409
430
|
class PydanticMeta(Model.PydanticMeta):
|
|
410
431
|
# max_recursion: int = 2
|
|
411
432
|
backward_relations = False
|
|
412
|
-
include = "id", "
|
|
433
|
+
include = "id", "cred__pmcur", "cred__detail", "cred__name", "amount"
|
|
413
434
|
|
|
414
435
|
@staticmethod
|
|
415
436
|
def epyd(ex: Ex):
|
|
@@ -418,18 +439,6 @@ class Fiat(Model):
|
|
|
418
439
|
return sys.modules[module_name].FiatEpyd
|
|
419
440
|
|
|
420
441
|
|
|
421
|
-
class Fiatex(BaseModel): # existence pm in ex with no cur tie
|
|
422
|
-
fiat: fields.ForeignKeyRelation[Fiat] = fields.ForeignKeyField("models.Fiat", "fiatexs")
|
|
423
|
-
fiat_id: int
|
|
424
|
-
ex: fields.ForeignKeyRelation[Ex] = fields.ForeignKeyField("models.Ex", "fiatexs")
|
|
425
|
-
ex_id: int
|
|
426
|
-
exid: int = fields.BigIntField()
|
|
427
|
-
|
|
428
|
-
class Meta:
|
|
429
|
-
table_description = "Fiat on Ex"
|
|
430
|
-
unique_together = (("fiat_id", "ex_id"), ("ex_id", "exid"))
|
|
431
|
-
|
|
432
|
-
|
|
433
442
|
class Limit(Model):
|
|
434
443
|
pmcur: fields.ForeignKeyRelation[Pmcur] = fields.ForeignKeyField("models.Pmcur")
|
|
435
444
|
pmcur_id: int
|
|
@@ -479,9 +488,9 @@ class Order(Model):
|
|
|
479
488
|
ad: fields.ForeignKeyRelation[Ad] = fields.ForeignKeyField("models.Ad", related_name="ads")
|
|
480
489
|
ad_id: int
|
|
481
490
|
amount: float = fields.FloatField()
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
taker: fields.ForeignKeyRelation[
|
|
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")
|
|
485
494
|
taker_id: int
|
|
486
495
|
maker_topic: int = fields.IntField()
|
|
487
496
|
taker_topic: int = fields.IntField()
|
|
@@ -493,10 +502,7 @@ class Order(Model):
|
|
|
493
502
|
|
|
494
503
|
msgs: fields.BackwardFKRelation["Msg"]
|
|
495
504
|
|
|
496
|
-
_name = {"
|
|
497
|
-
|
|
498
|
-
def repr(self):
|
|
499
|
-
return f"{self.fiat.pmcur.pm.name}/{self.fiat_id}:{self.amount:.3g} {self.status.name}"
|
|
505
|
+
_name = {"cred__pmcur__pm__name"}
|
|
500
506
|
|
|
501
507
|
async def client(self):
|
|
502
508
|
if isinstance(self.ad, QuerySet):
|
|
@@ -508,7 +514,7 @@ class Order(Model):
|
|
|
508
514
|
elif isinstance(self.ad.agent, Agent) and isinstance(self.ad.agent.ex, QuerySet):
|
|
509
515
|
# noinspection PyTypeChecker
|
|
510
516
|
self.ad.agent.ex = await self.ad.agent.ex
|
|
511
|
-
client = sys.modules[f"xync_client.{self.ad.
|
|
517
|
+
client = sys.modules[f"xync_client.{self.ad.maker.ex.name}.order"].Client
|
|
512
518
|
return client(self)
|
|
513
519
|
|
|
514
520
|
# def epyd(self): # todo: for who?
|
xync_schema/pydantic.py
CHANGED
|
@@ -6,12 +6,20 @@ from xync_schema.enums import AdStatus, PmType
|
|
|
6
6
|
from xync_schema.models import Fiat, Agent, Direction, Pmcur, User, Ex
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
class
|
|
9
|
+
class _CurCoin(BaseModel):
|
|
10
10
|
exid: int | str
|
|
11
11
|
ticker: str
|
|
12
12
|
rate: float | None = None
|
|
13
|
-
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class CoinEpyd(_CurCoin):
|
|
16
|
+
p2p: bool = True
|
|
17
|
+
minimum: float | None = None
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class CurEpyd(_CurCoin):
|
|
14
21
|
rounding_scale: int | None = None
|
|
22
|
+
minimum: int | None = None
|
|
15
23
|
|
|
16
24
|
|
|
17
25
|
class PmexBankPyd(BaseModel):
|
|
@@ -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=9nyibPT9ZPMWaiXHO3gBGipvN-P-h4sJjehOgH6ccUg,25126
|
|
4
|
-
xync_schema/pydantic.py,sha256=Xw7ARA2yV4QDako2Uw9rLw-pMjcpVTW-Sade3ARXZFQ,3936
|
|
5
|
-
xync_schema-0.6.70.dist-info/METADATA,sha256=nmh9EGERPywOssPlHY1ww6BJPHOl5pnmWtMmAVha8Dc,3985
|
|
6
|
-
xync_schema-0.6.70.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
|
7
|
-
xync_schema-0.6.70.dist-info/top_level.txt,sha256=jN8IBDfVY8b85Byyk8v0Gyj_0yLB8FO56WV4EvcXWY4,12
|
|
8
|
-
xync_schema-0.6.70.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|