ccxt 4.3.12__py2.py3-none-any.whl → 4.3.14__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.
@@ -7,7 +7,7 @@ from ccxt.async_support.base.exchange import Exchange
7
7
  from ccxt.abstract.coinbase import ImplicitAPI
8
8
  import asyncio
9
9
  import hashlib
10
- from ccxt.base.types import Account, Balances, Currencies, Currency, Int, Market, MarketInterface, Num, Order, OrderBook, OrderSide, OrderType, Str, Strings, Ticker, Tickers, Trade, Transaction
10
+ from ccxt.base.types import Account, Balances, Conversion, Currencies, Currency, Int, Market, MarketInterface, Num, Order, OrderBook, OrderSide, OrderType, Str, Strings, Ticker, Tickers, Trade, Transaction
11
11
  from typing import List
12
12
  from ccxt.base.errors import ExchangeError
13
13
  from ccxt.base.errors import AuthenticationError
@@ -55,6 +55,7 @@ class coinbase(Exchange, ImplicitAPI):
55
55
  'cancelOrders': True,
56
56
  'closeAllPositions': False,
57
57
  'closePosition': True,
58
+ 'createConvertTrade': True,
58
59
  'createDepositAddress': True,
59
60
  'createLimitBuyOrder': True,
60
61
  'createLimitSellOrder': True,
@@ -78,6 +79,9 @@ class coinbase(Exchange, ImplicitAPI):
78
79
  'fetchBorrowRateHistory': False,
79
80
  'fetchCanceledOrders': True,
80
81
  'fetchClosedOrders': True,
82
+ 'fetchConvertQuote': True,
83
+ 'fetchConvertTrade': True,
84
+ 'fetchConvertTradeHistory': False,
81
85
  'fetchCrossBorrowRate': False,
82
86
  'fetchCrossBorrowRates': False,
83
87
  'fetchCurrencies': True,
@@ -3904,6 +3908,97 @@ class coinbase(Exchange, ImplicitAPI):
3904
3908
  data = self.safe_dict(response, 'data', {})
3905
3909
  return self.parse_transaction(data)
3906
3910
 
3911
+ async def fetch_convert_quote(self, fromCode: str, toCode: str, amount: Num = None, params={}) -> Conversion:
3912
+ """
3913
+ fetch a quote for converting from one currency to another
3914
+ :see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_createconvertquote
3915
+ :param str fromCode: the currency that you want to sell and convert from
3916
+ :param str toCode: the currency that you want to buy and convert into
3917
+ :param float [amount]: how much you want to trade in units of the from currency
3918
+ :param dict [params]: extra parameters specific to the exchange API endpoint
3919
+ :param dict [params.trade_incentive_metadata]: an object to fill in user incentive data
3920
+ :param str [params.trade_incentive_metadata.user_incentive_id]: the id of the incentive
3921
+ :param str [params.trade_incentive_metadata.code_val]: the code value of the incentive
3922
+ :returns dict: a `conversion structure <https://docs.ccxt.com/#/?id=conversion-structure>`
3923
+ """
3924
+ await self.load_markets()
3925
+ request = {
3926
+ 'from_account': fromCode,
3927
+ 'to_account': toCode,
3928
+ 'amount': self.number_to_string(amount),
3929
+ }
3930
+ response = await self.v3PrivatePostBrokerageConvertQuote(self.extend(request, params))
3931
+ data = self.safe_dict(response, 'trade', {})
3932
+ return self.parse_conversion(data)
3933
+
3934
+ async def create_convert_trade(self, id: str, fromCode: str, toCode: str, amount: Num = None, params={}) -> Conversion:
3935
+ """
3936
+ convert from one currency to another
3937
+ :see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_commitconverttrade
3938
+ :param str id: the id of the trade that you want to make
3939
+ :param str fromCode: the currency that you want to sell and convert from
3940
+ :param str toCode: the currency that you want to buy and convert into
3941
+ :param float [amount]: how much you want to trade in units of the from currency
3942
+ :param dict [params]: extra parameters specific to the exchange API endpoint
3943
+ :returns dict: a `conversion structure <https://docs.ccxt.com/#/?id=conversion-structure>`
3944
+ """
3945
+ await self.load_markets()
3946
+ request = {
3947
+ 'trade_id': id,
3948
+ 'from_account': fromCode,
3949
+ 'to_account': toCode,
3950
+ }
3951
+ response = await self.v3PrivatePostBrokerageConvertTradeTradeId(self.extend(request, params))
3952
+ data = self.safe_dict(response, 'trade', {})
3953
+ return self.parse_conversion(data)
3954
+
3955
+ async def fetch_convert_trade(self, id: str, code: Str = None, params={}) -> Conversion:
3956
+ """
3957
+ fetch the data for a conversion trade
3958
+ :see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_getconverttrade
3959
+ :param str id: the id of the trade that you want to commit
3960
+ :param str code: the unified currency code that was converted from
3961
+ :param dict [params]: extra parameters specific to the exchange API endpoint
3962
+ :param strng params['toCode']: the unified currency code that was converted into
3963
+ :returns dict: a `conversion structure <https://docs.ccxt.com/#/?id=conversion-structure>`
3964
+ """
3965
+ await self.load_markets()
3966
+ if code is None:
3967
+ raise ArgumentsRequired(self.id + ' fetchConvertTrade() requires a code argument')
3968
+ toCode = self.safe_string(params, 'toCode')
3969
+ if toCode is None:
3970
+ raise ArgumentsRequired(self.id + ' fetchConvertTrade() requires a toCode parameter')
3971
+ params = self.omit(params, 'toCode')
3972
+ request = {
3973
+ 'trade_id': id,
3974
+ 'from_account': code,
3975
+ 'to_account': toCode,
3976
+ }
3977
+ response = await self.v3PrivateGetBrokerageConvertTradeTradeId(self.extend(request, params))
3978
+ data = self.safe_dict(response, 'trade', {})
3979
+ return self.parse_conversion(data)
3980
+
3981
+ def parse_conversion(self, conversion, fromCurrency: Currency = None, toCurrency: Currency = None) -> Conversion:
3982
+ fromCoin = self.safe_string(conversion, 'source_currency')
3983
+ fromCode = self.safe_currency_code(fromCoin, fromCurrency)
3984
+ to = self.safe_string(conversion, 'target_currency')
3985
+ toCode = self.safe_currency_code(to, toCurrency)
3986
+ fromAmountStructure = self.safe_dict(conversion, 'user_entered_amount')
3987
+ feeStructure = self.safe_dict(conversion, 'total_fee')
3988
+ feeAmountStructure = self.safe_dict(feeStructure, 'amount')
3989
+ return {
3990
+ 'info': conversion,
3991
+ 'timestamp': None,
3992
+ 'datetime': None,
3993
+ 'id': self.safe_string(conversion, 'id'),
3994
+ 'fromCurrency': fromCode,
3995
+ 'fromAmount': self.safe_number(fromAmountStructure, 'value'),
3996
+ 'toCurrency': toCode,
3997
+ 'toAmount': None,
3998
+ 'price': None,
3999
+ 'fee': self.safe_number(feeAmountStructure, 'value'),
4000
+ }
4001
+
3907
4002
  async def close_position(self, symbol: str, side: OrderSide = None, params={}) -> Order:
3908
4003
  """
3909
4004
  *futures only* closes open positions for a market