xync-client 0.0.141__py3-none-any.whl → 0.0.156.dev18__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.
Files changed (40) hide show
  1. xync_client/Abc/AdLoader.py +5 -0
  2. xync_client/Abc/Agent.py +354 -8
  3. xync_client/Abc/Ex.py +432 -25
  4. xync_client/Abc/HasAbotUid.py +10 -0
  5. xync_client/Abc/InAgent.py +0 -11
  6. xync_client/Abc/PmAgent.py +34 -26
  7. xync_client/Abc/xtype.py +57 -3
  8. xync_client/Bybit/InAgent.py +233 -409
  9. xync_client/Bybit/agent.py +844 -777
  10. xync_client/Bybit/etype/__init__.py +0 -0
  11. xync_client/Bybit/etype/ad.py +54 -86
  12. xync_client/Bybit/etype/cred.py +29 -9
  13. xync_client/Bybit/etype/order.py +75 -103
  14. xync_client/Bybit/ex.py +35 -48
  15. xync_client/Gmail/__init__.py +119 -98
  16. xync_client/Htx/agent.py +213 -40
  17. xync_client/Htx/etype/ad.py +40 -16
  18. xync_client/Htx/etype/order.py +194 -0
  19. xync_client/Htx/ex.py +17 -19
  20. xync_client/Mexc/agent.py +268 -0
  21. xync_client/Mexc/api.py +1255 -0
  22. xync_client/Mexc/etype/ad.py +52 -1
  23. xync_client/Mexc/etype/order.py +354 -0
  24. xync_client/Mexc/ex.py +34 -22
  25. xync_client/Okx/1.py +14 -0
  26. xync_client/Okx/agent.py +39 -0
  27. xync_client/Okx/ex.py +8 -8
  28. xync_client/Pms/Payeer/agent.py +396 -0
  29. xync_client/Pms/Payeer/login.py +1 -59
  30. xync_client/Pms/Payeer/trade.py +58 -0
  31. xync_client/Pms/Volet/__init__.py +82 -63
  32. xync_client/Pms/Volet/api.py +5 -4
  33. xync_client/loader.py +2 -0
  34. xync_client/pm_unifier.py +1 -1
  35. {xync_client-0.0.141.dist-info → xync_client-0.0.156.dev18.dist-info}/METADATA +5 -1
  36. {xync_client-0.0.141.dist-info → xync_client-0.0.156.dev18.dist-info}/RECORD +38 -29
  37. xync_client/Pms/Payeer/__init__.py +0 -253
  38. xync_client/Pms/Payeer/api.py +0 -25
  39. {xync_client-0.0.141.dist-info → xync_client-0.0.156.dev18.dist-info}/WHEEL +0 -0
  40. {xync_client-0.0.141.dist-info → xync_client-0.0.156.dev18.dist-info}/top_level.txt +0 -0
File without changes
@@ -1,7 +1,7 @@
1
1
  from enum import StrEnum
2
2
  from typing import List, Optional, Any, Literal
3
- from pydantic import BaseModel, Field, field_serializer
4
- from xync_schema import xtype
3
+ from pydantic import BaseModel, Field
4
+ from xync_client.Bybit.etype.cred import MyPaymentTerm
5
5
  from xync_schema.xtype import BaseAd
6
6
 
7
7
  from xync_client.Abc.xtype import BaseAdUpdate
@@ -13,9 +13,21 @@ class AdStatus(StrEnum):
13
13
 
14
14
 
15
15
  class AdsReq(BaseModel):
16
- tokenId: str
17
- currencyId: str
18
- side: Literal["0", "1"] # 0 покупка, # 1 продажа
16
+ tokenId: str = Field(validation_alias="coin_id")
17
+ currencyId: str = Field(validation_alias="cur_id")
18
+ side: Literal["0", "1"] = Field(validation_alias="is_sell") # 0 покупка, # 1 продажа
19
+ payment: list[str] = Field([], validation_alias="pm_ids") # int
20
+ size: str = Field("20", validation_alias="limit") # int
21
+ page: str = "1" # int
22
+ amount: str = "" # float
23
+ vaMaker: bool = Field(False, validation_alias="vm_only")
24
+ canTrade: bool = False
25
+ userId: str = "" # int
26
+ verificationFilter: Literal[0, 1, 2] = 0
27
+ sortType: Literal["OVERALL_RANKING", "TRADE_VOLUME", "TRADE_COMPLETION_RATE", "TRADE_PRICE"] = "OVERALL_RANKING"
28
+ paymentPeriod: Literal[[], [15], [30], [60]] = []
29
+ itemRegion: int = 1
30
+ bulkMaker: bool = False
19
31
 
20
32
 
21
33
  class Currency(BaseModel):
@@ -79,7 +91,39 @@ class TradingPreferenceSet(BaseModel):
79
91
  registerTimeThreshold: int
80
92
 
81
93
 
94
+ class AdPostRequest(BaseModel):
95
+ tokenId: str
96
+ currencyId: str
97
+ side: Literal[0, 1] # 0 - покупка, 1 - продажа
98
+ priceType: Literal[0, 1] # 0 - fix rate, 1 - floating
99
+ premium: str
100
+ price: str
101
+ minAmount: str
102
+ maxAmount: str
103
+ remark: str
104
+ tradingPreferenceSet: TradingPreferenceSet
105
+ paymentIds: list[str] # list[int]
106
+ quantity: str # float
107
+ paymentPeriod: int = 15
108
+ itemType: Literal["ORIGIN", "BULK"] = "ORIGIN"
109
+
110
+
111
+ class AdUpdateRequest(AdPostRequest, BaseAdUpdate):
112
+ actionType: Literal["MODIFY", "ACTIVE"] = "MODIFY"
113
+
114
+
82
115
  class Ad(BaseAd):
116
+ tokenId: str = None # for initial actualize
117
+ currencyId: str = None # for initial actualize
118
+ side: Literal[0, 1] = None # for initial actualize # 0 - покупка, 1 - продажа (для мейкера, т.е КАКАЯ объява)
119
+ priceType: Literal[0, 1] = None # for initial actualize # 0 - fix rate, 1 - floating
120
+ premium: str = None # for initial actualize
121
+ price: str = None # for initial actualize
122
+ maxAmount: str = Field(serialization_alias="max_fiat")
123
+ minAmount: str = Field(serialization_alias="min_fiat")
124
+ remark: str = Field(serialization_alias="auto_msg")
125
+ tradingPreferenceSet: TradingPreferenceSet | None = None # for initial actualize
126
+
83
127
  accountId: str = None # for initial actualize
84
128
  authStatus: int = None # for initial actualize
85
129
  authTag: List[str] = None # for initial actualize
@@ -87,7 +131,6 @@ class Ad(BaseAd):
87
131
  baned: bool = None # for initial actualize
88
132
  blocked: str = None # for initial actualize
89
133
  createDate: str = None # for initial actualize
90
- currencyId: str = None # for initial actualize
91
134
  executedQuantity: str = None # for initial actualize
92
135
  fee: str = None # for initial actualize
93
136
  finishNum: int = None # for initial actualize
@@ -98,27 +141,18 @@ class Ad(BaseAd):
98
141
  lastLogoutTime: str = None # for initial actualize
99
142
  lastQuantity: str = Field(serialization_alias="quantity")
100
143
  makerContact: bool = None # for initial actualize
101
- maxAmount: str = Field(serialization_alias="max_fiat")
102
- minAmount: str = Field(serialization_alias="min_fiat")
103
144
  nickName: str = None # for initial actualize
104
145
  orderNum: int = None # for initial actualize
105
146
  paymentPeriod: int = None # for initial actualize
106
147
  payments: List[str] = None # for initial actualize
107
- premium: str = None # for initial actualize
108
- price: str = None # for initial actualize
109
- priceType: Literal[0, 1] = None # for initial actualize # 0 - fix rate, 1 - floating
110
148
  quantity: str = Field(serialization_alias="allQuantity") # for initial actualize
111
149
  recentExecuteRate: int = None # for initial actualize
112
150
  recentOrderNum: int = None # for initial actualize
113
151
  recommend: bool = None # for initial actualize
114
152
  recommendTag: str = None # for initial actualize
115
- remark: str = Field(serialization_alias="auto_msg")
116
- side: Literal[0, 1] = None # for initial actualize # 0 - покупка, 1 - продажа (для мейкера, т.е КАКАЯ объява)
117
153
  status: Literal[10, 20, 30] # 10: online; 20: offline; 30: completed
118
154
  symbolInfo: SymbolInfo = None # for initial actualize
119
- tokenId: str = None # for initial actualize
120
155
  tokenName: str = None # for initial actualize
121
- tradingPreferenceSet: TradingPreferenceSet | None = None # for initial actualize
122
156
  userId: str
123
157
  userMaskId: str = None # for initial actualize
124
158
  userType: str = None # for initial actualize
@@ -126,77 +160,11 @@ class Ad(BaseAd):
126
160
  verificationOrderLabels: List[Any] = None # for initial actualize
127
161
  verificationOrderSwitch: bool = None # for initial actualize
128
162
  version: int = None # for initial actualize
129
- #
130
- #
131
- # class Ad(BaseAd):
132
- # accountId: str = None # for initial actualize
133
- # authStatus: int = None # for initial actualize
134
- # authTag: List[str] = None # for initial actualize
135
- # ban: bool = None # for initial actualize
136
- # baned: bool = None # for initial actualize
137
- # blocked: str = None # for initial actualize
138
- # createDate: str = None # for initial actualize
139
- # currencyId: str = None # for initial actualize
140
- # executedQuantity: str = None # for initial actualize
141
- # fee: str = None # for initial actualize
142
- # finishNum: int = None # for initial actualize
143
- # frozenQuantity: str = None # for initial actualize
144
- # exid: str = Field(serialization_alias="id")
145
- # isOnline: bool = None # for initial actualize
146
- # itemType: str = None # for initial actualize
147
- # lastLogoutTime: str = None # for initial actualize
148
- # quantity: str = Field(serialization_alias="lastQuantity")
149
- # makerContact: bool = None # for initial actualize
150
- # max_fiat: str = Field(serialization_alias="maxAmount")
151
- # min_fiat: str = Field(serialization_alias="minAmount")
152
- # nickName: str = None # for initial actualize
153
- # orderNum: int = None # for initial actualize
154
- # paymentPeriod: int = None # for initial actualize
155
- # payments: List[str] = None # for initial actualize
156
- # premium: str = None # for initial actualize
157
- # price: str = None # for initial actualize
158
- # priceType: Literal[0, 1] = None # for initial actualize # 0 - fix rate, 1 - floating
159
- # allQuantity: str = Field(serialization_alias="quantity") # for initial actualize
160
- # recentExecuteRate: int = None # for initial actualize
161
- # recentOrderNum: int = None # for initial actualize
162
- # recommend: bool = None # for initial actualize
163
- # recommendTag: str = None # for initial actualize
164
- # auto_msg: str = Field(serialization_alias="remark")
165
- # is_sell: Literal[0, 1] = Field(serialization_alias="side") # for initial actualize # 0 - покупка, 1 - продажа (для мейкера, т.е КАКАЯ объява)
166
- # status: Literal[10, 20, 30] # 10: online; 20: offline; 30: completed
167
- # symbolInfo: SymbolInfo = None # for initial actualize
168
- # tokenId: str = None # for initial actualize
169
- # tokenName: str = None # for initial actualize
170
- # tradingPreferenceSet: TradingPreferenceSet | None = None # for initial actualize
171
- # userId: str = Field(serialization_alias="maker__exid")
172
- # userMaskId: str = None # for initial actualize
173
- # userType: str = None # for initial actualize
174
- # verificationOrderAmount: str = None # for initial actualize
175
- # verificationOrderLabels: List[Any] = None # for initial actualize
176
- # verificationOrderSwitch: bool = None # for initial actualize
177
- # version: int = None # for initial actualize
178
-
179
- @field_serializer("status")
180
- def status(self, status, _info) -> xtype.AdStatus:
181
- return {10: xtype.AdStatus.active, 20: xtype.AdStatus.defActive, 30: xtype.AdStatus.soldOut}[status]
182
-
183
163
 
184
- class AdPostRequest(BaseModel):
185
- tokenId: str
186
- currencyId: str
187
- side: Literal[0, 1] # 0 - покупка, 1 - продажа
188
- priceType: Literal[0, 1] # 0 - fix rate, 1 - floating
189
- premium: str
190
- price: str
191
- minAmount: str
192
- maxAmount: str
193
- remark: str
194
- tradingPreferenceSet: TradingPreferenceSet
195
- paymentIds: list[str]
196
- quantity: str
197
- paymentPeriod: int
198
- itemType: str
164
+ # @field_serializer("status")
165
+ # def status(self, status, _info) -> xtype.AdStatus:
166
+ # return {10: xtype.AdStatus.active, 20: xtype.AdStatus.defActive, 30: xtype.AdStatus.soldOut}[status]
199
167
 
200
168
 
201
- class AdUpdateRequest(AdPostRequest, BaseAdUpdate):
202
- actionType: Literal["MODIFY", "ACTIVE"] = "MODIFY"
169
+ class MyAd(Ad):
170
+ paymentTerms: List[MyPaymentTerm]
@@ -1,5 +1,3 @@
1
- from typing import Literal
2
-
3
1
  from pydantic import BaseModel
4
2
 
5
3
  from xync_client.Abc.xtype import CredExOut
@@ -15,18 +13,31 @@ class PaymentItem(BaseModel):
15
13
  required: bool
16
14
 
17
15
 
18
- class PaymentConfigVo(BaseModel):
19
- paymentType: str
16
+ class BasePaymentConf(BaseModel):
17
+ paymentType: int
18
+ paymentName: str
19
+
20
+
21
+ class PaymentConfig(BasePaymentConf):
22
+ class PaymentTemplateItem(BaseModel):
23
+ labelDialect: str
24
+ placeholderDialect: str
25
+ fieldName: str
26
+
27
+ paymentDialect: str
28
+ paymentTemplateItem: list[PaymentTemplateItem]
29
+
30
+
31
+ class PaymentConfigVo(BasePaymentConf):
20
32
  checkType: int
21
33
  sort: int
22
- paymentName: str
23
34
  addTips: str
24
35
  itemTips: str
25
- online: Literal[0, 1] # Non-balance coin purchase (0 Offline), balance coin purchase (1 Online)
26
- items: list[PaymentItem]
36
+ online: int
37
+ items: list[dict[str, str | bool]]
27
38
 
28
39
 
29
- class CredEpyd(CredExOut):
40
+ class PaymentTerm(CredExOut):
30
41
  id: str # int
31
42
  realName: str
32
43
  paymentType: int # int
@@ -44,7 +55,7 @@ class CredEpyd(CredExOut):
44
55
  mobile: str
45
56
  businessName: str
46
57
  concept: str
47
- online: str
58
+ online: str = None
48
59
  paymentExt1: str
49
60
  paymentExt2: str
50
61
  paymentExt3: str
@@ -54,6 +65,15 @@ class CredEpyd(CredExOut):
54
65
  paymentTemplateVersion: int
55
66
 
56
67
 
68
+ class MyPaymentTerm(PaymentTerm):
69
+ paymentConfig: PaymentConfig
70
+ realNameVerified: bool
71
+
72
+
73
+ class CredEpyd(PaymentTerm):
74
+ securityRiskToken: str = ""
75
+
76
+
57
77
  class MyCredEpyd(CredEpyd): # todo: заменить везде где надо CredEpyd -> MyCredEpyd
58
78
  countNo: str
59
79
  hasPaymentTemplateChanged: bool
@@ -1,10 +1,10 @@
1
- from datetime import datetime
2
1
  from enum import IntEnum
3
2
  from typing import Literal
4
3
 
5
4
  from pydantic import BaseModel
6
5
 
7
- from xync_client.Bybit.etype.cred import CredEpyd
6
+ from xync_client.Abc.xtype import RemapBase
7
+ from xync_client.Bybit.etype.cred import CredEpyd, PaymentTerm as CredPaymentTerm, PaymentConfigVo
8
8
 
9
9
 
10
10
  class Topic(IntEnum):
@@ -15,34 +15,31 @@ class Topic(IntEnum):
15
15
 
16
16
 
17
17
  class Status(IntEnum):
18
- deleted = 40 # order canceled
19
- created = 10
20
- appealable = 20 # waiting for seller to release
21
- canceled = 40
22
- completed = 50 # order finished
23
- appealed_by_buyer = 30 # appealing
24
- appealed_by_seller = 30
25
- buyer_appeal_disputed_by_seller = 30
26
- paid = 50
27
- rejected = 40
28
- request_canceled = 40
29
- seller_appeal_disputed_by_buyer = 30
30
-
31
-
32
- class StatusApi(IntEnum):
33
- created = 1
34
- _web3 = 5
35
- wait_for_buyer = 10 # ws_canceled
36
- wait_for_seller = 20
37
- appealed = 30
38
- canceled = 40
39
- completed = 50
40
- _paying_online = 60
41
- _pay_fail_online = 70
42
- hotswap_cancelled = 80
43
- _buyer_sel_tokenId = 90
44
- objectioning = 100
45
- waiting_for_objection = 110
18
+ ws_new = 1
19
+ # chain = 5 # waiting for chain (only web3)
20
+ created = 10 # waiting for buyer to pay
21
+ paid = 20 # waiting for seller to release
22
+ appealed_by_seller = 30 # appealing
23
+ appealed_by_buyer = 30 # the same appealing
24
+ canceled = 40 # order cancelled
25
+ complete = 50 # order finished
26
+ # a = 60 # paying (only when paying online)
27
+ # a = 70 # pay fail (only when paying online)
28
+ # a = 80 # exception cancelled (the coin convert to other coin only hotswap)
29
+ # a = 90 # waiting for buyer to select tokenId
30
+ appeal_disputed = 100 # objectioning
31
+ appeal_dispute_disputed = 110 # waiting for the user to raise an objection
32
+
33
+
34
+ class TakeAdReq(BaseModel):
35
+ ad_id: int | str
36
+ amount: float
37
+ is_sell: bool
38
+ pm_id: int
39
+ coin_id: int
40
+ cur_id: int
41
+ quantity: float | None = None
42
+ price: float | None = None
46
43
 
47
44
 
48
45
  class OrderRequest(BaseModel):
@@ -60,33 +57,46 @@ class OrderRequest(BaseModel):
60
57
  flag: Literal["amount", "quantity"]
61
58
  version: str = "1.0"
62
59
  securityRiskToken: str = ""
60
+ isFromAi: bool = False
61
+
62
+
63
+ class OrderSellRequest(OrderRequest):
64
+ paymentId: str
65
+ paymentType: str
63
66
 
64
67
 
65
68
  class PreOrderResp(BaseModel):
66
- price: str # float
67
- curPrice: str
68
- totalAmount: float
69
- minAmount: float
70
- maxAmount: float
71
- minQuantity: float
72
- maxQuantity: float
73
- payments: list[str] # list[int]
74
- status: Literal[10, 20]
75
- paymentTerms: list
76
- paymentPeriod: Literal[15]
77
- lastQuantity: float
78
- lastPrice: float
69
+ id: str # bigint
70
+ price: str # float .cur.scale
71
+ lastQuantity: str # float .coin.scale
72
+ curPrice: str # hex 32
73
+ lastPrice: str # float .cur.scale # future
79
74
  isOnline: bool
80
- lastLogoutTime: datetime
81
- itemPriceAvailableTime: datetime
82
- itemPriceValidTime: int # 45000
75
+ lastLogoutTime: str # timestamp(0)+0
76
+ payments: list[str] # list[int]
77
+ status: Literal[10, 15, 20]
78
+ paymentTerms: list # empty
79
+ paymentPeriod: Literal[15, 30, 60]
80
+ totalAmount: str # float .cur.scale
81
+ minAmount: str # float .cur.scale
82
+ maxAmount: str # float .cur.scale
83
+ minQuantity: str # float .coin.scale
84
+ maxQuantity: str # float .coin.scale
85
+ itemPriceAvailableTime: str # timestamp(0)+0
86
+ itemPriceValidTime: Literal["45000"]
83
87
  itemType: Literal["ORIGIN"]
88
+ shareItem: bool # False
84
89
 
85
90
 
86
91
  class OrderResp(BaseModel):
87
92
  orderId: str
88
93
  isNeedConfirm: bool
94
+ confirmId: str = ""
89
95
  success: bool
96
+ securityRiskToken: str = ""
97
+ riskTokenType: Literal["challenge", ""] = ""
98
+ riskVersion: Literal["1", "2", ""] = ""
99
+ needSecurityRisk: bool
90
100
  isBulkOrder: bool
91
101
  confirmed: str = None
92
102
  delayTime: str
@@ -121,50 +131,28 @@ class AppraiseInfo(BaseModel):
121
131
  updateDate: str
122
132
 
123
133
 
124
- class PaymentConfigVo(BaseModel):
125
- paymentType: str
126
- checkType: int
127
- sort: int
128
- paymentName: str
129
- addTips: str
130
- itemTips: str
131
- online: int
132
- items: list[dict[str, str | bool]]
133
-
134
-
135
- class PaymentTerm(BaseModel):
136
- id: str
137
- realName: str
138
- paymentType: int
139
- bankName: str
140
- branchName: str
141
- accountNo: str
142
- qrcode: str
143
- visible: int
144
- payMessage: str
145
- firstName: str
146
- lastName: str
147
- secondLastName: str
148
- clabe: str
149
- debitCardNumber: str
150
- mobile: str
151
- businessName: str
152
- concept: str
153
- online: str
154
- paymentExt1: str
155
- paymentExt2: str
156
- paymentExt3: str
157
- paymentExt4: str
158
- paymentExt5: str
159
- paymentExt6: str
160
- paymentTemplateVersion: int
134
+ class PaymentTerm(CredPaymentTerm):
161
135
  paymentConfigVo: PaymentConfigVo
162
136
  ruPaymentPrompt: bool
163
137
 
164
138
 
165
- class OrderItem(BaseModel):
166
- id: str
139
+ class _BaseOrder(RemapBase):
140
+ _remap = {"status": {}}
141
+
142
+ id: int
143
+ userId: int
144
+ createDate: int
167
145
  side: Literal[0, 1] # int: 0 покупка, 1 продажа (именно для меня - апи агента, и пох мейкер я или тейкер)
146
+ status: Literal[*[s.value for s in Status]]
147
+
148
+
149
+ class _BaseChange(_BaseOrder):
150
+ makerUserId: int
151
+ appealedTimes: int
152
+ totalAppealedTimes: int
153
+
154
+
155
+ class OrderItem(_BaseOrder):
168
156
  tokenId: str
169
157
  orderType: Literal[
170
158
  "ORIGIN", "SMALL_COIN", "WEB3"
@@ -177,14 +165,9 @@ class OrderItem(BaseModel):
177
165
  fee: str
178
166
  targetNickName: str
179
167
  targetUserId: str # не я
180
- status: Literal[
181
- 5, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110
182
- ] # 5: waiting for chain (only web3), 10: waiting for buyer to pay, 20: waiting for seller to release, 30: appealing, 40: order cancelled, 50: order finished, 60: paying (only when paying online), 70: pay fail (only when paying online), 80: exception cancelled (the coin convert to other coin, only hotswap), 90: waiting for buyer to select tokenId, 100: objectioning, 110: waiting for the user to raise an objection
183
168
  selfUnreadMsgCount: str
184
- createDate: str
185
169
  transferLastSeconds: str
186
170
  appealLastSeconds: str
187
- userId: str # я
188
171
  sellerRealName: str
189
172
  buyerRealName: str
190
173
  judgeInfo: JudgeInfo
@@ -194,7 +177,7 @@ class OrderItem(BaseModel):
194
177
 
195
178
 
196
179
  class OrderFull(OrderItem):
197
- itemId: str
180
+ itemId: int
198
181
  makerUserId: str
199
182
  targetAccountId: str
200
183
  targetFirstName: str
@@ -297,17 +280,6 @@ class Message(BaseModel):
297
280
  onlyForCustomer: int | None = None
298
281
 
299
282
 
300
- class _BaseChange(BaseModel):
301
- userId: int
302
- makerUserId: int
303
- id: str
304
- createDate: int
305
- side: int
306
- appealedTimes: int
307
- totalAppealedTimes: int
308
- status: StatusApi | None = None
309
-
310
-
311
283
  class StatusChange(_BaseChange):
312
284
  appealVersion: int = None
313
285
 
@@ -336,7 +308,7 @@ class Receive(_BaseMsg):
336
308
  class Read(_BaseMsg):
337
309
  readAmount: int
338
310
  read: Literal["101", "110", "11", "111"]
339
- orderStatus: StatusApi
311
+ orderStatus: Status
340
312
 
341
313
 
342
314
  class SellerCancelChange(BaseModel):
xync_client/Bybit/ex.py CHANGED
@@ -2,26 +2,39 @@ import json
2
2
  from asyncio import run
3
3
 
4
4
  from pyro_client.client.file import FileClient
5
+ from x_client import df_hdrs
5
6
  from x_model import init_db
6
7
  from xync_schema import models, xtype
8
+ from xync_schema.enums import AdStatus, AgentStatus
7
9
  from xync_schema.models import Ex, Agent
8
10
 
9
11
  from xync_client.Abc.Ex import BaseExClient
10
12
  from xync_client.loader import NET_TOKEN
11
13
  from xync_client.Bybit.etype import ad
12
- from xync_client.Abc.xtype import PmEx, MapOfIdsList
14
+ from xync_client.Abc.xtype import PmEx, MapOfIdsList, GetAds
13
15
  from xync_client.loader import TORM
14
16
 
15
17
 
16
18
  class ExClient(BaseExClient): # Bybit client
17
- headers = {"cookie": ";"} # rewrite token for public methods
19
+ host = "api2.bybit.com"
20
+ headers = df_hdrs # rewrite token for public methods
18
21
  agent: Agent = None
19
22
 
20
23
  async def _get_auth_cks(self) -> dict[str, str]:
21
24
  if not self.agent:
22
- self.agent = await Agent.get(actor__ex=self.ex).prefetch_related("actor")
25
+ self.agent = (
26
+ await Agent.filter(actor__ex=self.ex, status__gt=AgentStatus.off).prefetch_related("actor").first()
27
+ )
23
28
  return self.agent.auth["cookies"]
24
29
 
30
+ @staticmethod
31
+ def ad_status(status: int) -> AdStatus:
32
+ return {
33
+ 10: AdStatus.active,
34
+ 20: AdStatus.defActive,
35
+ 30: AdStatus.soldOut,
36
+ }[status]
37
+
25
38
  async def _get_config(self):
26
39
  resp = await self._get("/fiat/p2p/config/initial")
27
40
  return resp["result"] # todo: tokens, pairs, ...
@@ -68,47 +81,20 @@ class ExClient(BaseExClient): # Bybit client
68
81
  return cc, cc
69
82
 
70
83
  # 24: Список объяв по (buy/sell, cur, coin, pm)
71
- async def ads(
72
- self,
73
- coin_exid: str,
74
- cur_exid: str,
75
- is_sell: bool,
76
- pm_exids: list[str | int] = None,
77
- amount: int = None,
78
- lim: int = 50,
79
- vm_filter: bool = False,
80
- ) -> list[ad.Ad]:
81
- data = {
82
- "userId": "",
83
- "tokenId": coin_exid,
84
- "currencyId": cur_exid,
85
- "payment": pm_exids or [],
86
- "side": "0" if is_sell else "1",
87
- "size": str(lim) if lim else "20",
88
- "page": "1",
89
- "amount": str(amount) if amount else "",
90
- "vaMaker": vm_filter,
91
- "bulkMaker": False,
92
- "canTrade": False,
93
- "verificationFilter": 0,
94
- "sortType": "OVERALL_RANKING",
95
- "paymentPeriod": [],
96
- "itemRegion": 1,
97
- }
98
- # {
99
- # "userId": "",
100
- # "tokenId": coin_exid,
101
- # "currencyId": cur_exid,
102
- # "payment": pm_exids or [],
103
- # "side": "0" if is_sell else "1",
104
- # "size": lim and str(lim) or "200",
105
- # "page": "1",
106
- # "amount": str(amount) if amount else "",
107
- # "authMaker": False,
108
- # "canTrade": False,
109
- # }
110
- ads = await self._post("/fiat/otc/item/online/", data)
111
- return [ad.Ad(**_ad) for _ad in ads["result"]["items"]]
84
+ async def _ads(self, req: ad.AdsReq, post_pmexs: set[models.PmEx] = None) -> list[ad.Ad]:
85
+ if post_pmexs:
86
+ req.payment = []
87
+ req.size = str(min(1000, int(req.size) * 25))
88
+ res = await self._post("/fiat/otc/item/online/", req.model_dump())
89
+ ads = [ad.Ad(**_ad) for _ad in res["result"]["items"]]
90
+ if post_pmexs:
91
+ post_pmexids = {p.exid for p in post_pmexs}
92
+ ads = [
93
+ ad
94
+ for ad in ads
95
+ if (set(ad.payments) & post_pmexids or [True for px in post_pmexs if px.pm.norm in ad.remark.lower()])
96
+ ]
97
+ return ads
112
98
 
113
99
 
114
100
  async def main():
@@ -117,10 +103,11 @@ async def main():
117
103
  bot: FileClient = FileClient(NET_TOKEN)
118
104
  # await bot.start()
119
105
  cl = ExClient(ex, bot)
120
- await cl.set_pms()
121
- await cl.set_coins()
122
- await cl.set_pairs()
123
- _ads = await cl.ads("USDT", "GEL", False)
106
+ # await cl.set_pms()
107
+ # await cl.set_coins()
108
+ # await cl.set_pairs()
109
+ x_ads_req = GetAds(coin_id=1, cur_id=1, is_sell=True, pm_ids=[330, 366, 1853], amount=1000)
110
+ _ads = await cl.ads(x_ads_req)
124
111
  # await bot.stop()
125
112
  await cl.close()
126
113