
    i^                         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    R/var/www/html/crypto-bot/backend/venv/lib/python3.11/site-packages/ccxt/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                 ~    |                                   |                     |          }|                     |          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>`
        )load_marketsprivateGetUserr{   )rc   paramsrv   s      re   fetch_balancezpaymium.fetch_balance   s=     	&&v..!!(+++rf   NrN   limitc           	          |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     ||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
        rr   rM   rN   N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
 224;;w3O3OPP$$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                     |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     ||          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>`
        rr   rM   )r}   r   publicGetDataCurrencyTickerr   r   )rc   rN   r   r   r   r   s         re   fetch_tickerzpaymium.fetch_ticker   sr     	V$$t
 11$++gv2N2NOO&   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                     |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     ||||          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>`
        rr   rM   )r}   r   publicGetDataCurrencyTradesr   parse_trades)rc   rN   r   r   r   r   r   rv   s           re   fetch_tradeszpaymium.fetch_trades  st     	V$$t
 33DKK4P4PQQ  65%@@@rf   ry   c                 ~    |                                   |                     |          }|                     |          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>`
        )r}   privatePostUserAddressesparse_deposit_address)rc   ry   r   rv   s       re   create_deposit_addresszpaymium.create_deposit_address  s?     	0088 ))(333rf   c                     |                                   d|i}|                     |                     ||                    }|                     |          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>`
        address)r}   privateGetUserAddressesAddressr   r   )rc   ry   r   r   rv   s        re   fetch_deposit_addresszpaymium.fetch_deposit_address1  s[     	t
 66t{{7F7S7STT ))(333rf   codesc                     |                                   |                     |          }|                     ||          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>`
        )r}   privateGetUserAddressesparse_deposit_addresses)rc   r   r   rv   s       re   fetch_deposit_addresseszpaymium.fetch_deposit_addressesH  sA     	//77 ++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                 @   |                                   |                     |          }|                     |          dz   |d         ||d}|dk    r||d<   |                     |                     ||                    }	|                     |	|	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>`
        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--dkk'6.J.JKK6" 
  
   	rf   rM   c                 \    d|i}|                      |                     ||                    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   )!privateDeleteUserOrdersUuidCancelr   )rc   rM   rN   r   r   s        re   cancel_orderzpaymium.cancel_order  s4     B
 55dkk'66R6RSSSrf   fromAccount	toAccountc                    |                                   |                     |          }|                    d          dk     rt          | j        dz             |dk    r|dk    rt          | j        dz             |d         |                     ||          |d}|                     |                     ||                    }|                     ||          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>`
        @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>>
 
 55dkk'66R6RSS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      sB       a a a a aF) ) ) ) )  $& 	, 	,( 	, 	, 	, 	, :>b j js j3 jY j j j j". .6 .V . . . .` 02  1  13  1f  1  1  1  1D  5    0 6:UW A A3 As A# A\`af\g A A A A$ 8: 4 43 4 4 4 4( 79 4 4# 4 4 4 4. :>b = =T#Y = = = =,
 
h 
 
 
 
& gksu  3 i y RW `c    8 37r T Ts TC T T T T [] 87 87S 87% 87c 87c 87an 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.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   ( ' ' ' ' ' - - - - - -  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   