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