xync-schema 0.6.27__tar.gz → 0.6.29__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.
@@ -1,19 +1,18 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: xync-schema
3
- Version: 0.6.27
3
+ Version: 0.6.29
4
4
  Summary: XyncNet project database model schema
5
5
  Author-email: Mike Artemiev <mixartemev@gmail.com>
6
6
  License: EULA
7
7
  Project-URL: Homepage, https://gitlab.com/xync/back/schema
8
8
  Project-URL: Repository, https://gitlab.com/xync/back/schema
9
- Requires-Python: >=3.11
9
+ Requires-Python: >=3.12
10
10
  Description-Content-Type: text/markdown
11
11
  Requires-Dist: xtg-auth
12
12
  Provides-Extra: dev
13
13
  Requires-Dist: pytest; extra == "dev"
14
14
  Requires-Dist: build; extra == "dev"
15
15
  Requires-Dist: twine; extra == "dev"
16
- Requires-Dist: setuptools_scm; extra == "dev"
17
16
 
18
17
  ## INSTALL
19
18
  ```bash
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "xync-schema"
3
- requires-python = ">=3.11"
3
+ requires-python = ">=3.12"
4
4
  authors = [
5
5
  {name = "Mike Artemiev", email = "mixartemev@gmail.com"},
6
6
  ]
@@ -28,7 +28,6 @@ dev = [
28
28
  "pytest",
29
29
  "build",
30
30
  "twine",
31
- "setuptools_scm",
32
31
  ]
33
32
 
34
33
  [tool.pytest.ini_options]
@@ -1,11 +1,12 @@
1
1
  from datetime import datetime
2
2
  from enum import IntEnum
3
3
  from tortoise import fields
4
- from x_model.model import Model, TsTrait, DatetimeSecField
4
+ from x_auth.models import Model
5
+ from x_model.models import TsTrait, DatetimeSecField
5
6
  from tg_auth.models import UserRefTrait, UserInfoTrait, User as BaseUser, UserStatus
6
7
 
7
8
 
8
- class AdvStatus(IntEnum):
9
+ class AdStatus(IntEnum):
9
10
  defActive = 0
10
11
  active = 1
11
12
  two = 2
@@ -16,7 +17,7 @@ class AdvStatus(IntEnum):
16
17
 
17
18
  class OrderStatus(IntEnum):
18
19
  zero = 0
19
- one = 1
20
+ active = 1
20
21
  two = 2
21
22
  three = 3
22
23
  done = 4
@@ -124,6 +125,7 @@ class Cur(Model):
124
125
  country: str | None = fields.CharField(63, null=True)
125
126
 
126
127
  pms: fields.ManyToManyRelation["Pm"] = fields.ManyToManyField("models.Pm", through="pmcur")
128
+ curexs: fields.ReverseRelation["Curex"]
127
129
  pmcurs: fields.ReverseRelation["Pmcur"] # no need. use pms
128
130
  pairs: fields.ReverseRelation["Pair"]
129
131
  countries: fields.ReverseRelation[Country]
@@ -136,7 +138,7 @@ class Cur(Model):
136
138
 
137
139
 
138
140
  class Coin(Model):
139
- id: int = fields.SmallIntField(True)
141
+ # id: int = fields.SmallIntField(True)
140
142
  ticker: str = fields.CharField(15, unique=True)
141
143
  rate: float | None = fields.FloatField(null=True)
142
144
  is_fiat: bool = fields.BooleanField(default=False)
@@ -151,7 +153,7 @@ class Coin(Model):
151
153
  _name = {"ticker"}
152
154
  _icon = "coin"
153
155
 
154
- def repr(self):
156
+ def repr(self, *args):
155
157
  return super().repr() + (self.is_fiat and " (fiat)" or "")
156
158
 
157
159
  class Meta:
@@ -161,8 +163,9 @@ class Coin(Model):
161
163
  class Ex(Model):
162
164
  id: int = fields.SmallIntField(True)
163
165
  name: str = fields.CharField(31)
164
- host: str | None = fields.CharField(31, null=True)
165
- url: str | None = fields.CharField(63, null=True)
166
+ host: str | None = fields.CharField(63, null=True, description="With no protocol 'https://'")
167
+ host_p2p: str | None = fields.CharField(63, null=True, description="With no protocol 'https://'")
168
+ url_login: str | None = fields.CharField(63, null=True, description="With no protocol 'https://'")
166
169
  type: ExType = fields.IntEnumField(ExType)
167
170
  logo: str = fields.CharField(511, default="")
168
171
 
@@ -194,6 +197,10 @@ class Curex(Model):
194
197
 
195
198
  _name = {"cur__ticker", "ex__name"}
196
199
 
200
+ class Meta:
201
+ table_description = "Currency in Exchange"
202
+ unique_together = (("cur_id", "ex_id"),)
203
+
197
204
 
198
205
  class Pair(Model, TsTrait):
199
206
  id = fields.SmallIntField(True)
@@ -210,7 +217,7 @@ class Pair(Model, TsTrait):
210
217
  table_description = "Coin/Currency pairs"
211
218
  unique_together = (("coin", "cur", "ex"),)
212
219
 
213
- def repr(self):
220
+ def repr(self, *args):
214
221
  return f"{self.coin.ticker}/{self.cur.ticker}"
215
222
 
216
223
 
@@ -228,7 +235,7 @@ class Direction(Model):
228
235
  table_description = "Trade directions"
229
236
  unique_together = (("pair", "sell"),)
230
237
 
231
- def repr(self):
238
+ def repr(self, *args):
232
239
  return f"{self.pair.coin.ticker}/{self.pair.cur.ticker} {'SELL' if self.sell else 'BUY'}"
233
240
 
234
241
 
@@ -250,8 +257,8 @@ class User(BaseUser, UserRefTrait, UserInfoTrait): # tg user
250
257
 
251
258
  class Agent(Model, TsTrait):
252
259
  id: int
260
+ exid: int = fields.IntField()
253
261
  ex: fields.ForeignKeyRelation[Ex] = fields.ForeignKeyField("models.Ex", related_name="agents")
254
- # ex_id: int
255
262
  auth: dict = fields.JSONField(null=True)
256
263
  user: fields.ForeignKeyRelation[User] = fields.ForeignKeyField("models.User", related_name="agents")
257
264
  user_id: int
@@ -262,11 +269,12 @@ class Agent(Model, TsTrait):
262
269
  _icon = "spy"
263
270
  _name = {"ex__name", "user__username"}
264
271
 
265
- def repr(self):
266
- return f"{self.ex.name}-{self.user.username}"
272
+ # def repr(self, *args):
273
+ # return f"{self.ex.name}-{self.user.username}"
267
274
 
268
- def balance(self) -> float:
269
- return sum(asset.free * (asset.coin.rate or 0) for asset in self.assets)
275
+ def balance(self) -> int:
276
+ return self.exid * 2
277
+ # return sum(asset.free * (asset.coin.rate or 0) for asset in self.assets)
270
278
 
271
279
  class Meta:
272
280
  table_description = "Agents"
@@ -275,11 +283,19 @@ class Agent(Model, TsTrait):
275
283
  class PydanticMeta:
276
284
  computed = ["balance"]
277
285
 
278
- class PydanticMetaListItem:
279
- max_recursion = 1
280
- backward_relations: bool = True
281
- exclude = ("user",)
282
- computed = ["balance"]
286
+ # class PydanticMetaListItem:
287
+ # max_recursion = 1
288
+ # backward_relations: bool = True
289
+ # exclude = ("user",)
290
+ # computed = ["balance"]
291
+
292
+ # async def client(self):
293
+ # import sys
294
+ # if isinstance(self.ex, QuerySet):
295
+ # # noinspection PyTypeChecker
296
+ # self.ex: Ex = await self.ex
297
+ # client = sys.modules[f'xync_client.{self.ex.name}.p2p'].AgentClient
298
+ # return client(self)
283
299
 
284
300
 
285
301
  class Adpm(Model):
@@ -303,14 +319,14 @@ class Ad(Model, TsTrait):
303
319
  detail: str = fields.CharField(4095, null=True)
304
320
  autoMsg: str = fields.CharField(255, null=True)
305
321
  agent: fields.ForeignKeyRelation[Agent] = fields.ForeignKeyField("models.Agent", "ads")
306
- status: AdvStatus = fields.IntEnumField(AdvStatus)
322
+ status: AdStatus = fields.IntEnumField(AdStatus)
307
323
 
308
324
  orders: fields.ReverseRelation["Order"]
309
325
 
310
326
  _icon = "ad"
311
327
  _name = {"direction__pair__coin__ticker", "direction__pair__cur__ticker", "direction__sell", "price"}
312
328
 
313
- def repr(self):
329
+ def repr(self, *args):
314
330
  return f"{TradeType(int(self.direction.sell.name)).name}: {self.price:.3g}"
315
331
 
316
332
  class Meta:
@@ -357,7 +373,7 @@ class Pmcur(Model): # for fiat with no exs tie
357
373
 
358
374
  # _sorts = ['-limits_count']
359
375
 
360
- def repr(self):
376
+ def repr(self, *args):
361
377
  return f"{self.pm.name}-{self.cur.ticker}"
362
378
 
363
379
  # @classmethod
@@ -391,17 +407,17 @@ class Pmex(Model): # existence pm in ex with no cur tie
391
407
  pm: fields.ForeignKeyRelation[Pm] = fields.ForeignKeyField("models.Pm", "pmexs")
392
408
  pm_id: int
393
409
  ex: fields.ForeignKeyRelation[Ex] = fields.ForeignKeyField("models.Ex", "pmexs")
394
- ex_id: int | None
395
- exid: int | None = fields.SmallIntField(null=True)
410
+ ex_id: int
411
+ exid: int = fields.SmallIntField()
396
412
 
397
413
  _name = {"pm__name", "ex__name"}
398
414
 
399
- def repr(self):
415
+ def repr(self, *args):
400
416
  return f"{self.pm.name}-{self.ex.name}"
401
417
 
402
418
  class Meta:
403
419
  table_description = "Payment methods - Currencies"
404
- unique_together = (("ex", "exid"),)
420
+ unique_together = (("pm_id", "ex_id"), ("ex_id", "exid"))
405
421
 
406
422
 
407
423
  class Pmcurex(Model): # existence pm in ex for exact cur, with "blocked" flag
@@ -432,12 +448,13 @@ class Fiat(Model):
432
448
  amount: float | None = fields.FloatField(default=0)
433
449
  target: float | None = fields.FloatField(default=None, null=True)
434
450
 
451
+ exs: fields.ManyToManyRelation[Ex] = fields.ManyToManyField("models.Ex", through="fiatex", related_name="fiats")
435
452
  orders: fields.ReverseRelation["Order"]
436
453
 
437
454
  _icon = "cash"
438
455
  _name = {"pmcur__pm__name", "pmcur__cur__ticker", "amount"}
439
456
 
440
- def repr(self):
457
+ def repr(self, *args):
441
458
  return f"{self.id}: {self.pmcur.repr()} ({self.user.username})"
442
459
 
443
460
  class Meta:
@@ -450,6 +467,23 @@ class Fiat(Model):
450
467
  # exclude_raw_fields = True
451
468
 
452
469
 
470
+ class Fiatex(Model): # existence pm in ex with no cur tie
471
+ fiat: fields.ForeignKeyRelation[Fiat] = fields.ForeignKeyField("models.Fiat", "fiatexs")
472
+ fiat_id: int
473
+ ex: fields.ForeignKeyRelation[Ex] = fields.ForeignKeyField("models.Ex", "fiatexs")
474
+ ex_id: int
475
+ exid: int = fields.SmallIntField()
476
+
477
+ _name = {"fiat__detail", "ex__name"}
478
+
479
+ def repr(self, *args):
480
+ return f"{self.fiat.detail}-{self.ex.name}"
481
+
482
+ class Meta:
483
+ table_description = "Fiat on Ex"
484
+ unique_together = (("fiat_id", "ex_id"), ("ex_id", "exid"))
485
+
486
+
453
487
  class Limit(Model):
454
488
  pmcur: fields.ForeignKeyRelation[Pmcur] = fields.ForeignKeyField("models.Pmcur")
455
489
  pmcur_id: int
@@ -465,7 +499,7 @@ class Limit(Model):
465
499
  _icon = "frame"
466
500
  _name = {"pmcur__pm__name", "pmcur__cur__ticker", "unit", "income", "amount"}
467
501
 
468
- def repr(self):
502
+ def repr(self, *args):
469
503
  return f"{self.pmcur.repr()}[{'<-' if self.income else '->'}]"
470
504
 
471
505
  class Meta:
@@ -486,7 +520,7 @@ class Asset(Model):
486
520
  _icon = "currency-bitcoin"
487
521
  _name = {"coin__ticker", "free"}
488
522
 
489
- def repr(self):
523
+ def repr(self, *args):
490
524
  return f"{self.coin.ticker} {self.free:.3g}/{self.freeze:.3g} user:{self.agent.repr()}"
491
525
 
492
526
  class Meta:
@@ -515,7 +549,7 @@ class Order(Model, TsTrait):
515
549
  _icon = "file-check"
516
550
  _name = {"fiat__pmcur__pm__name", "ad__direction__sell"}
517
551
 
518
- def repr(self):
552
+ def repr(self, *args):
519
553
  return f"{self.taker.repr()}: {self.amount:.3g} pm:{self.fiat.pmcur.pm.name}/{self.fiat_id} {self.status.name}"
520
554
 
521
555
  class Meta:
@@ -570,7 +604,7 @@ class Investment(Model, TsTrait):
570
604
  _icon = "trending-up"
571
605
  _name = {"dep__pid", "amount"}
572
606
 
573
- def repr(self):
607
+ def repr(self, *args):
574
608
  return f"{self.amount:.3g} {self.dep.repr()}"
575
609
 
576
610
  class Meta:
@@ -587,7 +621,7 @@ class TestEx(Model):
587
621
  _icon = "test-pipe"
588
622
  _name = {"ex__name", "action", "ok"}
589
623
 
590
- def repr(self):
624
+ def repr(self, *args):
591
625
  return f"{self.ex.name} {self.action.name} {self.ok}"
592
626
 
593
627
  class Meta:
@@ -605,7 +639,7 @@ class Vpn(Model):
605
639
  _icon = "vpn"
606
640
  _name = {"pub"}
607
641
 
608
- def repr(self):
642
+ def repr(self, *args):
609
643
  return self.user.username
610
644
 
611
645
  class Meta:
@@ -622,7 +656,7 @@ class Invite(Model, TsTrait):
622
656
  _icon = "invite"
623
657
  _name = {"ref__username", "protege__username", "approved"}
624
658
 
625
- def repr(self):
659
+ def repr(self, *args):
626
660
  return self.protege.name
627
661
 
628
662
  class Meta:
@@ -640,7 +674,7 @@ class Credit(Model, TsTrait):
640
674
  _icon = "credit"
641
675
  _name = {"lender__username", "borrower__username", "amount"}
642
676
 
643
- def repr(self):
677
+ def repr(self, *args):
644
678
  return self.borrower.name
645
679
 
646
680
  class Meta:
@@ -0,0 +1,11 @@
1
+ from pydantic import BaseModel
2
+
3
+
4
+ class FiatForm(BaseModel):
5
+ cur_id: int
6
+ pm_id: int
7
+ user_id: int
8
+ detail: str
9
+ name: str | None = None
10
+ amount: float
11
+ target: int | None = None
@@ -1,19 +1,18 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: xync-schema
3
- Version: 0.6.27
3
+ Version: 0.6.29
4
4
  Summary: XyncNet project database model schema
5
5
  Author-email: Mike Artemiev <mixartemev@gmail.com>
6
6
  License: EULA
7
7
  Project-URL: Homepage, https://gitlab.com/xync/back/schema
8
8
  Project-URL: Repository, https://gitlab.com/xync/back/schema
9
- Requires-Python: >=3.11
9
+ Requires-Python: >=3.12
10
10
  Description-Content-Type: text/markdown
11
11
  Requires-Dist: xtg-auth
12
12
  Provides-Extra: dev
13
13
  Requires-Dist: pytest; extra == "dev"
14
14
  Requires-Dist: build; extra == "dev"
15
15
  Requires-Dist: twine; extra == "dev"
16
- Requires-Dist: setuptools_scm; extra == "dev"
17
16
 
18
17
  ## INSTALL
19
18
  ```bash
@@ -8,6 +8,7 @@ tests/__init__.py
8
8
  tests/test_db.py
9
9
  xync_schema/__init__.py
10
10
  xync_schema/models.py
11
+ xync_schema/pydantic.py
11
12
  xync_schema.egg-info/PKG-INFO
12
13
  xync_schema.egg-info/SOURCES.txt
13
14
  xync_schema.egg-info/dependency_links.txt
@@ -4,4 +4,3 @@ xtg-auth
4
4
  pytest
5
5
  build
6
6
  twine
7
- setuptools_scm
File without changes
File without changes
File without changes
File without changes
File without changes