
    iG_                         d dl mZ d dlmZ d dlZd dlmZmZmZm	Z	m
Z
mZmZmZmZmZmZmZ d dlmZ d dlmZ d dlmZ d dlmZ  G d	 d
ee          ZdS )    )Exchange)ImplicitAPIN)BalancesCurrencyIntMarketNum	OrderBook	OrderSide	OrderTypeStrTickerTradeTransferEntry)List)ExchangeError)	TICK_SIZE)Precisec                       e Zd Z fdZdefdZi fdefdZdi fdedede	fdZ
d&d	edefd
Zi fdedefdZd&d	edefdZddi fdedededee         fdZi fdefdZi fdefdZdi fdee         fdZd&defdZdi fdededededef
dZdi fdedefdZi fdededededef
dZ d&defd Z!d! Z"d"d#i ddfd$Z#d% Z$ xZ%S )'paymiumc                    |                      t          t          |                                           ddddgddi ddd	dd
d dddddddddddddddddddddddddddddddddddddd	dddiddg d d!d"d#g d$ig d%g d&g d'd(d)d*|                     d+d*d,d-d.d+d	dd/          id0|                     d1          |                     d2          d3it          d4          S )5Nr   PaymiumFREUi  v1CORSTspotmarginswapFfutureoptioncancelOrdercreateDepositAddresscreateOrderfetchBalancefetchDepositAddressfetchDepositAddressesfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchIndexOHLCV)	fetchMarkOHLCVfetchOpenInterestHistoryfetchOrderBookfetchPremiumIndexOHLCVfetchTickerfetchTradesfetchTradingFeefetchTradingFeestransferzdhttps://user-images.githubusercontent.com/51840849/87153930-f0f02200-c2c0-11ea-9c0a-40337375ae89.jpgrestzhttps://paymium.com/apizhttps://www.paymium.comz&https://www.paymium.com/page/help/fees)z,https://github.com/Paymium/api-documentationz'https://www.paymium.com/page/developersz,https://paymium.github.io/api-documentation/zBhttps://www.paymium.com/page/sign-up?referral=eDAzPoRQFMvaAB8sf-qj)logoapiwwwfeesdocreferralget)	countries
currencieszdata/{currency}/tickerzdata/{currency}/tradeszdata/{currency}/depthzbitcoin_charts/{id}/tradeszbitcoin_charts/{id}/depth)useruser/addresseszuser/addresses/{address}user/ordersuser/orders/{uuid}user/price_alertszmerchant/get_payment/{uuid})rA   rB   zuser/withdrawalszuser/email_transferszuser/payment_requestsrD   zmerchant/create_payment)rC   zuser/orders/{uuid}/cancelzuser/price_alerts/{id})r=   postdelete)publicprivatezBTC/EUReurBTCEURbtc)idsymbolbasequotebaseIdquoteIdtyper   tradingz-0.001z0.005)makertaker)rM   namer>   	rateLimitversionhasurlsr8   marketsr:   precisionMode)deep_extendsuperr   describesafe_market_structureparse_numberr   )self	__class__s    `/var/www/html/crypto-bot/backend/venv/lib/python3.11/site-packages/ccxt/async_support/paymium.pyr`   zpaymium.describe   so   gt 4 4 = = ? ? $ 	
 % % t ' t  &t ( &u #E *5  $U!" "5#$ #(,1"&*/###($) 5  : 5 1@  
 a      
      ' % %N 455Uiafqv  CH  UZ  dj  tx  7y  7y  z  z !..x88!..w77  '`B
 `B
 ` ` `	    returnc                    d|i}t          | j                                                  }t          dt	          |                    D ]}||         }|                     |          }|d         }d|z   }||v rP|                                 }	d|z   }
|                     ||          |	d<   |                     ||
          |	d<   |	||<   |                     |          S )Ninfor   rM   balance_locked_freeused)	listr?   keysrangelencurrencyaccountsafe_stringsafe_balance)rc   responseresultr?   icoderr   
currencyIdrl   rs   rm   s              re   parse_balancezpaymium.parse_balanceu   s    (#$/..0011
q#j//** 
	' 
	'Aa=D}}T**H!$J
*Dx,,.. :-"&"2"28T"B"B"&"2"28T"B"B&t  (((rf   c                    K   |                                   d{V  |                     |           d{V }|                     |          S )av  
        query for balance and get the amount of funds available for trading or funds locked in orders
        :see: https://paymium.github.io/api-documentation/#tag/User/paths/~1user/get
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
        N)load_marketsprivateGetUserr{   )rc   paramsrv   s      re   fetch_balancezpaymium.fetch_balance   se       !!!!!!!!!,,V44444444!!(+++rf   NrN   limitc           	        K   |                                   d{V  |                     |          }d|d         i}|                     |                     ||                     d{V }|                     ||d         ddddd          S )	af  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
        :see: https://paymium.github.io/api-documentation/#tag/Public-data/paths/~1data~1%7Bcurrency%7D~1depth/get
        :param str symbol: unified symbol of the market to fetch the order book for
        :param int [limit]: the maximum amount of order book entries to return
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
        Nrr   rM   rN   bidsaskspriceamount)r}   marketpublicGetDataCurrencyDepthextendparse_order_book)rc   rN   r   r   r   requestrv   s          re   fetch_order_bookzpaymium.fetch_order_book   s       !!!!!!!!!V$$t
 88Wf9U9UVVVVVVVV$$Xvh/?vvW^`hiiirf   r   c                    |                      d |          }|                     |d          }|                     |d          }|                     |d          }t          j        ||          }|                     |d          }|                     i d|d|d|                     |          d|                     |d          d	|                     |d	          d
|                     |d
          dd d|                     |d          dd d|d|                     |d          d|d|dd dd d|                     |d          dd |||d|          S )Natvwapvolumer   rN   	timestampdatetimehighlowbid	bidVolumeask	askVolumeopencloselastpreviousClosechange
percentage	variationaverage)
baseVolumequoteVolumeri   )safe_symbolsafe_timestamprt   r   
string_mulsafe_tickeriso8601)	rc   tickerr   rN   r   r   r   r   r   s	            re   parse_tickerzpaymium.parse_ticker   s   & !!$//''55	//%%fh77
(T::00 !
f!
!
 Y//!
 D$$VV44	!

 4##FE22!
 4##FE22!
 !
 4##FE22!
 !
 D!
 D$$VV44!
 T!
 D!
 T!
 d!
  $**6;??!!
" t#!
$ %&)!
 !
 !
* +  	rf   c                   K   |                                   d{V  |                     |          }d|d         i}|                     |                     ||                     d{V }|                     ||          S )a  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
        :see: https://paymium.github.io/api-documentation/#tag/Public-data/paths/~1data~1%7Bcurrency%7D~1ticker/get
        :param str symbol: unified symbol of the market to fetch the ticker for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
        Nrr   rM   )r}   r   publicGetDataCurrencyTickerr   r   )rc   rN   r   r   r   r   s         re   fetch_tickerzpaymium.fetch_ticker   s       !!!!!!!!!V$$t
 77GV8T8TUUUUUUUU&   000rf   c                    |                      |d          }|                     |d          }|                     d |          }|                     |d          }|                     |d          }d|d                                         z   }|                     ||          }|                     ||d ||                     |          |d         d |d ||d d d|          S )	Ncreated_at_intuuidsider   traded_rO   rN   )ri   rM   orderr   r   rN   rS   r   takerOrMakerr   r   costfee)r   rt   safe_marketlower
safe_trader   )	rc   trader   r   rM   r   r   amountFieldr   s	            re   parse_tradezpaymium.parse_trade   s    ''/?@@	eV,,!!$//v..  00&."6"6"8"88!!%55"Y//X&  
  
   	rf   sincec                   K   |                                   d{V  |                     |          }d|d         i}|                     |                     ||                     d{V }|                     ||||          S )aQ  
        get the list of most recent trades for a particular symbol
        :see: https://paymium.github.io/api-documentation/#tag/Public-data/paths/~1data~1%7Bcurrency%7D~1trades/get
        :param str symbol: unified symbol of the market to fetch trades for
        :param int [since]: timestamp in ms of the earliest trade to fetch
        :param int [limit]: the maximum amount of trades to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
        Nrr   rM   )r}   r   publicGetDataCurrencyTradesr   parse_trades)rc   rN   r   r   r   r   r   rv   s           re   fetch_tradeszpaymium.fetch_trades  s       !!!!!!!!!V$$t
 99$++gv:V:VWWWWWWWW  65%@@@rf   ry   c                    K   |                                   d{V  |                     |           d{V }|                     |          S )a  
        create a currency deposit address
        :see: https://paymium.github.io/api-documentation/#tag/User/paths/~1user~1addresses/post
        :param str code: unified currency code of the currency for the deposit address
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
        N)r}   privatePostUserAddressesparse_deposit_address)rc   ry   r   rv   s       re   create_deposit_addresszpaymium.create_deposit_address  sg       !!!!!!!!!66v>>>>>>>> ))(333rf   c                    K   |                                   d{V  d|i}|                     |                     ||                     d{V }|                     |          S )a  
        fetch the deposit address for a currency associated with self account
        :see: https://paymium.github.io/api-documentation/#tag/User/paths/~1user~1addresses~1%7Baddress%7D/get
        :param str code: unified currency code
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
        Naddress)r}   privateGetUserAddressesAddressr   r   )rc   ry   r   r   rv   s        re   fetch_deposit_addresszpaymium.fetch_deposit_address1  s       !!!!!!!!!t
 <<T[[RX=Y=YZZZZZZZZ ))(333rf   codesc                    K   |                                   d{V  |                     |           d{V }|                     ||          S )a  
        fetch deposit addresses for multiple currencies and chain types
        :see: https://paymium.github.io/api-documentation/#tag/User/paths/~1user~1addresses/get
        :param str[]|None codes: list of unified currency codes, default is None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a list of `address structures <https://docs.ccxt.com/#/?id=address-structure>`
        N)r}   privateGetUserAddressesparse_deposit_addresses)rc   r   r   rv   s       re   fetch_deposit_addresseszpaymium.fetch_deposit_addressesH  si       !!!!!!!!!55f======== ++He<<<rf   rr   c                     |                      |d          }|                      |d          }||                     ||          |d d dS )Nr   rr   )ri   rr   r   tagnetwork)rt   safe_currency_code)rc   depositAddressrr   r   rz   s        re   r   zpaymium.parse_deposit_address^  s\     "">9==%%njAA
"//
HEE
 
 	
rf   rS   r   r   r   c                 \  K   |                                   d{V  |                     |          }|                     |          dz   |d         ||d}|dk    r||d<   |                     |                     ||                     d{V }	|                     |	|	d         d|          S )	a  
        create a trade order
        :see: https://paymium.github.io/api-documentation/#tag/Order/paths/~1user~1orders/post
        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit'
        :param str side: 'buy' or 'sell'
        :param float amount: how much of currency you want to trade in units of base currency
        :param float [price]: the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        NOrderrM   )rS   rr   	directionr   r   r   r   )ri   rM   )r}   r   
capitalizeprivatePostUserOrdersr   
safe_order)
rc   rN   rS   r   r   r   r   r   r   rv   s
             re   create_orderzpaymium.create_orderq  s       !!!!!!!!!V$$OOD))G3t	
 
 8$GG33DKK4P4PQQQQQQQQ6" 
  
   	rf   rM   c                 l   K   d|i}|                      |                     ||                     d{V S )a  
        cancels an open order
        :see: https://paymium.github.io/api-documentation/#tag/Order/paths/~1user~1orders~1%7Buuid%7D/delete
        :see: https://paymium.github.io/api-documentation/#tag/Order/paths/~1user~1orders~1%7Buuid%7D~1cancel/delete
        :param str id: order id
        :param str symbol: not used by paymium cancelOrder()
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r   N)!privateDeleteUserOrdersUuidCancelr   )rc   rM   rN   r   r   s        re   cancel_orderzpaymium.cancel_order  sK       B
 ;;DKKQW<X<XYYYYYYYYYrf   fromAccount	toAccountc                   K   |                                   d{V  |                     |          }|                    d          dk     rt          | j        dz             |dk    r|dk    rt          | j        dz             |d         |                     ||          |d	}|                     |                     ||                     d{V }|                     ||          S )
a>  
        transfer currency internally between wallets on the same account
        :see: https://paymium.github.io/api-documentation/#tag/Transfer/paths/~1user~1email_transfers/post
        :param str code: unified currency code
        :param float amount: amount to transfer
        :param str fromAccount: account to transfer from
        :param str toAccount: account to transfer to
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `transfer structure <https://docs.ccxt.com/#/?id=transfer-structure>`
        N@r   z5 transfer() only allows transfers to an email addressrJ   rK   z" transfer() only allows BTC or EURrM   )rr   r   email)	r}   rr   findr   rM   currency_to_precisionprivatePostUserEmailTransfersr   parse_transfer)	rc   ry   r   r   r   r   rr   r   rv   s	            re   r5   zpaymium.transfer  s	      !!!!!!!!!==&&>>#""*a abbb5==TU]]*N NOOO 00v>>
 
 ;;DKKQW<X<XYYYYYYYYB ""8X666rf   c                    |                      |d          }|                      |d          }|                     |          }|                     |d          }|                     |di           }|                      |d          }||                      |d          ||                     |          |                     ||          |                     |d          d |                      |d          |                     |          d		S )
Nrr   
updated_ataccount_operationsr   stater   r   r   )	ri   rM   r   r   rr   r   r   r   status)rt   
parse_date
safe_valuer   r   safe_numberparse_transfer_status)	rc   r5   rr   rz   	updatedAt
timetstampaccountOperationsfirstOperationr   s	            re   r   zpaymium.parse_transfer  s   B %%h
;;
$$X|<<	__Y//
 OOH6JKK):ArBB!!(G44""8V44#Z00//
HEE&&x::)).)DD0088

 

 
	
rf   c                 8    ddi}|                      |||          S )Nexecutedok)rt   )rc   r   statusess      re   r   zpaymium.parse_transfer_status	  s(    
 &&999rf   rG   GETc                    | j         d         d         dz   | j        z   dz   |                     ||          z   }|                     ||                     |                    }|dk    r|r|d|                     |          z   z  }n|                                  t          |                                           }	|	|z   }
| j	        |	d}|dk    r"|r| 
                    |          }|
|z  }
d|d	<   n$|r"|                     |          }|
|z  }
|d|z   z  }|                     |                     |
          |                     | j                  t          j                  |d
<   ||||dS )Nr8   r6   /rG   ?)zApi-Keyz	Api-NoncePOSTzapplication/jsonzContent-TypezApi-Signature)urlmethodbodyheaders)r[   rY   implode_paramsomitextract_params	urlencodecheck_required_credentialsstrnonceapiKeyjsonhmacencodesecrethashlibsha256)rc   pathr8   r   r   r   r   r   queryr  authqueryStrings               re   signzpaymium.sign  s   iv&,t|;cADDWDWX\^dDeDee		&$"5"5d";";<<(?? 3sT^^E2222++---

%%E3;D;" G  A99U++DDLD.@GN+ -"&.."7"7KK'D3,,C'+yyT1B1BDKKPTP[D\D\^e^l'm'mGO$fdwOOOrf   c
                     |d S |                      |d          }
|
-t          | j        dz   |                     |          z             d S )Nerrors )r   r   rM   r  )rc   httpCodereasonr   r   r   r   rv   requestHeadersrequestBodyr  s              re   handle_errorszpaymium.handle_errors+  sP    4844#		(0C0C CDDDtrf   )N)&__name__
__module____qualname__r`   r   r{   r   r  r   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   floatr	   r   r   r   r   r5   r   r   r  r  __classcell__)rd   s   @re   r   r      sJ       a a a a aF) ) ) ) )  *, 	, 	, 	, 	, 	, 	, @DB j jS j jS\ j j j j". .6 .V . . . .` 68  1  1  1F  1  1  1  1D  5    0 <@d[] A A AS A Abfglbm A A A A$ >@ 4 4 4 4 4 4( =? 4 4 4 4 4 4. @DB = =49 = = = =,
 
h 
 
 
 
& mqy{   I Y X] fi    8 9=R Z ZS Z# Z Z Z Z ac 87 873 87 87C 87TW 87gt 87 87 87 87t1
 1
 1
 1
 1
 1
f: : : &eBSW P P P P6      rf   r   ) ccxt.async_support.base.exchanger   ccxt.abstract.paymiumr   r  ccxt.base.typesr   r   r   r   r	   r
   r   r   r   r   r   r   typingr   ccxt.base.errorsr   ccxt.base.decimal_to_precisionr   ccxt.base.preciser   r    rf   re   <module>r(     sd   6 5 5 5 5 5 - - - - - -  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E       * * * * * * 4 4 4 4 4 4 % % % % % %a a a a ah a a a a arf   