ccxt 4.4.61__py2.py3-none-any.whl → 4.4.63__py2.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.
- ccxt/__init__.py +1 -1
- ccxt/abstract/bitmart.py +5 -1
- ccxt/abstract/bybit.py +1 -0
- ccxt/async_support/__init__.py +1 -1
- ccxt/async_support/base/exchange.py +9 -7
- ccxt/async_support/bingx.py +6 -7
- ccxt/async_support/bitmart.py +155 -54
- ccxt/async_support/bybit.py +112 -5
- ccxt/async_support/gate.py +106 -145
- ccxt/async_support/kraken.py +2 -2
- ccxt/async_support/phemex.py +239 -17
- ccxt/async_support/tradeogre.py +3 -3
- ccxt/async_support/whitebit.py +5 -5
- ccxt/base/errors.py +0 -6
- ccxt/base/exchange.py +64 -32
- ccxt/bingx.py +6 -7
- ccxt/bitmart.py +155 -54
- ccxt/bybit.py +112 -5
- ccxt/gate.py +106 -145
- ccxt/kraken.py +2 -2
- ccxt/phemex.py +238 -17
- ccxt/pro/__init__.py +1 -1
- ccxt/pro/binance.py +25 -11
- ccxt/pro/bitmart.py +64 -53
- ccxt/pro/lbank.py +10 -4
- ccxt/pro/myokx.py +10 -1
- ccxt/test/tests_init.py +2 -1
- ccxt/tradeogre.py +3 -3
- ccxt/whitebit.py +5 -5
- {ccxt-4.4.61.dist-info → ccxt-4.4.63.dist-info}/METADATA +4 -4
- {ccxt-4.4.61.dist-info → ccxt-4.4.63.dist-info}/RECORD +34 -34
- {ccxt-4.4.61.dist-info → ccxt-4.4.63.dist-info}/LICENSE.txt +0 -0
- {ccxt-4.4.61.dist-info → ccxt-4.4.63.dist-info}/WHEEL +0 -0
- {ccxt-4.4.61.dist-info → ccxt-4.4.63.dist-info}/top_level.txt +0 -0
ccxt/phemex.py
CHANGED
@@ -7,7 +7,7 @@ from ccxt.base.exchange import Exchange
|
|
7
7
|
from ccxt.abstract.phemex import ImplicitAPI
|
8
8
|
import hashlib
|
9
9
|
import numbers
|
10
|
-
from ccxt.base.types import Any, Balances, Currencies, Currency, DepositAddress, Int, LeverageTier, LeverageTiers, MarginModification, Market, Num, Order, OrderBook, OrderSide, OrderType, Str, Strings, Ticker, Tickers, FundingRate, Trade, Transaction, TransferEntry
|
10
|
+
from ccxt.base.types import Any, Balances, Conversion, Currencies, Currency, DepositAddress, Int, LeverageTier, LeverageTiers, MarginModification, Market, Num, Order, OrderBook, OrderSide, OrderType, Str, Strings, Ticker, Tickers, FundingRate, Trade, Transaction, TransferEntry
|
11
11
|
from typing import List
|
12
12
|
from ccxt.base.errors import ExchangeError
|
13
13
|
from ccxt.base.errors import AuthenticationError
|
@@ -50,6 +50,7 @@ class phemex(Exchange, ImplicitAPI):
|
|
50
50
|
'cancelAllOrders': True,
|
51
51
|
'cancelOrder': True,
|
52
52
|
'closePosition': False,
|
53
|
+
'createConvertTrade': True,
|
53
54
|
'createOrder': True,
|
54
55
|
'createReduceOnlyOrder': True,
|
55
56
|
'createStopLimitOrder': True,
|
@@ -60,6 +61,9 @@ class phemex(Exchange, ImplicitAPI):
|
|
60
61
|
'fetchBorrowRateHistories': False,
|
61
62
|
'fetchBorrowRateHistory': False,
|
62
63
|
'fetchClosedOrders': True,
|
64
|
+
'fetchConvertQuote': True,
|
65
|
+
'fetchConvertTrade': False,
|
66
|
+
'fetchConvertTradeHistory': True,
|
63
67
|
'fetchCrossBorrowRate': False,
|
64
68
|
'fetchCrossBorrowRates': False,
|
65
69
|
'fetchCurrencies': True,
|
@@ -681,7 +685,8 @@ class phemex(Exchange, ImplicitAPI):
|
|
681
685
|
# }
|
682
686
|
#
|
683
687
|
id = self.safe_string(market, 'symbol')
|
684
|
-
|
688
|
+
contractUnderlyingAssets = self.safe_string(market, 'contractUnderlyingAssets')
|
689
|
+
baseId = self.safe_string(market, 'baseCurrency', contractUnderlyingAssets)
|
685
690
|
quoteId = self.safe_string(market, 'quoteCurrency')
|
686
691
|
settleId = self.safe_string(market, 'settleCurrency')
|
687
692
|
base = self.safe_currency_code(baseId)
|
@@ -691,6 +696,9 @@ class phemex(Exchange, ImplicitAPI):
|
|
691
696
|
inverse = False
|
692
697
|
if settleId != quoteId:
|
693
698
|
inverse = True
|
699
|
+
# some unhandled cases
|
700
|
+
if not ('baseCurrency' in market) and base == quote:
|
701
|
+
base = settle
|
694
702
|
priceScale = self.safe_integer(market, 'priceScale')
|
695
703
|
ratioScale = self.safe_integer(market, 'ratioScale')
|
696
704
|
valueScale = self.safe_integer(market, 'valueScale')
|
@@ -876,7 +884,7 @@ class phemex(Exchange, ImplicitAPI):
|
|
876
884
|
:param dict [params]: extra parameters specific to the exchange API endpoint
|
877
885
|
:returns dict[]: an array of objects representing market data
|
878
886
|
"""
|
879
|
-
|
887
|
+
v2ProductsPromise = self.v2GetPublicProducts(params)
|
880
888
|
#
|
881
889
|
# {
|
882
890
|
# "code":0,
|
@@ -1026,7 +1034,8 @@ class phemex(Exchange, ImplicitAPI):
|
|
1026
1034
|
# }
|
1027
1035
|
# }
|
1028
1036
|
#
|
1029
|
-
|
1037
|
+
v1ProductsPromise = self.v1GetExchangePublicProducts(params)
|
1038
|
+
v2Products, v1Products = [v2ProductsPromise, v1ProductsPromise]
|
1030
1039
|
v1ProductsData = self.safe_value(v1Products, 'data', [])
|
1031
1040
|
#
|
1032
1041
|
# {
|
@@ -1063,14 +1072,14 @@ class phemex(Exchange, ImplicitAPI):
|
|
1063
1072
|
# ]
|
1064
1073
|
# }
|
1065
1074
|
#
|
1066
|
-
v2ProductsData = self.
|
1067
|
-
products = self.
|
1068
|
-
perpetualProductsV2 = self.
|
1075
|
+
v2ProductsData = self.safe_dict(v2Products, 'data', {})
|
1076
|
+
products = self.safe_list(v2ProductsData, 'products', [])
|
1077
|
+
perpetualProductsV2 = self.safe_list(v2ProductsData, 'perpProductsV2', [])
|
1069
1078
|
products = self.array_concat(products, perpetualProductsV2)
|
1070
|
-
riskLimits = self.
|
1071
|
-
riskLimitsV2 = self.
|
1079
|
+
riskLimits = self.safe_list(v2ProductsData, 'riskLimits', [])
|
1080
|
+
riskLimitsV2 = self.safe_list(v2ProductsData, 'riskLimitsV2', [])
|
1072
1081
|
riskLimits = self.array_concat(riskLimits, riskLimitsV2)
|
1073
|
-
currencies = self.
|
1082
|
+
currencies = self.safe_list(v2ProductsData, 'currencies', [])
|
1074
1083
|
riskLimitsById = self.index_by(riskLimits, 'symbol')
|
1075
1084
|
v1ProductsById = self.index_by(v1ProductsData, 'symbol')
|
1076
1085
|
currenciesByCode = self.index_by(currencies, 'currency')
|
@@ -1078,16 +1087,16 @@ class phemex(Exchange, ImplicitAPI):
|
|
1078
1087
|
for i in range(0, len(products)):
|
1079
1088
|
market = products[i]
|
1080
1089
|
type = self.safe_string_lower(market, 'type')
|
1081
|
-
if (type == 'perpetual') or (type == 'perpetualv2') or (type == '
|
1090
|
+
if (type == 'perpetual') or (type == 'perpetualv2') or (type == 'perpetualpilot'):
|
1082
1091
|
id = self.safe_string(market, 'symbol')
|
1083
|
-
riskLimitValues = self.
|
1092
|
+
riskLimitValues = self.safe_dict(riskLimitsById, id, {})
|
1084
1093
|
market = self.extend(market, riskLimitValues)
|
1085
|
-
v1ProductsValues = self.
|
1094
|
+
v1ProductsValues = self.safe_dict(v1ProductsById, id, {})
|
1086
1095
|
market = self.extend(market, v1ProductsValues)
|
1087
1096
|
market = self.parse_swap_market(market)
|
1088
1097
|
else:
|
1089
1098
|
baseCurrency = self.safe_string(market, 'baseCurrency')
|
1090
|
-
currencyValues = self.
|
1099
|
+
currencyValues = self.safe_dict(currenciesByCode, baseCurrency, {})
|
1091
1100
|
valueScale = self.safe_string(currencyValues, 'valueScale', '8')
|
1092
1101
|
market = self.extend(market, {'valueScale': valueScale})
|
1093
1102
|
market = self.parse_spot_market(market)
|
@@ -1254,7 +1263,7 @@ class phemex(Exchange, ImplicitAPI):
|
|
1254
1263
|
precise.decimals = precise.decimals - scale
|
1255
1264
|
precise.reduce()
|
1256
1265
|
preciseString = str(precise)
|
1257
|
-
return self.
|
1266
|
+
return self.parse_to_numeric(preciseString)
|
1258
1267
|
|
1259
1268
|
def to_ev(self, amount, market: Market = None):
|
1260
1269
|
if (amount is None) or (market is None):
|
@@ -2547,7 +2556,6 @@ class phemex(Exchange, ImplicitAPI):
|
|
2547
2556
|
market = self.market(symbol)
|
2548
2557
|
requestSide = self.capitalize(side)
|
2549
2558
|
type = self.capitalize(type)
|
2550
|
-
reduceOnly = self.safe_bool(params, 'reduceOnly')
|
2551
2559
|
request: dict = {
|
2552
2560
|
# common
|
2553
2561
|
'symbol': market['id'],
|
@@ -2630,8 +2638,10 @@ class phemex(Exchange, ImplicitAPI):
|
|
2630
2638
|
posSide = self.safe_string_lower(params, 'posSide')
|
2631
2639
|
if posSide is None:
|
2632
2640
|
if hedged:
|
2641
|
+
reduceOnly = self.safe_bool(params, 'reduceOnly')
|
2633
2642
|
if reduceOnly:
|
2634
2643
|
side = 'sell' if (side == 'buy') else 'buy'
|
2644
|
+
params = self.omit(params, 'reduceOnly')
|
2635
2645
|
posSide = 'Long' if (side == 'buy') else 'Short'
|
2636
2646
|
else:
|
2637
2647
|
posSide = 'Merged'
|
@@ -2709,7 +2719,6 @@ class phemex(Exchange, ImplicitAPI):
|
|
2709
2719
|
else:
|
2710
2720
|
request['stopLossEp'] = self.to_ep(stopLossPrice, market)
|
2711
2721
|
params = self.omit(params, 'stopLossPrice')
|
2712
|
-
params = self.omit(params, 'reduceOnly')
|
2713
2722
|
response = None
|
2714
2723
|
if market['settle'] == 'USDT':
|
2715
2724
|
response = self.privatePostGOrders(self.extend(request, params))
|
@@ -4760,6 +4769,218 @@ class phemex(Exchange, ImplicitAPI):
|
|
4760
4769
|
'datetime': self.iso8601(timestamp),
|
4761
4770
|
}, market)
|
4762
4771
|
|
4772
|
+
def fetch_convert_quote(self, fromCode: str, toCode: str, amount: Num = None, params={}) -> Conversion:
|
4773
|
+
"""
|
4774
|
+
fetch a quote for converting from one currency to another
|
4775
|
+
|
4776
|
+
https://phemex-docs.github.io/#rfq-quote
|
4777
|
+
|
4778
|
+
:param str fromCode: the currency that you want to sell and convert from
|
4779
|
+
:param str toCode: the currency that you want to buy and convert into
|
4780
|
+
:param float amount: how much you want to trade in units of the from currency
|
4781
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
4782
|
+
:returns dict: a `conversion structure <https://docs.ccxt.com/#/?id=conversion-structure>`
|
4783
|
+
"""
|
4784
|
+
self.load_markets()
|
4785
|
+
fromCurrency = self.currency(fromCode)
|
4786
|
+
toCurrency = self.currency(toCode)
|
4787
|
+
valueScale = self.safe_integer(fromCurrency, 'valueScale')
|
4788
|
+
request: dict = {
|
4789
|
+
'fromCurrency': fromCode,
|
4790
|
+
'toCurrency': toCode,
|
4791
|
+
'fromAmountEv': self.to_en(amount, valueScale),
|
4792
|
+
}
|
4793
|
+
response = self.privateGetAssetsQuote(self.extend(request, params))
|
4794
|
+
#
|
4795
|
+
# {
|
4796
|
+
# "code": 0,
|
4797
|
+
# "msg": "OK",
|
4798
|
+
# "data": {
|
4799
|
+
# "code": "GIF...AAA",
|
4800
|
+
# "quoteArgs": {
|
4801
|
+
# "origin": 10,
|
4802
|
+
# "price": "0.00000939",
|
4803
|
+
# "proceeds": "0.00000000",
|
4804
|
+
# "ttlMs": 7000,
|
4805
|
+
# "expireAt": 1739875826009,
|
4806
|
+
# "requestAt": 1739875818009,
|
4807
|
+
# "quoteAt": 1739875816594
|
4808
|
+
# }
|
4809
|
+
# }
|
4810
|
+
# }
|
4811
|
+
#
|
4812
|
+
data = self.safe_dict(response, 'data', {})
|
4813
|
+
return self.parse_conversion(data, fromCurrency, toCurrency)
|
4814
|
+
|
4815
|
+
def create_convert_trade(self, id: str, fromCode: str, toCode: str, amount: Num = None, params={}) -> Conversion:
|
4816
|
+
"""
|
4817
|
+
convert from one currency to another
|
4818
|
+
|
4819
|
+
https://phemex-docs.github.io/#convert
|
4820
|
+
|
4821
|
+
:param str id: the id of the trade that you want to make
|
4822
|
+
:param str fromCode: the currency that you want to sell and convert from
|
4823
|
+
:param str toCode: the currency that you want to buy and convert into
|
4824
|
+
:param float [amount]: how much you want to trade in units of the from currency
|
4825
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
4826
|
+
:returns dict: a `conversion structure <https://docs.ccxt.com/#/?id=conversion-structure>`
|
4827
|
+
"""
|
4828
|
+
self.load_markets()
|
4829
|
+
fromCurrency = self.currency(fromCode)
|
4830
|
+
toCurrency = self.currency(toCode)
|
4831
|
+
valueScale = self.safe_integer(fromCurrency, 'valueScale')
|
4832
|
+
request: dict = {
|
4833
|
+
'code': id,
|
4834
|
+
'fromCurrency': fromCode,
|
4835
|
+
'toCurrency': toCode,
|
4836
|
+
}
|
4837
|
+
if amount is not None:
|
4838
|
+
request['fromAmountEv'] = self.to_en(amount, valueScale)
|
4839
|
+
response = self.privatePostAssetsConvert(self.extend(request, params))
|
4840
|
+
#
|
4841
|
+
# {
|
4842
|
+
# "code": 0,
|
4843
|
+
# "msg": "OK",
|
4844
|
+
# "data": {
|
4845
|
+
# "moveOp": 0,
|
4846
|
+
# "fromCurrency": "USDT",
|
4847
|
+
# "toCurrency": "BTC",
|
4848
|
+
# "fromAmountEv": 4000000000,
|
4849
|
+
# "toAmountEv": 41511,
|
4850
|
+
# "linkKey": "45c8ed8e-d3f4-472d-8262-e464e8c46247",
|
4851
|
+
# "status": 10
|
4852
|
+
# }
|
4853
|
+
# }
|
4854
|
+
#
|
4855
|
+
data = self.safe_dict(response, 'data', {})
|
4856
|
+
fromCurrencyId = self.safe_string(data, 'fromCurrency')
|
4857
|
+
fromResult = self.safe_currency(fromCurrencyId, fromCurrency)
|
4858
|
+
toCurrencyId = self.safe_string(data, 'toCurrency')
|
4859
|
+
to = self.safe_currency(toCurrencyId, toCurrency)
|
4860
|
+
return self.parse_conversion(data, fromResult, to)
|
4861
|
+
|
4862
|
+
def fetch_convert_trade_history(self, code: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Conversion]:
|
4863
|
+
"""
|
4864
|
+
fetch the users history of conversion trades
|
4865
|
+
|
4866
|
+
https://phemex-docs.github.io/#query-convert-history
|
4867
|
+
|
4868
|
+
:param str [code]: the unified currency code
|
4869
|
+
:param int [since]: the earliest time in ms to fetch conversions for
|
4870
|
+
:param int [limit]: the maximum number of conversion structures to retrieve, default 20, max 200
|
4871
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
4872
|
+
:param str [params.until]: the end time in ms
|
4873
|
+
:param str [params.fromCurrency]: the currency that you sold and converted from
|
4874
|
+
:param str [params.toCurrency]: the currency that you bought and converted into
|
4875
|
+
:returns dict[]: a list of `conversion structures <https://docs.ccxt.com/#/?id=conversion-structure>`
|
4876
|
+
"""
|
4877
|
+
self.load_markets()
|
4878
|
+
request: dict = {}
|
4879
|
+
if code is not None:
|
4880
|
+
request['fromCurrency'] = code
|
4881
|
+
if since is not None:
|
4882
|
+
request['startTime'] = since
|
4883
|
+
if limit is not None:
|
4884
|
+
request['limit'] = limit
|
4885
|
+
request, params = self.handle_until_option('endTime', request, params)
|
4886
|
+
response = self.privateGetAssetsConvert(self.extend(request, params))
|
4887
|
+
#
|
4888
|
+
# {
|
4889
|
+
# "code": 0,
|
4890
|
+
# "msg": "OK",
|
4891
|
+
# "data": {
|
4892
|
+
# "total": 2,
|
4893
|
+
# "rows": [
|
4894
|
+
# {
|
4895
|
+
# "linkKey": "45c8ed8e-d3f4-472d-8262-e464e8c46247",
|
4896
|
+
# "createTime": 1739882294000,
|
4897
|
+
# "fromCurrency": "USDT",
|
4898
|
+
# "toCurrency": "BTC",
|
4899
|
+
# "fromAmountEv": 4000000000,
|
4900
|
+
# "toAmountEv": 41511,
|
4901
|
+
# "status": 10,
|
4902
|
+
# "conversionRate": 1037,
|
4903
|
+
# "errorCode": 0
|
4904
|
+
# },
|
4905
|
+
# ]
|
4906
|
+
# }
|
4907
|
+
# }
|
4908
|
+
#
|
4909
|
+
data = self.safe_dict(response, 'data', {})
|
4910
|
+
rows = self.safe_list(data, 'rows', [])
|
4911
|
+
return self.parse_conversions(rows, code, 'fromCurrency', 'toCurrency', since, limit)
|
4912
|
+
|
4913
|
+
def parse_conversion(self, conversion: dict, fromCurrency: Currency = None, toCurrency: Currency = None) -> Conversion:
|
4914
|
+
#
|
4915
|
+
# fetchConvertQuote
|
4916
|
+
#
|
4917
|
+
# {
|
4918
|
+
# "code": "GIF...AAA",
|
4919
|
+
# "quoteArgs": {
|
4920
|
+
# "origin": 10,
|
4921
|
+
# "price": "0.00000939",
|
4922
|
+
# "proceeds": "0.00000000",
|
4923
|
+
# "ttlMs": 7000,
|
4924
|
+
# "expireAt": 1739875826009,
|
4925
|
+
# "requestAt": 1739875818009,
|
4926
|
+
# "quoteAt": 1739875816594
|
4927
|
+
# }
|
4928
|
+
# }
|
4929
|
+
#
|
4930
|
+
# createConvertTrade
|
4931
|
+
#
|
4932
|
+
# {
|
4933
|
+
# "moveOp": 0,
|
4934
|
+
# "fromCurrency": "USDT",
|
4935
|
+
# "toCurrency": "BTC",
|
4936
|
+
# "fromAmountEv": 4000000000,
|
4937
|
+
# "toAmountEv": 41511,
|
4938
|
+
# "linkKey": "45c8ed8e-d3f4-472d-8262-e464e8c46247",
|
4939
|
+
# "status": 10
|
4940
|
+
# }
|
4941
|
+
#
|
4942
|
+
# fetchConvertTradeHistory
|
4943
|
+
#
|
4944
|
+
# {
|
4945
|
+
# "linkKey": "45c8ed8e-d3f4-472d-8262-e464e8c46247",
|
4946
|
+
# "createTime": 1739882294000,
|
4947
|
+
# "fromCurrency": "USDT",
|
4948
|
+
# "toCurrency": "BTC",
|
4949
|
+
# "fromAmountEv": 4000000000,
|
4950
|
+
# "toAmountEv": 41511,
|
4951
|
+
# "status": 10,
|
4952
|
+
# "conversionRate": 1037,
|
4953
|
+
# "errorCode": 0
|
4954
|
+
# }
|
4955
|
+
#
|
4956
|
+
quoteArgs = self.safe_dict(conversion, 'quoteArgs', {})
|
4957
|
+
requestTime = self.safe_integer(quoteArgs, 'requestAt')
|
4958
|
+
timestamp = self.safe_integer(conversion, 'createTime', requestTime)
|
4959
|
+
fromCoin = self.safe_string(conversion, 'fromCurrency', self.safe_string(fromCurrency, 'code'))
|
4960
|
+
fromCode = self.safe_currency_code(fromCoin, fromCurrency)
|
4961
|
+
toCoin = self.safe_string(conversion, 'toCurrency', self.safe_string(toCurrency, 'code'))
|
4962
|
+
toCode = self.safe_currency_code(toCoin, toCurrency)
|
4963
|
+
fromValueScale = self.safe_integer(fromCurrency, 'valueScale')
|
4964
|
+
toValueScale = self.safe_integer(toCurrency, 'valueScale')
|
4965
|
+
fromAmount = self.from_en(self.safe_string(conversion, 'fromAmountEv'), fromValueScale)
|
4966
|
+
if fromAmount is None and quoteArgs is not None:
|
4967
|
+
fromAmount = self.from_en(self.safe_string(quoteArgs, 'origin'), fromValueScale)
|
4968
|
+
toAmount = self.from_en(self.safe_string(conversion, 'toAmountEv'), toValueScale)
|
4969
|
+
if toAmount is None and quoteArgs is not None:
|
4970
|
+
toAmount = self.from_en(self.safe_string(quoteArgs, 'proceeds'), toValueScale)
|
4971
|
+
return {
|
4972
|
+
'info': conversion,
|
4973
|
+
'timestamp': timestamp,
|
4974
|
+
'datetime': self.iso8601(timestamp),
|
4975
|
+
'id': self.safe_string(conversion, 'code'),
|
4976
|
+
'fromCurrency': fromCode,
|
4977
|
+
'fromAmount': self.parse_number(fromAmount),
|
4978
|
+
'toCurrency': toCode,
|
4979
|
+
'toAmount': self.parse_number(toAmount),
|
4980
|
+
'price': self.safe_number(quoteArgs, 'price'),
|
4981
|
+
'fee': None,
|
4982
|
+
}
|
4983
|
+
|
4763
4984
|
def handle_errors(self, httpCode: int, reason: str, url: str, method: str, headers: dict, body: str, response, requestHeaders, requestBody):
|
4764
4985
|
if response is None:
|
4765
4986
|
return None # fallback to default error handler
|
ccxt/pro/__init__.py
CHANGED
ccxt/pro/binance.py
CHANGED
@@ -78,6 +78,7 @@ class binance(ccxt.async_support.binance):
|
|
78
78
|
'ws-api': {
|
79
79
|
'spot': 'wss://testnet.binance.vision/ws-api/v3',
|
80
80
|
'future': 'wss://testnet.binancefuture.com/ws-fapi/v1',
|
81
|
+
'delivery': 'wss://testnet.binancefuture.com/ws-dapi/v1',
|
81
82
|
},
|
82
83
|
},
|
83
84
|
},
|
@@ -90,6 +91,7 @@ class binance(ccxt.async_support.binance):
|
|
90
91
|
'ws-api': {
|
91
92
|
'spot': 'wss://ws-api.binance.com:443/ws-api/v3',
|
92
93
|
'future': 'wss://ws-fapi.binance.com/ws-fapi/v1',
|
94
|
+
'delivery': 'wss://ws-dapi.binance.com/ws-dapi/v1',
|
93
95
|
},
|
94
96
|
'papi': 'wss://fstream.binance.com/pm/ws',
|
95
97
|
},
|
@@ -2334,6 +2336,7 @@ class binance(ccxt.async_support.binance):
|
|
2334
2336
|
|
2335
2337
|
https://developers.binance.com/docs/derivatives/usds-margined-futures/account/websocket-api/Futures-Account-Balance
|
2336
2338
|
https://developers.binance.com/docs/binance-spot-api-docs/web-socket-api#account-information-user_data
|
2339
|
+
https://developers.binance.com/docs/derivatives/coin-margined-futures/account/websocket-api
|
2337
2340
|
|
2338
2341
|
:param dict [params]: extra parameters specific to the exchange API endpoint
|
2339
2342
|
:param str|None [params.type]: 'future', 'delivery', 'savings', 'funding', or 'spot'
|
@@ -2344,7 +2347,7 @@ class binance(ccxt.async_support.binance):
|
|
2344
2347
|
"""
|
2345
2348
|
await self.load_markets()
|
2346
2349
|
type = self.get_market_type('fetchBalanceWs', None, params)
|
2347
|
-
if type != 'spot' and type != 'future':
|
2350
|
+
if type != 'spot' and type != 'future' and type != 'delivery':
|
2348
2351
|
raise BadRequest(self.id + ' fetchBalanceWs only supports spot or swap markets')
|
2349
2352
|
url = self.urls['api']['ws']['ws-api'][type]
|
2350
2353
|
requestId = self.request_id(url)
|
@@ -2450,6 +2453,7 @@ class binance(ccxt.async_support.binance):
|
|
2450
2453
|
fetch all open positions
|
2451
2454
|
|
2452
2455
|
https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/websocket-api/Position-Information
|
2456
|
+
https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/websocket-api/Position-Information
|
2453
2457
|
|
2454
2458
|
:param str[] [symbols]: list of unified market symbols
|
2455
2459
|
:param dict [params]: extra parameters specific to the exchange API endpoint
|
@@ -2458,15 +2462,20 @@ class binance(ccxt.async_support.binance):
|
|
2458
2462
|
:returns dict[]: a list of `position structure <https://docs.ccxt.com/#/?id=position-structure>`
|
2459
2463
|
"""
|
2460
2464
|
await self.load_markets()
|
2461
|
-
symbols = self.market_symbols(symbols, 'swap', True, True, True)
|
2462
|
-
url = self.urls['api']['ws']['ws-api']['future']
|
2463
|
-
requestId = self.request_id(url)
|
2464
|
-
messageHash = str(requestId)
|
2465
2465
|
payload: dict = {}
|
2466
|
+
market = None
|
2467
|
+
symbols = self.market_symbols(symbols, 'swap', True, True, True)
|
2466
2468
|
if symbols is not None:
|
2467
2469
|
symbolsLength = len(symbols)
|
2468
2470
|
if symbolsLength == 1:
|
2469
|
-
|
2471
|
+
market = self.market(symbols[0])
|
2472
|
+
payload['symbol'] = market['id']
|
2473
|
+
type = self.get_market_type('fetchPositionsWs', market, params)
|
2474
|
+
if type != 'future' and type != 'delivery':
|
2475
|
+
raise BadRequest(self.id + ' fetchPositionsWs only supports swap markets')
|
2476
|
+
url = self.urls['api']['ws']['ws-api'][type]
|
2477
|
+
requestId = self.request_id(url)
|
2478
|
+
messageHash = str(requestId)
|
2470
2479
|
returnRateLimits = False
|
2471
2480
|
returnRateLimits, params = self.handle_option_and_params(params, 'fetchPositionsWs', 'returnRateLimits', False)
|
2472
2481
|
payload['returnRateLimits'] = returnRateLimits
|
@@ -2675,6 +2684,7 @@ class binance(ccxt.async_support.binance):
|
|
2675
2684
|
|
2676
2685
|
https://developers.binance.com/docs/binance-spot-api-docs/web-socket-api#place-new-order-trade
|
2677
2686
|
https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/websocket-api/New-Order
|
2687
|
+
https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/websocket-api
|
2678
2688
|
|
2679
2689
|
:param str symbol: unified symbol of the market to create an order in
|
2680
2690
|
:param str type: 'market' or 'limit'
|
@@ -2689,7 +2699,7 @@ class binance(ccxt.async_support.binance):
|
|
2689
2699
|
await self.load_markets()
|
2690
2700
|
market = self.market(symbol)
|
2691
2701
|
marketType = self.get_market_type('createOrderWs', market, params)
|
2692
|
-
if marketType != 'spot' and marketType != 'future':
|
2702
|
+
if marketType != 'spot' and marketType != 'future' and marketType != 'delivery':
|
2693
2703
|
raise BadRequest(self.id + ' createOrderWs only supports spot or swap markets')
|
2694
2704
|
url = self.urls['api']['ws']['ws-api'][marketType]
|
2695
2705
|
requestId = self.request_id(url)
|
@@ -2819,6 +2829,7 @@ class binance(ccxt.async_support.binance):
|
|
2819
2829
|
|
2820
2830
|
https://developers.binance.com/docs/binance-spot-api-docs/web-socket-api#cancel-and-replace-order-trade
|
2821
2831
|
https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/websocket-api/Modify-Order
|
2832
|
+
https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/websocket-api/Modify-Order
|
2822
2833
|
|
2823
2834
|
:param str id: order id
|
2824
2835
|
:param str symbol: unified symbol of the market to create an order in
|
@@ -2832,22 +2843,23 @@ class binance(ccxt.async_support.binance):
|
|
2832
2843
|
await self.load_markets()
|
2833
2844
|
market = self.market(symbol)
|
2834
2845
|
marketType = self.get_market_type('editOrderWs', market, params)
|
2835
|
-
if marketType != 'spot' and marketType != 'future':
|
2846
|
+
if marketType != 'spot' and marketType != 'future' and marketType != 'delivery':
|
2836
2847
|
raise BadRequest(self.id + ' editOrderWs only supports spot or swap markets')
|
2837
2848
|
url = self.urls['api']['ws']['ws-api'][marketType]
|
2838
2849
|
requestId = self.request_id(url)
|
2839
2850
|
messageHash = str(requestId)
|
2851
|
+
isSwap = (marketType == 'future' or marketType == 'delivery')
|
2840
2852
|
payload = None
|
2841
2853
|
if marketType == 'spot':
|
2842
2854
|
payload = self.editSpotOrderRequest(id, symbol, type, side, amount, price, params)
|
2843
|
-
elif
|
2855
|
+
elif isSwap:
|
2844
2856
|
payload = self.editContractOrderRequest(id, symbol, type, side, amount, price, params)
|
2845
2857
|
returnRateLimits = False
|
2846
2858
|
returnRateLimits, params = self.handle_option_and_params(params, 'editOrderWs', 'returnRateLimits', False)
|
2847
2859
|
payload['returnRateLimits'] = returnRateLimits
|
2848
2860
|
message: dict = {
|
2849
2861
|
'id': messageHash,
|
2850
|
-
'method': 'order.modify' if (
|
2862
|
+
'method': 'order.modify' if (isSwap) else 'order.cancelReplace',
|
2851
2863
|
'params': self.sign_params(self.extend(payload, params)),
|
2852
2864
|
}
|
2853
2865
|
subscription: dict = {
|
@@ -2970,6 +2982,7 @@ class binance(ccxt.async_support.binance):
|
|
2970
2982
|
|
2971
2983
|
https://developers.binance.com/docs/binance-spot-api-docs/web-socket-api#cancel-order-trade
|
2972
2984
|
https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/websocket-api/Cancel-Order
|
2985
|
+
https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/websocket-api/Cancel-Order
|
2973
2986
|
|
2974
2987
|
:param str id: order id
|
2975
2988
|
:param str [symbol]: unified market symbol, default is None
|
@@ -3047,6 +3060,7 @@ class binance(ccxt.async_support.binance):
|
|
3047
3060
|
|
3048
3061
|
https://developers.binance.com/docs/binance-spot-api-docs/web-socket-api#query-order-user_data
|
3049
3062
|
https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/websocket-api/Query-Order
|
3063
|
+
https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/websocket-api/Query-Order
|
3050
3064
|
|
3051
3065
|
:param str id: order id
|
3052
3066
|
:param str [symbol]: unified symbol of the market the order was made in
|
@@ -3058,7 +3072,7 @@ class binance(ccxt.async_support.binance):
|
|
3058
3072
|
raise BadRequest(self.id + ' cancelOrderWs requires a symbol')
|
3059
3073
|
market = self.market(symbol)
|
3060
3074
|
type = self.get_market_type('fetchOrderWs', market, params)
|
3061
|
-
if type != 'spot' and type != 'future':
|
3075
|
+
if type != 'spot' and type != 'future' and type != 'delivery':
|
3062
3076
|
raise BadRequest(self.id + ' fetchOrderWs only supports spot or swap markets')
|
3063
3077
|
url = self.urls['api']['ws']['ws-api'][type]
|
3064
3078
|
requestId = self.request_id(url)
|