MCPcopy Create free account
hub / github.com/ccxt/ccxt / create_convert_trade

Method create_convert_trade

python/ccxt/phemex.py:4942–4987  ·  view source on GitHub ↗

convert from one currency to another https://phemex-docs.github.io/#convert :param str id: the id of the trade that you want to make :param str fromCode: the currency that you want to sell and convert from :param str toCode: the currency that you want to bu

(self, id: str, fromCode: str, toCode: str, amount: Num = None, params={})

Source from the content-addressed store, hash-verified

4940 return self.parse_conversion(data, fromCurrency, toCurrency)
4941
4942 def create_convert_trade(self, id: str, fromCode: str, toCode: str, amount: Num = None, params={}) -> Conversion:
4943 """
4944 convert from one currency to another
4945
4946 https://phemex-docs.github.io/#convert
4947
4948 :param str id: the id of the trade that you want to make
4949 :param str fromCode: the currency that you want to sell and convert from
4950 :param str toCode: the currency that you want to buy and convert into
4951 :param float [amount]: how much you want to trade in units of the from currency
4952 :param dict [params]: extra parameters specific to the exchange API endpoint
4953 :returns dict: a `conversion structure <https://docs.ccxt.com/?id=conversion-structure>`
4954 """
4955 self.load_markets()
4956 fromCurrency = self.currency(fromCode)
4957 toCurrency = self.currency(toCode)
4958 valueScale = self.safe_integer(fromCurrency, 'valueScale')
4959 request = {
4960 'code': id,
4961 'fromCurrency': fromCode,
4962 'toCurrency': toCode,
4963 }
4964 if amount is not None:
4965 request['fromAmountEv'] = self.to_en(amount, valueScale)
4966 response = self.privatePostAssetsConvert(self.extend(request, params))
4967 #
4968 # {
4969 # "code": 0,
4970 # "msg": "OK",
4971 # "data": {
4972 # "moveOp": 0,
4973 # "fromCurrency": "USDT",
4974 # "toCurrency": "BTC",
4975 # "fromAmountEv": 4000000000,
4976 # "toAmountEv": 41511,
4977 # "linkKey": "45c8ed8e-d3f4-472d-8262-e464e8c46247",
4978 # "status": 10
4979 # }
4980 # }
4981 #
4982 data = self.safe_dict(response, 'data', {})
4983 fromCurrencyId = self.safe_string(data, 'fromCurrency')
4984 fromResult = self.safe_currency(fromCurrencyId, fromCurrency)
4985 toCurrencyId = self.safe_string(data, 'toCurrency')
4986 to = self.safe_currency(toCurrencyId, toCurrency)
4987 return self.parse_conversion(data, fromResult, to)
4988
4989 def fetch_convert_trade_history(self, code: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Conversion]:
4990 """

Callers

nothing calls this directly

Calls 10

to_enMethod · 0.95
parse_conversionMethod · 0.95
safe_integerMethod · 0.80
safe_dictMethod · 0.80
safe_stringMethod · 0.80
safe_currencyMethod · 0.80
load_marketsMethod · 0.45
currencyMethod · 0.45
extendMethod · 0.45

Tested by

no test coverage detected