openfund-core 1.0.9__py3-none-any.whl → 1.0.10__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.
- core/Exchange.py +28 -77
- {openfund_core-1.0.9.dist-info → openfund_core-1.0.10.dist-info}/METADATA +1 -1
- {openfund_core-1.0.9.dist-info → openfund_core-1.0.10.dist-info}/RECORD +5 -5
- {openfund_core-1.0.9.dist-info → openfund_core-1.0.10.dist-info}/WHEEL +1 -1
- {openfund_core-1.0.9.dist-info → openfund_core-1.0.10.dist-info}/entry_points.txt +0 -0
core/Exchange.py
CHANGED
@@ -24,8 +24,6 @@ class Exchange:
|
|
24
24
|
self.exchange = getattr(ccxt, exchangeKey)(config)
|
25
25
|
self.logger = logging.getLogger(__name__)
|
26
26
|
|
27
|
-
|
28
|
-
|
29
27
|
def getMarket(self, symbol:str):
|
30
28
|
# 配置交易对
|
31
29
|
self.exchange.load_markets()
|
@@ -61,9 +59,7 @@ class Exchange:
|
|
61
59
|
|
62
60
|
def amount_to_precision(self,symbol, contract_size):
|
63
61
|
return self.exchange.amount_to_precision(symbol, contract_size)
|
64
|
-
|
65
|
-
|
66
|
-
|
62
|
+
|
67
63
|
def set_leverage(self,symbol, leverage, mgnMode='isolated',posSide=None):
|
68
64
|
try:
|
69
65
|
# 设置杠杆
|
@@ -166,8 +162,7 @@ class Exchange:
|
|
166
162
|
else:
|
167
163
|
self.logger.warning(f"{symbol} 平仓失败,正在进行第{retry_count}次重试: {str(e)}")
|
168
164
|
time.sleep(0.1) # 重试前等待0.1秒
|
169
|
-
|
170
|
-
|
165
|
+
|
171
166
|
def cancel_all_orders(self, symbol):
|
172
167
|
max_retries = 3
|
173
168
|
retry_count = 0
|
@@ -257,6 +252,7 @@ class Exchange:
|
|
257
252
|
|
258
253
|
self.logger.warning(f"{symbol} : Error cancelling order {algo_ids}: {str(e)}")
|
259
254
|
time.sleep(0.1) # 重试前等待0.1秒
|
255
|
+
|
260
256
|
def place_algo_orders(self, symbol, position, price: Decimal, order_type, sl_or_tp='SL', params={}) -> bool:
|
261
257
|
"""
|
262
258
|
下单
|
@@ -323,47 +319,23 @@ class Exchange:
|
|
323
319
|
self.logger.info(f"{symbol} : Pre Algo Order placed: {order} ")
|
324
320
|
while retry_count < max_retries:
|
325
321
|
try:
|
322
|
+
# 创建订单
|
323
|
+
order_result = self.exchange.create_order(**order)
|
324
|
+
self.logger.info(f"{symbol} : --------- ++ Algo Order placed done. --------")
|
325
|
+
return True
|
326
326
|
|
327
|
-
|
328
|
-
**order
|
329
|
-
# symbol=symbol,
|
330
|
-
# type=order_type,
|
331
|
-
# price=adjusted_price,
|
332
|
-
# side=orderSide,
|
333
|
-
# amount=amount,
|
334
|
-
# params=order_params
|
335
|
-
)
|
336
|
-
|
337
|
-
break
|
338
|
-
|
339
|
-
except ccxt.NetworkError as e:
|
340
|
-
# 处理网络相关错误
|
341
|
-
retry_count += 1
|
342
|
-
self.logger.warning(f"{symbol} : 设置止盈止损时发生网络错误,正在进行第{retry_count}次重试: {str(e)}")
|
343
|
-
time.sleep(0.1) # 重试前等待1秒
|
344
|
-
continue
|
345
|
-
except ccxt.ExchangeError as e:
|
346
|
-
# 处理交易所API相关错误
|
327
|
+
except (ccxt.NetworkError, ccxt.ExchangeError, Exception) as e:
|
347
328
|
retry_count += 1
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
329
|
+
error_type = "网络" if isinstance(e, ccxt.NetworkError) else "交易所" if isinstance(e, ccxt.ExchangeError) else "未知"
|
330
|
+
self.logger.warning(f"{symbol} : 设置止盈止损单时发生{error_type}错误,正在进行第{retry_count}次重试: {str(e)}")
|
331
|
+
|
332
|
+
if retry_count == max_retries:
|
333
|
+
error_message = f"!! {symbol}: 设置止盈止损单失败(重试{max_retries}次): {str(e)}"
|
334
|
+
self.logger.error(error_message)
|
335
|
+
raise Exception(error_message)
|
336
|
+
|
355
337
|
time.sleep(0.1)
|
356
|
-
continue
|
357
|
-
|
358
|
-
if retry_count >= max_retries:
|
359
|
-
# 重试次数用完仍未成功设置止损单
|
360
|
-
error_message = f"!! {symbol}: 设置止盈止损单时重试次数用完仍未成功设置成功。 "
|
361
|
-
self.logger.error(error_message)
|
362
|
-
raise Exception(error_message)
|
363
|
-
self.logger.debug(f"{symbol} : --------- ++ Order placed done. --------")
|
364
|
-
return True
|
365
338
|
|
366
|
-
|
367
339
|
def place_order(self, symbol, price: Decimal, amount_usdt, side, leverage=20, order_type='limit', params={}) -> bool:
|
368
340
|
"""
|
369
341
|
下单
|
@@ -418,40 +390,18 @@ class Exchange:
|
|
418
390
|
while retry_count < max_retries:
|
419
391
|
try:
|
420
392
|
# 使用ccxt创建订单
|
421
|
-
order_result = self.exchange.create_order(
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
# side=side,
|
426
|
-
# amount=amount_usdt,
|
427
|
-
# price=float(adjusted_price),
|
428
|
-
# params=params
|
429
|
-
)
|
430
|
-
except ccxt.NetworkError as e:
|
431
|
-
# 处理网络相关错误
|
432
|
-
retry_count += 1
|
433
|
-
self.logger.warning(f"{symbol} : 下单时发生网络错误,正在进行第{retry_count}次重试: {str(e)}")
|
434
|
-
time.sleep(0.1) # 重试前等待1秒
|
435
|
-
continue
|
436
|
-
except ccxt.ExchangeError as e:
|
437
|
-
# 处理交易所API相关错误
|
438
|
-
retry_count += 1
|
439
|
-
self.logger.warning(f"{symbol} : 下单时发生交易所错误,正在进行第{retry_count}次重试: {str(e)}")
|
440
|
-
time.sleep(0.1)
|
441
|
-
continue
|
442
|
-
except Exception as e:
|
443
|
-
# 处理其他未预期的错误
|
393
|
+
order_result = self.exchange.create_order(**order)
|
394
|
+
self.logger.info(f"{symbol} : --------- ++ Order placed done. --------")
|
395
|
+
return True
|
396
|
+
except (ccxt.NetworkError, ccxt.ExchangeError, Exception) as e:
|
444
397
|
retry_count += 1
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
raise Exception(error_message)
|
453
|
-
self.logger.debug(f"{symbol} : --------- ++ Order placed done. --------")
|
454
|
-
return True
|
398
|
+
error_type = "网络" if isinstance(e, ccxt.NetworkError) else "交易所" if isinstance(e, ccxt.ExchangeError) else "未知"
|
399
|
+
self.logger.warning(f"{symbol} : 下单时发生{error_type}错误,正在进行第{retry_count}次重试: {str(e)}")
|
400
|
+
if retry_count == max_retries:
|
401
|
+
error_message = f"!! {symbol}: 下单时重试{max_retries}次后仍未成功:{str(e)}"
|
402
|
+
self.logger.error(error_message)
|
403
|
+
raise Exception(error_message)
|
404
|
+
time.sleep(1)
|
455
405
|
|
456
406
|
def fetch_position(self, symbol):
|
457
407
|
"""_summary_
|
@@ -523,6 +473,7 @@ class Exchange:
|
|
523
473
|
|
524
474
|
self.logger.warning(f"{symbol} : Error fetching open orders: {str(e)}")
|
525
475
|
time.sleep(0.1) # 重试前等待0.1秒
|
476
|
+
|
526
477
|
def get_market_price(self, symbol) -> Decimal:
|
527
478
|
"""
|
528
479
|
获取最新价格
|
@@ -1,4 +1,4 @@
|
|
1
|
-
core/Exchange.py,sha256=
|
1
|
+
core/Exchange.py,sha256=ifZiziRKJP9-9WBCuHa2HLu4mmGIB-V6J8WirZgkCOQ,21502
|
2
2
|
core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
3
3
|
core/main.py,sha256=E-VZzem7-0_J6EmOo9blLPokc5MRcgjqCbqAvbkPnWI,630
|
4
4
|
core/smc/SMCBase.py,sha256=epRC5bWDymx7ZMIhn_bVJRjvBHItt6BCnYASO2fhSDg,4302
|
@@ -9,7 +9,7 @@ core/smc/SMCPDArray.py,sha256=IjBdpQuAQd3t_nTovEzeiml-EQ-KeLNCmitFxadYxMM,5030
|
|
9
9
|
core/smc/SMCStruct.py,sha256=dW3iLKNV78pDbcpyL7SjLVUyAsc1DrO8gSCJkGbrKO4,12339
|
10
10
|
core/smc/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
11
11
|
core/utils/OPTools.py,sha256=tJ1Jq_Caab6OWaX12xn4_g9ryf98Rm5I1zsJEEU8NIQ,1002
|
12
|
-
openfund_core-1.0.
|
13
|
-
openfund_core-1.0.
|
14
|
-
openfund_core-1.0.
|
15
|
-
openfund_core-1.0.
|
12
|
+
openfund_core-1.0.10.dist-info/METADATA,sha256=zCl4CuqeksPfr7usyT0LvLaI8ZMVs4Zlib0Q1oyokYw,1954
|
13
|
+
openfund_core-1.0.10.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
14
|
+
openfund_core-1.0.10.dist-info/entry_points.txt,sha256=g8GUw3cyKFtcG5VWs8geU5VBLqiWr59GElqERuH8zD0,48
|
15
|
+
openfund_core-1.0.10.dist-info/RECORD,,
|
File without changes
|