xync-schema 0.6.28__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.
- {xync_schema-0.6.28/xync_schema.egg-info → xync_schema-0.6.29}/PKG-INFO +1 -1
- {xync_schema-0.6.28 → xync_schema-0.6.29}/tests/test_db.py +3 -3
- xync_schema-0.6.28/xync_schema/model.py → xync_schema-0.6.29/xync_schema/models.py +69 -36
- xync_schema-0.6.29/xync_schema/pydantic.py +11 -0
- {xync_schema-0.6.28 → xync_schema-0.6.29/xync_schema.egg-info}/PKG-INFO +1 -1
- {xync_schema-0.6.28 → xync_schema-0.6.29}/xync_schema.egg-info/SOURCES.txt +2 -1
- {xync_schema-0.6.28 → xync_schema-0.6.29}/.env.sample +0 -0
- {xync_schema-0.6.28 → xync_schema-0.6.29}/.gitignore +0 -0
- {xync_schema-0.6.28 → xync_schema-0.6.29}/.pre-commit-config.yaml +0 -0
- {xync_schema-0.6.28 → xync_schema-0.6.29}/README.md +0 -0
- {xync_schema-0.6.28 → xync_schema-0.6.29}/makefile +0 -0
- {xync_schema-0.6.28 → xync_schema-0.6.29}/pyproject.toml +0 -0
- {xync_schema-0.6.28 → xync_schema-0.6.29}/setup.cfg +0 -0
- {xync_schema-0.6.28 → xync_schema-0.6.29}/tests/__init__.py +0 -0
- {xync_schema-0.6.28 → xync_schema-0.6.29}/xync_schema/__init__.py +0 -0
- {xync_schema-0.6.28 → xync_schema-0.6.29}/xync_schema.egg-info/dependency_links.txt +0 -0
- {xync_schema-0.6.28 → xync_schema-0.6.29}/xync_schema.egg-info/requires.txt +0 -0
- {xync_schema-0.6.28 → xync_schema-0.6.29}/xync_schema.egg-info/top_level.txt +0 -0
|
@@ -6,15 +6,15 @@ from tortoise import connections
|
|
|
6
6
|
from tortoise.backends.asyncpg import AsyncpgDBClient
|
|
7
7
|
from x_model import init_db
|
|
8
8
|
|
|
9
|
-
from xync_schema import
|
|
10
|
-
from xync_schema.
|
|
9
|
+
from xync_schema import models
|
|
10
|
+
from xync_schema.models import Cur
|
|
11
11
|
|
|
12
12
|
load_dotenv()
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
@pytest.fixture
|
|
16
16
|
async def dbc() -> AsyncpgDBClient:
|
|
17
|
-
await init_db(env("DB_URL"),
|
|
17
|
+
await init_db(env("DB_URL"), models, True)
|
|
18
18
|
cn: AsyncpgDBClient = connections.get("default")
|
|
19
19
|
yield cn
|
|
20
20
|
await cn.close()
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
from datetime import datetime
|
|
2
2
|
from enum import IntEnum
|
|
3
3
|
from tortoise import fields
|
|
4
|
-
from x_auth.
|
|
5
|
-
from x_model.
|
|
4
|
+
from x_auth.models import Model
|
|
5
|
+
from x_model.models import TsTrait, DatetimeSecField
|
|
6
6
|
from tg_auth.models import UserRefTrait, UserInfoTrait, User as BaseUser, UserStatus
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
class
|
|
9
|
+
class AdStatus(IntEnum):
|
|
10
10
|
defActive = 0
|
|
11
11
|
active = 1
|
|
12
12
|
two = 2
|
|
@@ -17,7 +17,7 @@ class AdvStatus(IntEnum):
|
|
|
17
17
|
|
|
18
18
|
class OrderStatus(IntEnum):
|
|
19
19
|
zero = 0
|
|
20
|
-
|
|
20
|
+
active = 1
|
|
21
21
|
two = 2
|
|
22
22
|
three = 3
|
|
23
23
|
done = 4
|
|
@@ -125,6 +125,7 @@ class Cur(Model):
|
|
|
125
125
|
country: str | None = fields.CharField(63, null=True)
|
|
126
126
|
|
|
127
127
|
pms: fields.ManyToManyRelation["Pm"] = fields.ManyToManyField("models.Pm", through="pmcur")
|
|
128
|
+
curexs: fields.ReverseRelation["Curex"]
|
|
128
129
|
pmcurs: fields.ReverseRelation["Pmcur"] # no need. use pms
|
|
129
130
|
pairs: fields.ReverseRelation["Pair"]
|
|
130
131
|
countries: fields.ReverseRelation[Country]
|
|
@@ -137,7 +138,7 @@ class Cur(Model):
|
|
|
137
138
|
|
|
138
139
|
|
|
139
140
|
class Coin(Model):
|
|
140
|
-
id: int = fields.SmallIntField(True)
|
|
141
|
+
# id: int = fields.SmallIntField(True)
|
|
141
142
|
ticker: str = fields.CharField(15, unique=True)
|
|
142
143
|
rate: float | None = fields.FloatField(null=True)
|
|
143
144
|
is_fiat: bool = fields.BooleanField(default=False)
|
|
@@ -152,7 +153,7 @@ class Coin(Model):
|
|
|
152
153
|
_name = {"ticker"}
|
|
153
154
|
_icon = "coin"
|
|
154
155
|
|
|
155
|
-
def repr(self):
|
|
156
|
+
def repr(self, *args):
|
|
156
157
|
return super().repr() + (self.is_fiat and " (fiat)" or "")
|
|
157
158
|
|
|
158
159
|
class Meta:
|
|
@@ -162,8 +163,9 @@ class Coin(Model):
|
|
|
162
163
|
class Ex(Model):
|
|
163
164
|
id: int = fields.SmallIntField(True)
|
|
164
165
|
name: str = fields.CharField(31)
|
|
165
|
-
host: str | None = fields.CharField(
|
|
166
|
-
|
|
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://'")
|
|
167
169
|
type: ExType = fields.IntEnumField(ExType)
|
|
168
170
|
logo: str = fields.CharField(511, default="")
|
|
169
171
|
|
|
@@ -195,6 +197,10 @@ class Curex(Model):
|
|
|
195
197
|
|
|
196
198
|
_name = {"cur__ticker", "ex__name"}
|
|
197
199
|
|
|
200
|
+
class Meta:
|
|
201
|
+
table_description = "Currency in Exchange"
|
|
202
|
+
unique_together = (("cur_id", "ex_id"),)
|
|
203
|
+
|
|
198
204
|
|
|
199
205
|
class Pair(Model, TsTrait):
|
|
200
206
|
id = fields.SmallIntField(True)
|
|
@@ -211,7 +217,7 @@ class Pair(Model, TsTrait):
|
|
|
211
217
|
table_description = "Coin/Currency pairs"
|
|
212
218
|
unique_together = (("coin", "cur", "ex"),)
|
|
213
219
|
|
|
214
|
-
def repr(self):
|
|
220
|
+
def repr(self, *args):
|
|
215
221
|
return f"{self.coin.ticker}/{self.cur.ticker}"
|
|
216
222
|
|
|
217
223
|
|
|
@@ -229,7 +235,7 @@ class Direction(Model):
|
|
|
229
235
|
table_description = "Trade directions"
|
|
230
236
|
unique_together = (("pair", "sell"),)
|
|
231
237
|
|
|
232
|
-
def repr(self):
|
|
238
|
+
def repr(self, *args):
|
|
233
239
|
return f"{self.pair.coin.ticker}/{self.pair.cur.ticker} {'SELL' if self.sell else 'BUY'}"
|
|
234
240
|
|
|
235
241
|
|
|
@@ -251,8 +257,8 @@ class User(BaseUser, UserRefTrait, UserInfoTrait): # tg user
|
|
|
251
257
|
|
|
252
258
|
class Agent(Model, TsTrait):
|
|
253
259
|
id: int
|
|
260
|
+
exid: int = fields.IntField()
|
|
254
261
|
ex: fields.ForeignKeyRelation[Ex] = fields.ForeignKeyField("models.Ex", related_name="agents")
|
|
255
|
-
# ex_id: int
|
|
256
262
|
auth: dict = fields.JSONField(null=True)
|
|
257
263
|
user: fields.ForeignKeyRelation[User] = fields.ForeignKeyField("models.User", related_name="agents")
|
|
258
264
|
user_id: int
|
|
@@ -263,11 +269,12 @@ class Agent(Model, TsTrait):
|
|
|
263
269
|
_icon = "spy"
|
|
264
270
|
_name = {"ex__name", "user__username"}
|
|
265
271
|
|
|
266
|
-
def repr(self):
|
|
267
|
-
|
|
272
|
+
# def repr(self, *args):
|
|
273
|
+
# return f"{self.ex.name}-{self.user.username}"
|
|
268
274
|
|
|
269
|
-
def balance(self) ->
|
|
270
|
-
return
|
|
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)
|
|
271
278
|
|
|
272
279
|
class Meta:
|
|
273
280
|
table_description = "Agents"
|
|
@@ -276,11 +283,19 @@ class Agent(Model, TsTrait):
|
|
|
276
283
|
class PydanticMeta:
|
|
277
284
|
computed = ["balance"]
|
|
278
285
|
|
|
279
|
-
class PydanticMetaListItem:
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
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)
|
|
284
299
|
|
|
285
300
|
|
|
286
301
|
class Adpm(Model):
|
|
@@ -304,14 +319,14 @@ class Ad(Model, TsTrait):
|
|
|
304
319
|
detail: str = fields.CharField(4095, null=True)
|
|
305
320
|
autoMsg: str = fields.CharField(255, null=True)
|
|
306
321
|
agent: fields.ForeignKeyRelation[Agent] = fields.ForeignKeyField("models.Agent", "ads")
|
|
307
|
-
status:
|
|
322
|
+
status: AdStatus = fields.IntEnumField(AdStatus)
|
|
308
323
|
|
|
309
324
|
orders: fields.ReverseRelation["Order"]
|
|
310
325
|
|
|
311
326
|
_icon = "ad"
|
|
312
327
|
_name = {"direction__pair__coin__ticker", "direction__pair__cur__ticker", "direction__sell", "price"}
|
|
313
328
|
|
|
314
|
-
def repr(self):
|
|
329
|
+
def repr(self, *args):
|
|
315
330
|
return f"{TradeType(int(self.direction.sell.name)).name}: {self.price:.3g}"
|
|
316
331
|
|
|
317
332
|
class Meta:
|
|
@@ -358,7 +373,7 @@ class Pmcur(Model): # for fiat with no exs tie
|
|
|
358
373
|
|
|
359
374
|
# _sorts = ['-limits_count']
|
|
360
375
|
|
|
361
|
-
def repr(self):
|
|
376
|
+
def repr(self, *args):
|
|
362
377
|
return f"{self.pm.name}-{self.cur.ticker}"
|
|
363
378
|
|
|
364
379
|
# @classmethod
|
|
@@ -392,17 +407,17 @@ class Pmex(Model): # existence pm in ex with no cur tie
|
|
|
392
407
|
pm: fields.ForeignKeyRelation[Pm] = fields.ForeignKeyField("models.Pm", "pmexs")
|
|
393
408
|
pm_id: int
|
|
394
409
|
ex: fields.ForeignKeyRelation[Ex] = fields.ForeignKeyField("models.Ex", "pmexs")
|
|
395
|
-
ex_id: int
|
|
396
|
-
exid: int
|
|
410
|
+
ex_id: int
|
|
411
|
+
exid: int = fields.SmallIntField()
|
|
397
412
|
|
|
398
413
|
_name = {"pm__name", "ex__name"}
|
|
399
414
|
|
|
400
|
-
def repr(self):
|
|
415
|
+
def repr(self, *args):
|
|
401
416
|
return f"{self.pm.name}-{self.ex.name}"
|
|
402
417
|
|
|
403
418
|
class Meta:
|
|
404
419
|
table_description = "Payment methods - Currencies"
|
|
405
|
-
unique_together = (("
|
|
420
|
+
unique_together = (("pm_id", "ex_id"), ("ex_id", "exid"))
|
|
406
421
|
|
|
407
422
|
|
|
408
423
|
class Pmcurex(Model): # existence pm in ex for exact cur, with "blocked" flag
|
|
@@ -433,12 +448,13 @@ class Fiat(Model):
|
|
|
433
448
|
amount: float | None = fields.FloatField(default=0)
|
|
434
449
|
target: float | None = fields.FloatField(default=None, null=True)
|
|
435
450
|
|
|
451
|
+
exs: fields.ManyToManyRelation[Ex] = fields.ManyToManyField("models.Ex", through="fiatex", related_name="fiats")
|
|
436
452
|
orders: fields.ReverseRelation["Order"]
|
|
437
453
|
|
|
438
454
|
_icon = "cash"
|
|
439
455
|
_name = {"pmcur__pm__name", "pmcur__cur__ticker", "amount"}
|
|
440
456
|
|
|
441
|
-
def repr(self):
|
|
457
|
+
def repr(self, *args):
|
|
442
458
|
return f"{self.id}: {self.pmcur.repr()} ({self.user.username})"
|
|
443
459
|
|
|
444
460
|
class Meta:
|
|
@@ -451,6 +467,23 @@ class Fiat(Model):
|
|
|
451
467
|
# exclude_raw_fields = True
|
|
452
468
|
|
|
453
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
|
+
|
|
454
487
|
class Limit(Model):
|
|
455
488
|
pmcur: fields.ForeignKeyRelation[Pmcur] = fields.ForeignKeyField("models.Pmcur")
|
|
456
489
|
pmcur_id: int
|
|
@@ -466,7 +499,7 @@ class Limit(Model):
|
|
|
466
499
|
_icon = "frame"
|
|
467
500
|
_name = {"pmcur__pm__name", "pmcur__cur__ticker", "unit", "income", "amount"}
|
|
468
501
|
|
|
469
|
-
def repr(self):
|
|
502
|
+
def repr(self, *args):
|
|
470
503
|
return f"{self.pmcur.repr()}[{'<-' if self.income else '->'}]"
|
|
471
504
|
|
|
472
505
|
class Meta:
|
|
@@ -487,7 +520,7 @@ class Asset(Model):
|
|
|
487
520
|
_icon = "currency-bitcoin"
|
|
488
521
|
_name = {"coin__ticker", "free"}
|
|
489
522
|
|
|
490
|
-
def repr(self):
|
|
523
|
+
def repr(self, *args):
|
|
491
524
|
return f"{self.coin.ticker} {self.free:.3g}/{self.freeze:.3g} user:{self.agent.repr()}"
|
|
492
525
|
|
|
493
526
|
class Meta:
|
|
@@ -516,7 +549,7 @@ class Order(Model, TsTrait):
|
|
|
516
549
|
_icon = "file-check"
|
|
517
550
|
_name = {"fiat__pmcur__pm__name", "ad__direction__sell"}
|
|
518
551
|
|
|
519
|
-
def repr(self):
|
|
552
|
+
def repr(self, *args):
|
|
520
553
|
return f"{self.taker.repr()}: {self.amount:.3g} pm:{self.fiat.pmcur.pm.name}/{self.fiat_id} {self.status.name}"
|
|
521
554
|
|
|
522
555
|
class Meta:
|
|
@@ -571,7 +604,7 @@ class Investment(Model, TsTrait):
|
|
|
571
604
|
_icon = "trending-up"
|
|
572
605
|
_name = {"dep__pid", "amount"}
|
|
573
606
|
|
|
574
|
-
def repr(self):
|
|
607
|
+
def repr(self, *args):
|
|
575
608
|
return f"{self.amount:.3g} {self.dep.repr()}"
|
|
576
609
|
|
|
577
610
|
class Meta:
|
|
@@ -588,7 +621,7 @@ class TestEx(Model):
|
|
|
588
621
|
_icon = "test-pipe"
|
|
589
622
|
_name = {"ex__name", "action", "ok"}
|
|
590
623
|
|
|
591
|
-
def repr(self):
|
|
624
|
+
def repr(self, *args):
|
|
592
625
|
return f"{self.ex.name} {self.action.name} {self.ok}"
|
|
593
626
|
|
|
594
627
|
class Meta:
|
|
@@ -606,7 +639,7 @@ class Vpn(Model):
|
|
|
606
639
|
_icon = "vpn"
|
|
607
640
|
_name = {"pub"}
|
|
608
641
|
|
|
609
|
-
def repr(self):
|
|
642
|
+
def repr(self, *args):
|
|
610
643
|
return self.user.username
|
|
611
644
|
|
|
612
645
|
class Meta:
|
|
@@ -623,7 +656,7 @@ class Invite(Model, TsTrait):
|
|
|
623
656
|
_icon = "invite"
|
|
624
657
|
_name = {"ref__username", "protege__username", "approved"}
|
|
625
658
|
|
|
626
|
-
def repr(self):
|
|
659
|
+
def repr(self, *args):
|
|
627
660
|
return self.protege.name
|
|
628
661
|
|
|
629
662
|
class Meta:
|
|
@@ -641,7 +674,7 @@ class Credit(Model, TsTrait):
|
|
|
641
674
|
_icon = "credit"
|
|
642
675
|
_name = {"lender__username", "borrower__username", "amount"}
|
|
643
676
|
|
|
644
|
-
def repr(self):
|
|
677
|
+
def repr(self, *args):
|
|
645
678
|
return self.borrower.name
|
|
646
679
|
|
|
647
680
|
class Meta:
|
|
@@ -7,7 +7,8 @@ pyproject.toml
|
|
|
7
7
|
tests/__init__.py
|
|
8
8
|
tests/test_db.py
|
|
9
9
|
xync_schema/__init__.py
|
|
10
|
-
xync_schema/
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|