xync-client 0.0.164__py3-none-any.whl → 0.0.172__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.
@@ -1,13 +1,17 @@
1
- from enum import StrEnum
2
- from typing import List, Optional, Any, Literal
3
- from pydantic import BaseModel, Field
4
- from xync_client.Bybit.etype.cred import MyPaymentTerm
5
- from xync_schema.xtype import BaseAd
1
+ from enum import StrEnum, IntEnum
2
+ from typing import Optional, Any, Literal
3
+ from pydantic import BaseModel, Field, model_validator
4
+ from xync_client.Abc.xtype import BaseAd, AdStatus as xAdStatus, RemapBase, BaseCredexsExidsTrait
5
+ from xync_schema.enums import Side, PriceType
6
6
 
7
- from xync_client.Abc.xtype import BaseAdUpdate
8
7
 
8
+ class AdStatus(IntEnum):
9
+ active = 10
10
+ hidden = 20
11
+ complete = 30
9
12
 
10
- class AdStatus(StrEnum):
13
+
14
+ class AdStatusReq(StrEnum):
11
15
  sold_out = "1"
12
16
  active = "2"
13
17
 
@@ -108,63 +112,80 @@ class AdPostRequest(BaseModel):
108
112
  itemType: Literal["ORIGIN", "BULK"] = "ORIGIN"
109
113
 
110
114
 
111
- class AdUpdateRequest(AdPostRequest, BaseAdUpdate):
115
+ class AdRequest(AdPostRequest, BaseAd):
112
116
  actionType: Literal["MODIFY", "ACTIVE"] = "MODIFY"
113
117
 
114
118
 
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
-
127
- accountId: str = None # for initial actualize
128
- authStatus: int = None # for initial actualize
129
- authTag: List[str] = None # for initial actualize
130
- ban: bool = None # for initial actualize
131
- baned: bool = None # for initial actualize
132
- blocked: str = None # for initial actualize
133
- createDate: str = None # for initial actualize
134
- executedQuantity: str = None # for initial actualize
135
- fee: str = None # for initial actualize
136
- finishNum: int = None # for initial actualize
137
- frozenQuantity: str = None # for initial actualize
138
- id: str = Field(serialization_alias="exid")
139
- isOnline: bool = None # for initial actualize
140
- itemType: str = None # for initial actualize
141
- lastLogoutTime: str = None # for initial actualize
142
- lastQuantity: str = Field(serialization_alias="quantity")
143
- makerContact: bool = None # for initial actualize
144
- nickName: str = None # for initial actualize
145
- orderNum: int = None # for initial actualize
146
- paymentPeriod: int = None # for initial actualize
147
- payments: List[str] = None # for initial actualize
148
- quantity: str = Field(serialization_alias="allQuantity") # for initial actualize
149
- recentExecuteRate: int = None # for initial actualize
150
- recentOrderNum: int = None # for initial actualize
151
- recommend: bool = None # for initial actualize
152
- recommendTag: str = None # for initial actualize
153
- status: Literal[10, 20, 30] # 10: online; 20: offline; 30: completed
154
- symbolInfo: SymbolInfo = None # for initial actualize
155
- tokenName: str = None # for initial actualize
156
- userId: str
157
- userMaskId: str = None # for initial actualize
158
- userType: str = None # for initial actualize
159
- verificationOrderAmount: str = None # for initial actualize
160
- verificationOrderLabels: List[Any] = None # for initial actualize
161
- verificationOrderSwitch: bool = None # for initial actualize
162
- version: int = None # for initial actualize
119
+ class Ad(BaseAd, RemapBase):
120
+ _remap = {
121
+ "status": {
122
+ AdStatus.active: xAdStatus.active,
123
+ AdStatus.hidden: xAdStatus.defActive,
124
+ AdStatus.complete: xAdStatus.soldOut,
125
+ }
126
+ }
127
+
128
+ auto_msg: None = None
129
+ cond_txt: str = Field(alias="remark")
130
+ created_at: int = Field(alias="createDate")
131
+ coinex_exid: str = Field(alias="tokenId") # ticker
132
+ curex_exid: str = Field(alias="currencyId") # ticker
133
+ maker_exid: int = Field(alias="userId")
134
+ maker_name: str = Field(alias="nickName")
135
+ max_fiat: float = Field(alias="maxAmount")
136
+ min_fiat: float = Field(alias="minAmount")
137
+ # paymentPeriod: int
138
+ pmex_exids: list[int] = Field(alias="payments")
139
+ # recentOrderNum: int
140
+ side: Literal[Side.BUY, Side.SALE]
141
+ priceType: Literal[PriceType.FIX, PriceType.FLOAT]
142
+ # tradingPreferenceSet: TradingPreferenceSet | None = None # for initial actualize
143
+
144
+ # accountId: str = None # for initial actualize
145
+ # authStatus: int = None # for initial actualize
146
+ # authTag: List[str] = None # for initial actualize
147
+ # ban: bool = None # for initial actualize
148
+ # baned: bool = None # for initial actualize
149
+ # blocked: str = None # for initial actualize
150
+ # createDate: str = None # for initial actualize
151
+ # executedQuantity: str = None # for initial actualize
152
+ # fee: str = None # for initial actualize
153
+ # finishNum: int = None # for initial actualize
154
+ # frozenQuantity: str = None # for initial actualize
155
+ # isOnline: bool = None # for initial actualize
156
+ # itemType: str = None # for initial actualize
157
+ # lastLogoutTime: str = None # for initial actualize
158
+ # lastQuantity: str = Field(serialization_alias="quantity")
159
+ # makerContact: bool = None # for initial actualize
160
+ # nickName: str = None # for initial actualize
161
+ # orderNum: int = None # for initial actualize
162
+ # paymentPeriod: int = None # for initial actualize
163
+ # payments: List[str] = None # for initial actualize
164
+ # quantity: str = Field(serialization_alias="allQuantity") # for initial actualize
165
+ # recentExecuteRate: int = None # for initial actualize
166
+ # recentOrderNum: int = None # for initial actualize
167
+ # recommend: bool = None # for initial actualize
168
+ # recommendTag: str = None # for initial actualize
169
+ # status: Literal[10, 20, 30] # 10: online; 20: offline; 30: completed
170
+ # symbolInfo: SymbolInfo = None # for initial actualize
171
+ # tokenName: str = None # for initial actualize
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
163
178
 
164
179
  # @field_serializer("status")
165
180
  # def status(self, status, _info) -> xtype.AdStatus:
166
181
  # return {10: xtype.AdStatus.active, 20: xtype.AdStatus.defActive, 30: xtype.AdStatus.soldOut}[status]
167
182
 
168
183
 
169
- class MyAd(Ad):
170
- paymentTerms: List[MyPaymentTerm]
184
+ class MyAd(Ad, BaseCredexsExidsTrait):
185
+ credex_exids: list[int] = Field(alias="paymentTerms")
186
+ # paymentTerms: list[MyPaymentTerm]
187
+
188
+ @model_validator(mode="before")
189
+ def cred_exids(cls, data: "MyAd"):
190
+ data["paymentTerms"] = [pt["id"] for pt in data["paymentTerms"]]
191
+ return data
@@ -1,6 +1,6 @@
1
- from pydantic import BaseModel
1
+ from pydantic import BaseModel, Field, model_validator
2
2
 
3
- from xync_client.Abc.xtype import CredExOut
3
+ from xync_client.Abc.xtype import BaseCredEx
4
4
 
5
5
 
6
6
  class PaymentItem(BaseModel):
@@ -37,7 +37,7 @@ class PaymentConfigVo(BasePaymentConf):
37
37
  items: list[dict[str, str | bool]]
38
38
 
39
39
 
40
- class PaymentTerm(CredExOut):
40
+ class PaymentTerm(BaseModel):
41
41
  id: str # int
42
42
  realName: str
43
43
  paymentType: int # int
@@ -81,3 +81,25 @@ class MyCredEpyd(CredEpyd): # todo: заменить везде где надо
81
81
  realNameVerified: bool
82
82
  channel: str
83
83
  currencyBalance: list[str]
84
+
85
+
86
+ class CredEx(BaseCredEx):
87
+ detail: str = Field(alias="accountNo")
88
+ extra: str | None = Field(alias="bankName")
89
+ name: str = Field(alias="realName")
90
+ pmex_exid: int = Field(alias="paymentType")
91
+
92
+ @model_validator(mode="before")
93
+ def xtr_fill(cls, data: PaymentTerm):
94
+ data = dict(data)
95
+ xtr = data["bankName"]
96
+ if data["branchName"]:
97
+ xtr += (" | " if xtr else "") + data["branchName"]
98
+ if data["payMessage"]:
99
+ xtr += (" | " if xtr else "") + data["payMessage"]
100
+ if data["qrcode"]:
101
+ xtr += (" | " if xtr else "") + data["qrcode"]
102
+ if data["paymentExt1"]:
103
+ xtr += (" | " if xtr else "") + data["paymentExt1"]
104
+ data["bankName"] = xtr
105
+ return data
@@ -1,10 +1,11 @@
1
1
  from enum import IntEnum
2
2
  from typing import Literal, ClassVar
3
3
 
4
- from pydantic import BaseModel
4
+ from pydantic import BaseModel, Field, model_validator
5
+ from xync_schema.enums import OrderStatus
5
6
 
6
- from xync_client.Abc.xtype import RemapBase
7
- from xync_client.Bybit.etype.cred import CredEpyd, PaymentTerm as CredPaymentTerm, PaymentConfigVo
7
+ from xync_client.Abc.xtype import RemapBase, BaseOrderItem, BaseOrderFull, BaseOrder, BaseCounteragent
8
+ from xync_client.Bybit.etype.cred import CredEpyd, PaymentTerm as CredPaymentTerm, PaymentConfigVo, CredEx
8
9
 
9
10
 
10
11
  class Topic(IntEnum):
@@ -19,7 +20,7 @@ class Status(IntEnum):
19
20
  # chain = 5 # waiting for chain (only web3)
20
21
  created = 10 # waiting for buyer to pay
21
22
  paid = 20 # waiting for seller to release
22
- appealed_by_seller = 30 # appealing
23
+ appealed = 30 # appealing
23
24
  # appealed_by_buyer = 30 # the same appealing
24
25
  canceled = 40 # order cancelled
25
26
  completed = 50 # order finished
@@ -43,10 +44,6 @@ class TakeAdReq(BaseModel):
43
44
 
44
45
 
45
46
  class OrderRequest(BaseModel):
46
- class Side(IntEnum):
47
- BUY = 0
48
- SALE = 1
49
-
50
47
  itemId: str
51
48
  tokenId: str
52
49
  currencyId: str
@@ -137,59 +134,77 @@ class PaymentTerm(CredPaymentTerm):
137
134
 
138
135
 
139
136
  class _BaseOrder(RemapBase):
140
- _remap: ClassVar[dict[str, dict]] = {"status": {}}
141
-
142
- id: int
143
- userId: int
144
- createDate: int
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
137
+ _remap: ClassVar[dict[str, dict]] = {
138
+ "status": {
139
+ Status.ws_new: OrderStatus.created,
140
+ Status.created: OrderStatus.created,
141
+ Status.paid: OrderStatus.paid,
142
+ Status.appealed: OrderStatus.appealed_by_seller, # all appeals from bybit marks as appealed_by_seller
143
+ Status.canceled: OrderStatus.canceled,
144
+ Status.completed: OrderStatus.completed,
145
+ Status.appeal_disputed: OrderStatus.appeal_disputed, # appeal_disputed and appeal_dispute_disputed from bybit
146
+ Status.appeal_dispute_disputed: OrderStatus.appeal_disputed, # marks as just appeal_disputed
147
+ }
148
+ }
149
+ ad__pair_side__is_sell: bool = Field(
150
+ alias="side"
151
+ ) # int: 0 покупка, 1 продажа (именно для меня - апи агента, и пох мейкер я или тейкер)
152
+ created_at: int = Field(alias="createDate")
153
+
154
+
155
+ class _BaseChange(_BaseOrder, BaseOrder):
156
+ ad__pair_side__is_sell: bool # int: 0 покупка, 1 продажа (именно для меня - апи агента, и пох мейкер я или тейкер)
157
+ created_at: int
158
+ exid: int = Field(alias="id")
159
+ my_exid: int | None = None # апи агент юзер
160
+ status: OrderStatus | None = None
161
+
162
+ ad__maker_exid: int = Field(alias="makerUserId")
151
163
  appealedTimes: int
164
+ user_exid: int = Field(alias="userId") # todo: define: is it initiator or counteragent?
152
165
  totalAppealedTimes: int
153
166
 
154
167
 
155
- class OrderItem(_BaseOrder):
156
- tokenId: str
168
+ class OrderItem(_BaseOrder, BaseOrderItem):
169
+ my_exid: int = Field(alias="userId")
170
+ coinex_exid: str = Field(alias="tokenId")
157
171
  orderType: Literal[
158
172
  "ORIGIN", "SMALL_COIN", "WEB3"
159
173
  ] # str: ORIGIN: normal p2p order, SMALL_COIN: HotSwap p2p order, WEB3: web3 p2p order
160
- amount: str
161
- currencyId: str
162
- price: str
163
- notifyTokenQuantity: str
164
- notifyTokenId: str
165
- fee: str
166
- targetNickName: str
167
- targetUserId: str # не я
174
+ amount: float
175
+ curex_exid: str = Field(alias="currencyId")
176
+ price: float
177
+ # notifyTokenQuantity: str
178
+ # notifyTokenId: str
179
+ fee: float
180
+ ctr_nick: str = Field(alias="targetNickName")
181
+ ctr_exid: int = Field(alias="targetUserId")
168
182
  selfUnreadMsgCount: str
169
- transferLastSeconds: str
170
- appealLastSeconds: str
171
- sellerRealName: str
172
- buyerRealName: str
173
- judgeInfo: JudgeInfo
183
+ # transferLastSeconds: str
184
+ # appealLastSeconds: str
185
+ seller_name: str = Field(alias="sellerRealName")
186
+ buyer_name: str = Field(alias="buyerRealName")
187
+ # judgeInfo: JudgeInfo
174
188
  unreadMsgCount: str
175
- extension: Extension
176
- bulkOrderFlag: bool
189
+ # extension: Extension
190
+ # bulkOrderFlag: bool
177
191
 
178
192
 
179
- class OrderFull(OrderItem):
180
- itemId: int
181
- makerUserId: str
182
- targetAccountId: str
183
- targetFirstName: str
184
- targetSecondName: str
193
+ class OrderFull(OrderItem, BaseOrderFull):
194
+ ad_id: int = Field(alias="itemId")
195
+ ad__maker_exid: int = Field(alias="makerUserId")
196
+ my_nick: str = Field(alias="nickName")
197
+ # targetAccountId: str
198
+ # targetFirstName: str
199
+ # targetSecondName: str
185
200
  targetUserAuthStatus: int
186
201
  targetConnectInformation: str
187
- payerRealName: str
202
+ # payerRealName: str # todo: why? we have sellerRealName already
188
203
  tokenName: str
189
- quantity: str
204
+ quantity: float
190
205
  payCode: str
191
206
  paymentType: int
192
- transferDate: str
207
+ payed_at: int = Field(alias="transferDate")
193
208
  paymentTermList: list[CredEpyd]
194
209
  remark: str
195
210
  recentOrderNum: int
@@ -200,79 +215,109 @@ class OrderFull(OrderItem):
200
215
  canAppeal: str
201
216
  totalAppealTimes: str
202
217
  paymentTermResult: CredEpyd
203
- confirmedPayTerm: CredEpyd
218
+ credex: CredEx = Field(alias="confirmedPayTerm")
204
219
  appealedTimes: str
205
220
  orderFinishMinute: int
206
221
  makerFee: str
207
222
  takerFee: str
208
223
  showContact: bool
209
224
  contactInfo: list[str]
210
- tokenBalance: str
211
- fiatBalance: str
212
- updateDate: str
213
- judgeType: str
214
- canReport: bool
215
- canReportDisagree: bool
216
- canReportType: list[str]
217
- canReportDisagreeType: list[str]
225
+ tokenBalance: float
226
+ fiatBalance: float
227
+ updateDate: int
228
+ # judgeType: str
229
+ # canReport: bool
230
+ # canReportDisagree: bool
231
+ # canReportType: list[str]
232
+ # canReportDisagreeType: list[str]
218
233
  appraiseStatus: str
219
234
  appraiseInfo: AppraiseInfo
220
- canReportDisagreeTypes: list[str]
221
- canReportTypes: list[str]
222
- middleToken: str
223
- beforePrice: str
224
- beforeQuantity: str
225
- beforeToken: str
226
- alternative: str
235
+ # canReportDisagreeTypes: list[str]
236
+ # canReportTypes: list[str]
237
+ # middleToken: str
238
+ # beforePrice: str
239
+ # beforeQuantity: str
240
+ # beforeToken: str
241
+ # alternative: str
227
242
  appealUserId: str
228
243
  cancelResponsible: str
229
- chainType: str
230
- chainAddress: str
244
+ # chainType: str
245
+ # chainAddress: str
231
246
  tradeHashCode: str
232
- estimatedGasFee: str
233
- gasFeeTokenId: str
234
- tradingFeeTokenId: str
235
- onChainInfo: str
247
+ # estimatedGasFee: str
248
+ # gasFeeTokenId: str
249
+ # tradingFeeTokenId: str
250
+ # onChainInfo: str
236
251
  transactionId: str
237
252
  displayRefund: str
238
- chainWithdrawLastSeconds: str
239
- chainTransferLastSeconds: str
253
+ # chainWithdrawLastSeconds: str
254
+ # chainTransferLastSeconds: str
240
255
  orderSource: str
241
256
  cancelReason: str
242
- sellerCancelExamineRemainTime: str
243
- needSellerExamineCancel: bool
244
- couponCurrencyAmount: str
245
- totalCurrencyAmount: str
246
- usedCoupon: bool # bool: 1: used, 2: no used
247
- couponTokenId: str
248
- couponQuantity: str
249
- completedOrderAppealCount: int
250
- totalCompletedOrderAppealCount: int
251
- realOrderStatus: int
252
- appealVersion: int
253
- helpType: str
254
- appealFlowStatus: str
255
- appealSubStatus: str
256
- targetUserType: str
257
- targetUserDisplays: list[str]
258
- appealProcessChangeFlag: bool
259
- appealNegotiationNode: int
257
+ # sellerCancelExamineRemainTime: str
258
+ # needSellerExamineCancel: bool
259
+ # couponCurrencyAmount: str
260
+ # totalCurrencyAmount: str
261
+ # usedCoupon: bool # bool: 1: used, 2: no used
262
+ # couponTokenId: str
263
+ # couponQuantity: str
264
+ # completedOrderAppealCount: int
265
+ # totalCompletedOrderAppealCount: int
266
+ # realOrderStatus: int
267
+ # appealVersion: int
268
+ # helpType: str
269
+ # appealFlowStatus: str
270
+ # appealSubStatus: str
271
+ # targetUserType: str
272
+ # targetUserDisplays: list[str]
273
+ # appealProcessChangeFlag: bool
274
+ # appealNegotiationNode: int
275
+
276
+ @model_validator(mode="after") # todo: separate to common part, and special bybit only part
277
+ def users_cred_cur(self):
278
+ mc_exids = self.my_exid, self.ctr_exid
279
+ mc_nicks = self.my_nick, self.ctr_nick
280
+ sb_names = self.seller_name, self.buyer_name
281
+ im_maker = self.ad__maker_exid == self.my_exid
282
+ im_seller = self.ad__pair_side__is_sell == im_maker
283
+ taker_exid = mc_exids[int(im_maker)] # if im maker, then ctr(mc_exids[1]) - taker;
284
+ taker_nick = mc_nicks[int(im_maker)]
285
+ taker_name = sb_names[int(im_seller)] # if im seller(im_maker==ad__is_sell), then taker(sb_names[1]) - buyer;
286
+ seller_exid = mc_exids[int(not im_seller)] # if im buyer, then ctr(mc_exids[1]) - seller;
287
+ seller_nick = mc_nicks[int(not im_seller)]
288
+ self.taker = BaseCounteragent(
289
+ exid=taker_exid,
290
+ nick=taker_nick,
291
+ name=taker_name,
292
+ )
293
+ if self.credex: # по дефолту в credex confirmedPayTerm
294
+ if not self.credex.pmex_exid: # но если там пусто, берем из paymentTermResult
295
+ self.credex = CredEx.model_validate(self.paymentTermResult)
296
+ if not self.credex.pmex_exid: # а если и там пусто, то берем первый из paymentTermList
297
+ self.credex = CredEx.model_validate(self.paymentTermList[0])
298
+ self.credex.seller = BaseCounteragent(
299
+ exid=seller_exid,
300
+ nick=seller_nick,
301
+ name=self.seller_name,
302
+ )
303
+ self.credex.curex_exid = self.curex_exid
304
+ return self
260
305
 
261
306
 
262
307
  class Message(BaseModel):
263
- id: str
264
- accountId: str
308
+ exid: int = Field(alias="id")
309
+ # accountId: str
265
310
  message: str
266
311
  msgType: Literal[
267
312
  0, 1, 2, 5, 6, 7, 8
268
313
  ] # int: 0: system message, 1: text (user), 2: image (user), 5: text (admin), 6: image (admin), 7: pdf (user), 8: video (user)
269
314
  msgCode: int
270
- createDate: str
315
+ created_at: int = Field(alias="createDate")
271
316
  isRead: Literal[0, 1] # int: 1: read, 0: unread
272
317
  contentType: Literal["str", "pic", "pdf", "video"]
273
318
  roleType: str
274
- userId: str
275
- orderId: str
319
+ my_exid: int = Field(alias="userId")
320
+ order_exid: str = Field(alias="orderId")
276
321
  msgUuid: str
277
322
  nickName: str
278
323
  read: Literal[0, 1]
@@ -281,7 +326,17 @@ class Message(BaseModel):
281
326
 
282
327
 
283
328
  class StatusChange(_BaseChange):
284
- appealVersion: int = None
329
+ status: OrderStatus | None = None
330
+ appealVersion: int = None # 3 - my (seller) appeal is accepted by support # todo: выяснить другие значения
331
+
332
+ @model_validator(mode="after")
333
+ def amount_or_quantity_required(self):
334
+ if not self.status and not self.appealVersion:
335
+ raise ValueError("either status or appealVersion is required")
336
+ if not self.status:
337
+ if self.appealVersion == 3:
338
+ self.status = OrderStatus.canceled
339
+ return self
285
340
 
286
341
 
287
342
  class CountDown(_BaseChange):
@@ -307,12 +362,12 @@ class Receive(_BaseMsg):
307
362
 
308
363
  class Read(_BaseMsg):
309
364
  readAmount: int
310
- read: Literal["101", "110", "11", "111"]
365
+ read: Literal["1", "101", "110", "11", "111"]
311
366
  orderStatus: Status
312
367
 
313
368
 
314
369
  class SellerCancelChange(BaseModel):
315
370
  userId: int
316
371
  makerUserId: int
317
- id: str
372
+ id: int
318
373
  createDate: int
xync_client/Bybit/ex.py CHANGED
@@ -11,12 +11,11 @@ from xync_schema.models import Ex, Agent
11
11
  from xync_client.Abc.Ex import BaseExClient
12
12
  from xync_client.loader import NET_TOKEN
13
13
  from xync_client.Bybit.etype import ad
14
- from xync_client.Abc.xtype import PmEx, MapOfIdsList, GetAds
14
+ from xync_client.Abc.xtype import PmEx, MapOfIdsList, GetAdsReq
15
15
  from xync_client.loader import TORM
16
16
 
17
17
 
18
18
  class ExClient(BaseExClient): # Bybit client
19
- host = "api2.bybit.com"
20
19
  headers = df_hdrs # rewrite token for public methods
21
20
  agent: Agent = None
22
21
 
@@ -36,21 +35,33 @@ class ExClient(BaseExClient): # Bybit client
36
35
  }[status]
37
36
 
38
37
  async def _get_config(self):
39
- resp = await self._get("/fiat/p2p/config/initial")
40
- return resp["result"] # todo: tokens, pairs, ...
38
+ hdrs = {
39
+ "accept-language": "en",
40
+ "lang": "en",
41
+ "platform": "PC",
42
+ "risktoken": "dmVyMQ|==||==",
43
+ "traceparent": "00-4b51509490cb5b62e83d6e4f502a48be-24cdc3508360d087-01",
44
+ }
45
+ resp = await self._get("/x-api/fiat/p2p/config/initial", hdrs=hdrs)
46
+ return resp["result"]["symbols"] # todo: tokens, pairs, ...
41
47
 
42
48
  # 19: Список поддерживаемых валют тейкера
43
49
  async def curs(self) -> dict[int, xtype.CurEx]:
44
50
  config = await self._get_config()
45
51
  return {
46
- c["currencyId"]: xtype.CurEx(exid=c["currencyId"], ticker=c["currencyId"], scale=c["scale"])
47
- for c in config["currencies"]
52
+ c["currencyId"]: xtype.CurEx(
53
+ exid=c["currencyId"],
54
+ ticker=c["currencyId"],
55
+ scale=c["currency"]["scale"],
56
+ minimum=c["currencyMinQuote"],
57
+ )
58
+ for c in config
48
59
  }
49
60
 
50
61
  # 20: Список платежных методов
51
62
  async def pms(self, cur: models.Cur = None) -> dict[int | str, PmEx]:
52
63
  self.session.cookie_jar.update_cookies(await self._get_auth_cks())
53
- pms = await self._post("/fiat/otc/configuration/queryAllPaymentList/")
64
+ pms = await self._post("/x-api/fiat/otc/configuration/queryAllPaymentList/")
54
65
  self.session.cookie_jar.clear()
55
66
 
56
67
  pms = pms["result"]["paymentConfigVo"]
@@ -59,14 +70,14 @@ class ExClient(BaseExClient): # Bybit client
59
70
  # 21: Список платежных методов по каждой валюте
60
71
  async def cur_pms_map(self) -> MapOfIdsList:
61
72
  self.session.cookie_jar.update_cookies(await self._get_auth_cks())
62
- pms = await self._post("/fiat/otc/configuration/queryAllPaymentList/")
73
+ pms = await self._post("/x-api/fiat/otc/configuration/queryAllPaymentList/")
63
74
  return json.loads(pms["result"]["currencyPaymentIdMap"])
64
75
 
65
76
  # 22: Список торгуемых монет (с ограничениям по валютам, если есть)
66
77
  async def coins(self) -> dict[str, xtype.CoinEx]:
67
78
  config = await self._get_config()
68
79
  coinexs = {}
69
- for c in config["symbols"]:
80
+ for c in config:
70
81
  coinexs[c["tokenId"]] = xtype.CoinEx(
71
82
  exid=c["tokenId"], ticker=c["tokenId"], minimum=c["tokenMinQuote"], scale=c["token"]["scale"]
72
83
  )
@@ -76,7 +87,7 @@ class ExClient(BaseExClient): # Bybit client
76
87
  async def pairs(self) -> tuple[MapOfIdsList, MapOfIdsList]:
77
88
  config = await self._get_config()
78
89
  cc: dict[str, set[str]] = {}
79
- for c in config["symbols"]:
90
+ for c in config:
80
91
  cc[c["currencyId"]] = cc.get(c["currencyId"], set()) | {c["tokenId"]}
81
92
  return cc, cc
82
93
 
@@ -85,7 +96,7 @@ class ExClient(BaseExClient): # Bybit client
85
96
  if post_pmexs:
86
97
  req.payment = []
87
98
  req.size = str(min(1000, int(req.size) * 25))
88
- res = await self._post("/fiat/otc/item/online/", req.model_dump())
99
+ res = await self._post("/x-api/fiat/otc/item/online/", req.model_dump())
89
100
  ads = [ad.Ad(**_ad) for _ad in res["result"]["items"]]
90
101
  if post_pmexs:
91
102
  post_pmexids = {p.exid for p in post_pmexs}
@@ -103,10 +114,11 @@ async def main():
103
114
  bot: FileClient = FileClient(NET_TOKEN)
104
115
  # await bot.start()
105
116
  cl = ExClient(ex, bot)
117
+ await cl.set_curs()
106
118
  # await cl.set_pms()
107
119
  # await cl.set_coins()
108
120
  # 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)
121
+ x_ads_req = GetAdsReq(coin_id=1, cur_id=1, is_sell=True, pm_ids=[330, 366, 1853], amount=1000)
110
122
  _ads = await cl.ads(x_ads_req)
111
123
  # await bot.stop()
112
124
  await cl.close()