
    !:h                    x   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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 d d	lm Z  d d
lm!Z! d dlm"Z" d dlm#Z# d dlm$Z$ d dlm%Z% d dlm&Z& d dlm'Z' d dlm(Z( d dlm)Z) d dlm*Z* d dlm+Z+ d dlm,Z, d dl-m.Z. d dl/m0Z0  G d dee      Z1y)    )Exchange)ImplicitAPIN)AnyBalances
CurrenciesCurrencyDepositAddressIntMarketNumOrder	OrderBook	OrderSide	OrderTypeStrStringsTickerTickersTradeTradingFeeInterfaceTradingFeesTransaction)List)ExchangeError)AuthenticationError)PermissionDenied)ArgumentsRequired)
BadRequest)	BadSymbol)InsufficientFunds)InvalidAddress)InvalidOrder)OrderNotFound)OrderImmediatelyFillable)DuplicateOrderId)NotSupported)RateLimitExceeded)ExchangeNotAvailable)BadResponse)	TICK_SIZE)Precisec                       e Zd Zdef fdZi fdefdZi fdZi fdZi fde	fdZ
i fdee   fdZdi fd	edefd
Zi fdedefdZdKdededefdZdi fdede	defdZdddi fdede	de	dee   fdZdKdedefdZddi fdede	de	dee   fdZdddi fdede	de	fdZdddi fdedede	de	fdZdKdededefdZ i fde!fdZ"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)dddi fdede	de	dee*   fd$Z+dddi fdede	de	dee*   fd%Z,di fdedefd&Z-di fdefd'Z.dKd(edede*fd)Z/d* Z0d+ Z1d, Z2d- Z3d.efd/Z4d0 Z5i fdede6fd1Z7i fde8fd2Z9dKd3edede6fd4Z:di fd5ed e&d6ede;fd7Z<dddi fd5ede	de	dee;   fd8Z=dddi fd5ede	de	dee;   fd9Z>dKd:ed;e?de;fd<Z@d.efd=ZAi fd5edeBfd>ZCdKd;e?deBfd?ZDi fd@ZEdA ZFdBdCi ddfdDZGd5eHdEedFedGedHedIefdJZI xZJS )Lcoinsphreturnc                    | j                  t        t        |          i ddddddgddd	d
ddd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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d0dd1di d2dd3dd4d d5dd6dd7dd8dd9dd:dd;dd<dd=dd>dd?dd@ddAddBdi dCddDddEddFddGddHddIddJddKddLd dMddNddOddPddQddRddSdi dTddUddVddWddXddYddZdd[dd\dd]dd^dd_dd`ddaddbddcddddi deddfddgd dhddiddjddkddlddmddnddoddpddqddrddsddtddudvdwdxdydzd{d|d}d~ddddddddddddddgddddddddddgddgddggdddddddddddgddggddddddii ddddddddddddddddddddddddddddddddddddi ddddddddddddddddddddddddddddddddddddddddddddddddd| j	                  dī      | j	                  dū      | j	                  dƫ      | j	                  dū      g| j	                  dǫ      | j	                  dȫ      g| j	                  dɫ      | j	                  dʫ      g| j	                  d˫      | j	                  d̫      g| j	                  dͫ      | j	                  dΫ      g| j	                  dϫ      | j	                  dЫ      g| j	                  dѫ      | j	                  dҫ      g| j	                  dӫ      | j	                  dԫ      g| j	                  dի      | j	                  d֫      g| j	                  d׫      | j	                  dث      gg
| j	                  dƫ      | j	                  dī      g| j	                  dǫ      | j	                  d٫      g| j	                  dɫ      | j	                  dΫ      g| j	                  d˫      | j	                  dЫ      g| j	                  dͫ      | j	                  dҫ      g| j	                  dϫ      | j	                  dګ      g| j	                  dѫ      | j	                  d۫      g| j	                  dӫ      | j	                  d֫      g| j	                  dի      | j	                  dܫ      g| j	                  d׫      | j	                  dث      gg
dݜdޜidt
        ddddiddidddddddiddiddddddddddd dddd dddddddddddddd ddddddddddddd ddddd dddddddddddid	d d dd d dddi dt        dt        dt        dt        d t        dt        dt        dt        dt        dt        dt        dt        dt        d	t        d
t        dt        dt        i dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        i dt        dt        d t        d!t        d"t        d#t        d$t        d%t        d&t        d't        d(t        d)t        d*t        d+t        d,t        d-t        d.t        i d/t         d0t        d1t        d2t        d3t        d4t        d5t        d6t        d7t        d8t        d9t        d:t        d;t        d<t        d=t        d>t        d?t        i d@t        dAt        dBt        dCt         dDt        dEt        dFt        dGt        dHt        dIt        dJt        dKt        dLt        dMt        dNt        dOt"        i dPt         dQt        dRt        dSt        dTt        dUt        dVt        dWt        dXt        dYt        dZt        d[t        d\t$        d]t        d^t        d_t        d`t&        t        t        t        t        t        t        t        t        dadb      S (c  Nidr-   namezCoins.ph	countriesPHversionv1	rateLimit2   	certifiedFprohasCORSspotTmarginswapfutureoption	addMargincancelAllOrderscancelOrdercancelOrderscloseAllPositionsclosePositioncreateDepositAddresscreateMarketBuyOrderWithCostcreateMarketOrderWithCostcreateMarketSellOrderWithCostcreateOrdercreatePostOnlyOrdercreateReduceOnlyOrdercreateStopLimitOrdercreateStopMarketOrdercreateStopOrderdeposit	editOrderfetchAccountsfetchBalancefetchBidsAsksfetchBorrowInterestfetchBorrowRateHistoriesfetchBorrowRateHistoryfetchCanceledOrdersfetchClosedOrderfetchClosedOrdersfetchCrossBorrowRatefetchCrossBorrowRatesfetchCurrenciesfetchDepositfetchDepositAddressfetchDepositAddressesfetchDepositAddressesByNetworkfetchDepositsfetchDepositWithdrawFeefetchDepositWithdrawFeesfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchL3OrderBookfetchLedgerfetchLeveragefetchLeverageTiersfetchMarketLeverageTiersfetchMarketsfetchMarkOHLCVfetchMyTrades
fetchOHLCVfetchOpenInterestHistoryfetchOpenOrderfetchOpenOrders
fetchOrderfetchOrderBookfetchOrderBooksfetchOrdersfetchOrderTradesfetchPositionfetchPositionHistoryfetchPositionModefetchPositionsfetchPositionsForSymbolfetchPositionsHistoryfetchPositionsRiskfetchPremiumIndexOHLCVfetchStatusfetchTickerfetchTickers	fetchTimefetchTradesfetchTradingFeefetchTradingFeesfetchTradingLimitsfetchTransactionFeefetchTransactionFeesfetchTransactionsfetchTransfersfetchWithdrawalfetchWithdrawalsfetchWithdrawalWhitelistreduceMarginrepayCrossMarginrepayIsolatedMarginsetLeverage	setMarginsetMarginModesetPositionModesignIntransferwithdrawws
timeframes1m3m5m15m30m1h2h4h6h8h12h1d3d1w1M)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   urlszdhttps://user-images.githubusercontent.com/1294454/225719995-48ab2026-4ddb-496c-9da7-0d7566617c9b.jpgzhttps://api.pro.coins.ph)publicprivatezhttps://coins.ph/z%https://coins-docs.github.io/rest-apizDhttps://support.coins.ph/hc/en-us/sections/4407198694681-Limits-Fees)logoapiwwwdocfeesr   get   (   e         r   )costnoSymbolAndNoSymbolsbyNumberOfSymbols   )r   noSymbol
      )r   byLimit)zopenapi/v1/pingzopenapi/v1/timezopenapi/quote/v1/ticker/24hrzopenapi/quote/v1/ticker/pricez"openapi/quote/v1/ticker/bookTickerzopenapi/v1/exchangeInfozopenapi/quote/v1/depthzopenapi/quote/v1/klineszopenapi/quote/v1/tradeszopenapi/v1/pairszopenapi/quote/v1/avgPricezopenapi/wallet/v1/config/getallz!openapi/wallet/v1/deposit/addressz!openapi/wallet/v1/deposit/historyz"openapi/wallet/v1/withdraw/historyzopenapi/v1/accountopenapi/v1/openOrders   zopenapi/v1/asset/tradeFeeopenapi/v1/orderzopenapi/v1/historyOrderszopenapi/v1/myTradesz"openapi/v1/capital/deposit/historyz#openapi/v1/capital/withdraw/historyz.openapi/v3/payment-request/get-payment-requestzmerchant-api/v1/get-invoicesz"openapi/account/v3/crypto-accountsz"openapi/transfer/v3/transfers/{id}z openapi/wallet/v1/withdraw/applyiX  zopenapi/v1/order/testz!openapi/v1/capital/withdraw/applyz openapi/v1/capital/deposit/applyz+openapi/v3/payment-request/payment-requestsz1openapi/v3/payment-request/delete-payment-requestz3openapi/v3/payment-request/payment-request-reminderopenapi/v1/userDataStreamzmerchant-api/v1/invoiceszmerchant-api/v1/invoices-cancelz.openapi/convert/v1/get-supported-trading-pairszopenapi/convert/v1/get-quotezopenapi/convert/v1/accpet-quotezopenapi/fiat/v1/support-channelzopenapi/fiat/v1/cash-outzopenapi/fiat/v1/history)zopenapi/migration/v4/sellorderz#openapi/migration/v4/validate-fieldzopenapi/transfer/v3/transfers)r   r   r   )r   postdeleter   tradingz0.0025z0.0030500000z0.00271000000z0.00242500000z0.0025000000z0.001810000000z0.0015	100000000z0.0012	500000000z0.0009
1000000000z0.0007
2500000000z0.0005z0.0022z0.001z0.0008z0.0006)takermaker)feeSide	tierBased
percentager   r   tiersprecisionModeoptionswarningGTCFULL)marketlimit)timeInForcenewOrderRespTypemethod!publicGetOpenapiQuoteV1Ticker24hrTRXETHBSCARBITRUM)TRC20ERC20BEP20ARB)!createMarketBuyOrderRequiresPricer   rQ   rK   r   r   networksfeatures)IOCFOKPOGTD)
marginModetriggerPricetriggerPriceTypetriggerDirectionstopLossPricetakeProfitPriceattachedStopLossTakeProfitr   hedgedtrailingleveragemarketBuyByCostmarketBuyRequiresPriceselfTradePreventioniceberg  i )r   r   daysBack	untilDayssymbolRequired)r   triggerr   r  )r   r   r	  r   r  )r   r   r  daysBackCanceledr  r	  r   r  r   )	sandboxrK   createOrdersrt   ry   rx   r|   r[   ru   )linearinverse)r<   r>   r?   
exceptionsz-1000z-1001z-1002z-1003z-1004z-1006z-1007z-1014z-1015z-1016z-1020z-1021z-1022z-1023z-1024z-1025z-1030z-1100z-1101z-1102z-1103z-1104z-1105z-1106z-1111z-1112z-1114z-1115z-1116z-1117z-1118z-1119z-1120z-1121z-1122z-1125z-1127z-1128z-1130z-1131z-1132z-1133z-1134z-1135z-1136z-1137z-1138z-1139z-1140z-1141z-1142z-1143z-1144z-1145z-1146z-1147z-1148z-1149z-1150z-1151z-1152z-1153z-1154z-1155z-1156z-1157z-1158z-1159z-1160z-1161z-2010z-2013z-2011z-2014z-2015z-2016z-3126z-3127z-4001z-100011z-100012z-30008z-30036403zUnknown order sentzDuplicate order sentzMarket is closedz5Account has insufficient balance for requested actionz/Market orders are not supported for self symbolz0Iceberg orders are not supported for self symbolz2Stop loss orders are not supported for self symbolz8Stop loss limit orders are not supported for self symbolz4Take profit orders are not supported for self symbolz:Take profit limit orders are not supported for self symbolzPrice* QTY is zero or lesszIcebergQty exceeds QTYz'This action disabled is on self accountzUnsupported order combinationzOrder would trigger immediatelyz6Cancel order is invalid. Check origClOrdId and orderIdz&Order would immediately match and take)PRICE_FILTERLOT_SIZEMIN_NOTIONALMAX_NUM_ORDERSMAX_ALGO_ORDERSBROKER_MAX_NUM_ORDERSBROKER_MAX_ALGO_ORDERSICEBERG_PARTS)exactbroad)deep_extendsuperr-   describeparse_numberr*   r   r   r'   r"   r)   r&   r   r   r    r%   r#   r(   r   r$   )self	__class__s    F/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/coinsph.pyr  zcoinsph.describe!   s   gt = ? TB
)TB
JTB
 $TB
 t	TB

 TB
 TB
 5TB
  fff %f 	f
 %f %f Uf "4f tf f $Uf  f 'f /f ,Uf  0!f" t#f$ &u%f& ('f( ')f* (+f, "4-f. 4/f0 U1f2  3f4 5f6  7f8 &u9f: +E;f< )%=f> &u?f@ #EAfB $TCfD 'EfF (GfH "4IfJ KfL &tMfN (OfP 1%QfR  SfT *5UfV +EWfX &uYfZ #E[f\ *5]f^ $U_f` "5afb *5cfd +Eeff #Egfh uifj  kfl %emfn +Eofp qfr !%sft  ufv dwfx +Eyfz !${f| "4}f~ df@ !$AfB "5CfD uEfF #DGfH  IfJ 'KfL $UMfN !%OfP *5QfR (SfT %eUfV )%WfX tYfZ t[f\ ]f^ T_f` tafb "4cfd #Deff %egfh &uifj 'kfl $Umfn !%ofp "4qfr #Dsft +Eufv wfx #Eyfz &u{f| u}f~ Uf@  AfB "5CfD %EfF EGfH DIfJ eKfTB
^ _TB
@ ~89 +; _ATB
X +,+, BC\^wz|~v  CE  GI  BJ  MN  PQ  LR  vS  9T CDQR9S HIVW>X35;<3PQ(UVXYTZI[2\3434,-56'092;R <Q =a	
 -b 0!1L 4Q +A 3RR4P .r =a >q I!  7!" =a#$ =a%(:C/ +A <Q	
 ;A Fq LQ Nq 4Q 3A :1 I! 7 :1 :1  3A!" 21#$ ;<?@9:). -.1256W01IYTB
l $!%"&!..x8!..w7 "..s3T5F5Fw5OP!..x8$:K:KH:UV!..y94;L;LX;VW!..y94;L;LW;UV!..y94;L;LX;VW!..z:D<M<Mh<WX!..{;T=N=Nx=XY!..{;T=N=Nx=XY!..|<d>O>OPX>YZ!..|<d>O>OPX>YZ" "..s3T5F5Fx5PQ!..x8$:K:KH:UV!..y94;L;LX;VW!..y94;L;LX;VW!..y94;L;LX;VW!..z:D<M<Mg<VW!..{;T=N=Nx=XY!..{;T=N=Nx=XY!..|<d>O>OPX>YZ!..|<d>O>OPX>YZ" #mTB
t YuTB
x 59u u $)"(!')  A  A! #""%+yTB
t $&+(,,0,1).+06:#'#'"'#(	( #($)$)+/27/3#()$, %)&+!%$*%+*.& ',#($)*/	# ',!%#($)*/( $(&+!%$*,-%+#($)*.	*  #q;z ##
 ##CEuTB
B UZUZU 0U .	U
 \U [U [U \U .U \U \U ZU ZU 0U ZU  Z!U" ]#U$ Z%U& Z'U( Z)U* Z+U, Z-U. Z/U0 Z1U2 Z3U4 [5U6 Z7U8 \9U: \;U< \=U> \?U@ \AUB ZCUD YEUF \GUH ZIUJ ZKUL ZMUN ZOUP .QUR \SUT \UUV \WUX \YUZ \[U\ \]U^ \_U` \aUb \cUd -eUf \gUh ]iUj \kUl \mUn \oUp \qUr \sUt \uUv \wUx YyUz \{U| 0}U~ ZU@ ZAUB \CUD YEUF \GUH \IUJ ZKUL ZMUN \OUP ]QUR ZSUT ZUUV 0WUX [YUZ \[U\ \]U^ Z_U` yaUb ycUd /eUf /gUh /iUl(-*,< '	 LM^	
 Fy G	 I) OPY KI QR[ 1* -j >?O 4\ 6|  Ml!" =>V#$ %1 ,$0&2'3-9.:%/3orCTB
 T T	    c                    | j                  d      sy| j                  |      }i }t        dt        |            D ]  }||   }| j	                  |d      }| j                  |      }| j                  |d      }| j                  |dg       }	i }
t        dt        |	            D ]  }|	|   }| j	                  |d      }| j                  |      }|||d| j                  |d      | j                  |d	      | j                  |d
      | j                  |d      | j                  |d      | j                  |d      dddddd	|
|<    | j                  || j	                  |d      ||rdnd| j                  | j                  | j	                  |d                  |d| j                  |d      | j                  |d      |
ddi d      ||<    |S )a  
        fetches all available currencies on an exchange

        https://docs.coins.ph/rest-api/#all-coins-information-user_data

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an associative dictionary of currencies
        FNr   coinisLegalMoneynetworkListnetworkdepositEnablewithdrawEnablewithdrawFeewithdrawIntegerMultiplewithdrawMinwithdrawMaxminmax)r   rQ   )	infor0   r'  activerQ   r   fee	precisionlimitsr1   fiatcryptotransferPrecisiondepositAllEnablewithdrawAllEnable)r0   r1   codetyper4  r1  r2  rQ   r   r   r3  r   r5  )check_required_credentials%privateGetOpenapiWalletV1ConfigGetallrangelensafe_stringsafe_currency_code	safe_bool	safe_listnetwork_id_to_codesafe_numbersafe_currency_structurer  parse_precision)r  paramsresponseresultientryr0   r;  isFiatr&  r   jnetworkItemr'  networkCodes                  r!  fetch_currencieszcoinsph.fetch_currencies  s    ..u5==fE| q#h-( -	AQKE!!%0B**2.D^^E>:F..rBKH1c+./ )!n**;	B"55g>'!*"#~~k?K ${<L M++KG!%!1!1+?X!Y $(#3#3K#O#'#3#3K#O%
 $(#'$	)%	0  77((7"(h!..t/C/CDDTDTUZ\oDp/qr>>%1CD NN52EF$9 F4L?-	\ r"  c                 |   d|v r	d|vr|d   S d|v rd|vr	d|vr|d   S d|v rHd|v rD|d   }t        |      }|d   }t        dt        |            D ]  }	||	   }
||
d   k\  s|
d   c S  n@d|v r<d	|v r8|d	   }|d   }t        dt        |            D ]  }	||	   }
||
d   k\  s|
d   c S  | j                  |d
d      S )Nr   symbolr   symbolsr   r   r   r   r   r   )r@  r?  
safe_value)r  r   r   pathrI  configrU  symbolsAmountr   rL  rM  r   r   s                r!  calculate_rate_limiter_costz#coinsph.calculate_rate_limiter_costr  s   & 8v+=*%%$.V9KV_ciVi011!V+)v2EY'GLM &': ;1c"345 $)!, E!H, 8O$ 6!6(97OEY'G1c'l+ $
E!H$ 8O$ vvq11r"  c                 4    | j                  |      }dddd|dS )aR  
        the latest known information on the availability of the exchange API

        https://coins-docs.github.io/rest-api/#test-connectivity

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `status structure <https://docs.ccxt.com/#/?id=exchange-status-structure>`
        okN)statusupdatedetaurlr1  )publicGetOpenapiV1Pingr  rI  rJ  s      r!  fetch_statuszcoinsph.fetch_status  s-     ..v6
 	
r"  c                 H    | j                  |      }| j                  |d      S )aU  
        fetches the current integer timestamp in milliseconds from the exchange server

        https://coins-docs.github.io/rest-api/#check-server-time

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns int: the current integer timestamp in milliseconds from the exchange server
        
serverTime)publicGetOpenapiV1Timesafe_integerrb  s      r!  
fetch_timezcoinsph.fetch_time  s)     ..v6   <88r"  c                    | j                  |      }| j                  |dg       }g }t        dt        |            D ]  }||   }| j	                  |d      }| j	                  |d      }| j	                  |d      }	| j                  |      }
| j                  |	      }| j                  | j                  |dg       d      }| j                  |di       }| j                  |d	i       }| j                  |d
i       }|j                  i d|d|
dz   |z   d|
d|ddd|d|	ddddddddddddddd| j                  |d      dk(  ddd ddddddddd| j                  | j	                  |d!            | j                  | j	                  |d"            d#ddd$| j                  | j	                  |d%            | j                  | j	                  |d&            d$| j                  | j	                  |d'            | j                  | j	                  |d(            d$| j                  | j	                  |d)            dd$d*d|d+        | j                  |       |S ),a  
        retrieves data on all markets for coinsph

        https://coins-docs.github.io/rest-api/#exchange-information

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        rU  r   rT  	baseAsset
quoteAssetfilters
filterTyper  r  NOTIONALr0   /basequotesettleNbaseIdquoteIdsettleIdr<  r<   Tr=   Fr>   r?   r@   r2  r]  r   contractr  stepSizetickSize)amountpricer.  minQtymaxQtyminPricemaxPriceminNotional)r   ry  rz  r   )r  r   r   contractSizeexpiryexpiryDatetimestrike
optionTyper4  r5  createdr1  )publicGetOpenapiV1ExchangeInforD  r?  r@  rA  rB  index_byrV  appendsafe_string_lowerr  set_markets)r  rI  rJ  marketsrK  rL  r   r0   rs  rt  rp  rq  r5  amountLimitspriceLimits
costLimitss                   r!  fetch_marketszcoinsph.fetch_markets  s    66v>x ..9b9q#g,' =	AQZF!!&(3B%%fk:F&&v|<G**62D++G4E]]4>>&)R#H,WF??6:rBL//&."EKR@JMM 2b2$*u,2 2 	2
 $2 &2 72 D2 2 2 %2 2 %2 %2 $00BiO2  E!2" $#2$   $"&""//0@0@z0Z[!..t/?/?Z/XY  $#!
  $001A1A,PX1YZ#001A1A,PX1YZ
  $001A1A+z1Z[#001A1A+z1Z[
  $001A1A*m1\]#$  c2 2=	| 	 r"  NrU  c                 ,   | j                          i }|Kg }t        dt        |            D ],  }| j                  ||         }|d   }|j	                  |       . ||d<   d}| j                  | j                  di       }	| j                  |	d|      }
d}|
dk(  r"| j                  | j                  ||            }nH|
d	k(  r"| j                  | j                  ||            }n!| j                  | j                  ||            }| j                  |||      S )
a  
        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market

        https://coins-docs.github.io/rest-api/#24hr-ticker-price-change-statistics
        https://coins-docs.github.io/rest-api/#symbol-price-ticker
        https://coins-docs.github.io/rest-api/#symbol-order-book-ticker

        :param str[]|None symbols: unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
        Nr   r0   rU  r   r   r   "publicGetOpenapiQuoteV1TickerPrice'publicGetOpenapiQuoteV1TickerBookTicker)load_marketsr?  r@  r   r  	safe_dictr   rA  r  extendr  r   parse_tickers)r  rU  rI  requestidsrL  r   r0   defaultMethodr   r   tickerss               r!  fetch_tickerszcoinsph.fetch_tickers1  s    	C1c'l+ WQZ0D\

2 "%GI;..~rB!!'8]C99==dkk'SY>Z[G@@BB4;;wX^C_`G<<T[[RX=YZG!!'7F;;r"  rT  c                    | j                          | j                  |      }d|d   i}d}| j                  | j                  di       }| j	                  |d|      }d}|dk(  r"| j                  | j                  ||            }nH|dk(  r"| j                  | j                  ||            }n!| j                  | j                  ||            }| j                  ||      S )	ap  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

        https://coins-docs.github.io/rest-api/#24hr-ticker-price-change-statistics
        https://coins-docs.github.io/rest-api/#symbol-price-ticker
        https://coins-docs.github.io/rest-api/#symbol-order-book-ticker

        :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>`
        rT  r0   r   r   r   Nr  r  )
r  r   r  r   rA  r  r  r  r   parse_ticker)	r  rT  rI  r   r  r  r   r   tickers	            r!  fetch_tickerzcoinsph.fetch_tickerR  s     	V$fTl
 <..}bA!!'8]C99<<T[[RX=YZF@@AA$++gW]B^_F;;DKKQW<XYF  00r"  r  r   c           	      H   | j                  |d      }| j                  ||      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }	| j                  |d      }
| j                  |d	      }| j                  |d
      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }t        j                  |d      }| j                  i d|d   d|d| j                  |      d|d|d|d| j                  |dd      d|d|d|d|d|d|d|d |d!d d"|	|
|d#|      S )$NrT  	closeTimebidPriceaskPricebidQtyaskQtyvolumequoteVolume	openPrice	highPricelowPriceprevClosePriceweightedAvgPricepriceChangepriceChangePercent100	timestampdatetimeopenhighlowclose	lastPricerz  bid	bidVolumeask	askVolumevwappreviousClosechanger   average
baseVolume)r  r1  )rA  safe_marketrg  r+   
string_mulsafe_tickeriso8601safe_string_2)r  r  r   marketIdr  r  r  r  r  r  r  r  r  r  	prevCloser  changeValue
changePcnts                     r!  r  zcoinsph.parse_tickero  sI   N ##FH5!!(F3%%fk:	vz2vz2$$VX6	$$VX6	%%fh7
&&v}=44vz2$$V-=>	(:;&&v}=%%f.BC
''
E:
 !
fX&!
!
 Y/!
 D	!

 D!
 3!
 T''WE!
 3!
 !
 3!
 !
 D!
 Y!
 k!
 *!
  t!!
" *#!
$ ''!
( ) 	r"  r   c                     | j                          | j                  |      }d|d   i}|||d<   | j                  | j                  ||            }| j	                  ||      }| j                  |d      |d<   |S )aE  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

        https://coins-docs.github.io/rest-api/#order-book

        :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(default 100, max 200)
        :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
        rT  r0   r   lastUpdateIdnonce)r  r   publicGetOpenapiQuoteV1Depthr  parse_order_bookrg  )r  rT  r   rI  r   r  rJ  	orderbooks           r!  fetch_order_bookzcoinsph.fetch_order_book  s     	V$fTl
 $GG44T[[&5QR ))(F;	!..xH	'r"  r   sincec                 Z   | j                          | j                  |      }| j                  | j                  |      }| j	                  |d      }|d   |d}	|d}|Y||	d<   |||	d<   nu| j                  |      dz  }
| j                  ||
|dz
  z        }| j                         }t        ||      |	d<   n)|'||	d<   | j                  |      dz  }
||
|dz
  z  z
  |	d<   ||	d<   | j                  |d      }| j                  | j                  |	|            }| j                  |||||      S )	a   
        fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market

        https://coins-docs.github.io/rest-api/#klinecandlestick-data

        :param str symbol: unified symbol of the market to fetch OHLCV data for
        :param str timeframe: the length of time each candle represents
        :param int [since]: timestamp in ms of the earliest candle to fetch
        :param int [limit]: the maximum amount of candles to fetch(default 500, max 1000)
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: timestamp in ms of the latest candle to fetch
        :returns int[][]: A list of candles ordered, open, high, low, close, volume
        untilr0   )rT  intervalr  	startTimeendTimer   r   )r  r   rA  r   rg  parse_timeframesummillisecondsr/  omitpublicGetOpenapiQuoteV1Klinesr  parse_ohlcvs)r  rT  	timeframer  r   rI  r   r  r  r  durationendTimeByLimitnowrJ  s                 r!  fetch_ohlcvzcoinsph.fetch_ohlcv  s]    	V$##DOOY?!!&'2Tl 
 =E#(GK  %*	"//	:TA!%%UQY1G!H'')%(%=	"!&GI++I6=H#(H	,B#CGK  67+55dkk'66RS$   69eUKKr"  c           	          | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      gS )Nr   r   r   r      r   )rg  rF  )r  ohlcvr   s      r!  parse_ohlcvzcoinsph.parse_ohlcv  sl    eQ'UA&UA&UA&UA&UA&
 	
r"  c                     | j                          | j                  |      }d|d   i}|d|d<   n|||d<   | j                  | j                  ||            }| j	                  ||||      S )a8  
        get the list of most recent trades for a particular symbol

        https://coins-docs.github.io/rest-api/#recent-trades-list

        :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(default 500, max 1000)
        :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>`
        rT  r0   r  r   )r  r   publicGetOpenapiQuoteV1Tradesr  parse_tradesr  rT  r  r   rI  r   r  rJ  s           r!  fetch_tradeszcoinsph.fetch_trades(  s     	V$fTl
 #GG #( 55dkk'66RS   65%@@r"  c                    |t        | j                  dz         | j                          | j                  |      }d|d   i}|||d<   d|d<   n|||d<   | j	                  | j                  ||            }| j                  ||||      S )a  
        fetch all trades made by the user

        https://coins-docs.github.io/rest-api/#account-trade-list-user_data

        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch trades for
        :param int [limit]: the maximum number of trades structures to retrieve(default 500, max 1000)
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
        z+ fetchMyTrades() requires a symbol argumentrT  r0   r  r  r   )r   r0   r  r   privateGetOpenapiV1MyTradesr  r  r  s           r!  fetch_my_tradeszcoinsph.fetch_my_tradesO  s     >#DGG.[$[\\V$fTl
 #(GK #GG$GG33DKK4PQ  65%@@r"  r0   c           	          |t        | j                  dz         d|i}| j                  |||| j                  ||            S )a$  
        fetch all the trades made from a single order

        https://coins-docs.github.io/rest-api/#account-trade-list-user_data

        :param str id: order id
        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch trades for
        :param int [limit]: the maximum number of trades to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
        z. fetchOrderTrades() requires a symbol argumentorderId)r   r0   r  r  )r  r0   rT  r  r   rI  r  s          r!  fetch_order_tradeszcoinsph.fetch_order_tradesk  sN     >#DGG.^$^__r
 ##FE5$++gv:VWWr"  tradec                    | j                  |d      }| j                  ||      }|d   }| j                  |dd      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }	d }
d }| j                  |d      }|&| j                  |d	      }|| j	                  |      d
}| j                  |ddd       }d }||du rdnd}| j                  |dd       }d }|	|dk(  rdnd}d }|| j                  |d      }| j                  |||| j                  |      ||
||||	|||d|      S )NrT  r0   tradeIdr  timerz  qty
commissioncommissionAsset)r   currencyisBuyerisBuyerMakerTbuysellisMakertruer   r   quoteQty)r0   orderr  r  rT  r<  sidetakerOrMakerrz  ry  r   r3  r1  )rA  r  r  rg  rB  safe_bool_2
safe_trader  )r  r  r   r  rT  r0   r  r  priceStringamountStringr<  r3  feeCostfeeCurrencyIdr  r   r  r  
costStrings                      r!  parse_tradezcoinsph.parse_trade  s   L ##E84!!(F3!tY7""5)4%%eV4	&&ug6''u5""5,7 ,,U4EFM 33MBC ""5)^TJ$_56D$$UIt<'.&'87wL
))%<J"Y/( " 
  	r"  c                 f    | j                          | j                  |      }| j                  |      S )ac  
        query for balance and get the amount of funds available for trading or funds locked in orders

        https://coins-docs.github.io/rest-api/#accept-the-quote

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
        )r  privateGetOpenapiV1Accountparse_balancerb  s      r!  fetch_balancezcoinsph.fetch_balance  s3     	226:, !!(++r"  c                 X   | j                  |dg       }|d d d}t        dt        |            D ]i  }||   }| j                  |d      }| j	                  |      }| j                         }| j                  |d      |d<   | j                  |d      |d<   |||<   k | j                  |      S )Nbalances)r1  r  r  r   assetfreelockedused)rD  r?  r@  rA  rB  accountsafe_balance)	r  rJ  r  rK  rL  balance
currencyIdr;  r  s	            r!  r  zcoinsph.parse_balance  s    >>(J;

 q#h-( 	#AqkG))'7;J**:6DllnG"..w?GFO"..wAGFO"F4L	#   ((r"  r<  r   ry  rz  c                 l   | j                          | j                  |      }| j                  |dd      }| j                  |d      }| j	                  |d|      }	| j                  |	      }	| j                  |d      }| j                  |      }
|d   |	|
d}| j                  | j                  di       }| j                  |di       }|	dk(  s|	d	k(  s
|	d
k(  s|	dk(  r{|t        | j                  dz   |z   dz         | j	                  |dd      }| j                  ||      |d<   | j                  ||      |d<   |	dk7  r.| j	                  |dd      |d<   n|	dk(  s|	dk(  s|	dk(  r| j	                  |dd      }|
dk(  r| j                  ||      |d<   n|
dk(  rd}d}| j                  |ddd      \  }}| j                  |dd      }| j                  |d      }|| j                  ||      }ny|re|t!        | j                  dz         | j#                  |      }| j#                  |      }t%        j&                  ||      }| j                  ||      }n| j                  ||      }||d<   |	dk(  s|	d	k(  s
|	dk(  s|	d
k(  rB| j)                  |d d!      }|t!        | j                  d"z         | j                  ||      |d!<   ||d<   | j                  |dd!d dd      }d}|r"| j+                  | j-                  ||            }n!| j/                  | j-                  ||            }| j1                  ||      S )#a  
        create a trade order

        https://coins-docs.github.io/rest-api/#new-order--trade

        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market', 'limit', 'stop_loss', 'take_profit', 'stop_loss_limit', 'take_profit_limit' or 'limit_maker'
        :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 fulfilled, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param float [params.cost]: the quote quantity that can be used alternative for the amount for market buy orders
        :param bool [params.test]: set to True to test an order, no order will be created but the request will be validated
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        testFr<  r0   )rT  r<  r   rK   r   LIMITSTOP_LOSS_LIMITTAKE_PROFIT_LIMITLIMIT_MAKERNz/ createOrder() requires a price argument for a z orderr   r   rz  quantityr   r   MARKET	STOP_LOSSTAKE_PROFITr   SELLBUYTr   r   quoteOrderQtyz createOrder() requires the price argument for market buy orders to calculate the total cost to spend(amount * price), alternatively set the createMarketBuyOrderRequiresPrice option or param to False and pass the cost to spend in the amount argumentr   	stopPricez createOrder() requires a triggerPrice or stopPrice param for stop_loss, take_profit, stop_loss_limit, and take_profit_limit orders)r  r   rC  r  rA  encode_order_typeencode_order_siderV  r   r   r0   price_to_precisionamount_to_precisionhandle_option_and_paramssafe_number_2cost_to_precisionr"   number_to_stringr+   r  r  privatePostOpenapiV1OrderTestr  privatePostOpenapiV1Orderparse_order)r  rT  r<  r   ry  rz  rI  r   	testOrder	orderType	orderSider  r   r   quoteAmountr   r   r  r  costRequestr   rJ  s                         r!  create_orderzcoinsph.create_order  s   " 	V$NN6659	66*$$VVT:	**95	66***40	Tl

 //$,,rB??74FK90A#AYReEeir  wD  jD}'2c(cfj(jmu(uvv#//0@'6R#66vuEGG"&":":66"JGJM))-)9)9'=RW)X&("i;&>)}B\#//0@(FSF"&*&>&>vv&N
#e#"481<@<Y<YZ`bo  rU  W[  =\916))&&/J662#"&"8"8"FK6}*477  6q  ,q  r  r'+'<'<V'D&*&;&;E&B&-&8&8{&S&*&<&<V[&Q"&"8"8"HK+6(#y4E'EVcIcgp  uH  hH--fnkRL#"477  .s  $s  t  t#'#:#:6<#PGK &6"#67KUde99$++gv:VWH55dkk'66RSH8 &11r"  c                     | j                          i }| j                  |dd      }|||d<   n||d<   | j                  |ddg      }| j                  | j	                  ||            }| j                  |      S )a  
        fetches information on an order made by the user

        https://coins-docs.github.io/rest-api/#query-order-user_data

        :param int|str id: order id
        :param str symbol: not used by coinsph fetchOrder()
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        origClientOrderIdclientOrderIdr  )r  safe_value_2r  privateGetOpenapiV1Orderr  r0  r  r0   rT  rI  r  r9  rJ  s          r!  fetch_orderzcoinsph.fetch_ordern  s     	))&2EW$+8G'(!#GI6O5H#IJ00Wf1MN))r"  c                     | j                          d}i }|| j                  |      }|d   |d<   | j                  | j                  ||            }| j	                  ||||      S )a  
        fetch all unfilled currently open orders

        https://coins-docs.github.io/rest-api/#current-open-orders-user_data

        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch open orders for
        :param int [limit]: the maximum number of  open orders structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nr0   rT  )r  r   privateGetOpenapiV1OpenOrdersr  parse_ordersr  s           r!  fetch_open_orderszcoinsph.fetch_open_orders  sn     	[[(F &tGH55dkk'66RS  65%@@r"  c                    |t        | j                  dz         | j                          | j                  |      }d|d   i}|||d<   d|d<   n|||d<   | j	                  | j                  ||            }| j                  ||||      S )aU  
        fetches information on multiple closed orders made by the user

        https://coins-docs.github.io/rest-api/#history-orders-user_data

        :param str symbol: unified market symbol of the market orders were made in
        :param int [since]: the earliest time in ms to fetch orders for
        :param int [limit]: the maximum number of order structures to retrieve(default 500, max 1000)
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        z/ fetchClosedOrders() requires a symbol argumentrT  r0   r  r  r   )r   r0   r  r    privateGetOpenapiV1HistoryOrdersr  r@  r  s           r!  fetch_closed_orderszcoinsph.fetch_closed_orders  s     >#DGG._$_``V$fTl
 #(GK #GG$GG88Wf9UV  65%@@r"  c                     | j                          i }| j                  |dd      }|||d<   n||d<   | j                  |ddg      }| j                  | j	                  ||            }| j                  |      S )aw  
        cancels an open order

        https://coins-docs.github.io/rest-api/#cancel-order-trade

        :param str id: order id
        :param str symbol: not used by coinsph cancelOrder()
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r8  r9  r  )r  r:  r  privateDeleteOpenapiV1Orderr  r0  r<  s          r!  cancel_orderzcoinsph.cancel_order  s     	))&2EW$+8G'(!#GI6O5H#IJ33DKK4PQ))r"  c                     |t        | j                  dz         | j                          d}i }|| j                  |      }|d   |d<   | j	                  | j                  ||            }| j                  ||      S )ar  
        cancel open orders of market

        https://coins-docs.github.io/rest-api/#cancel-all-open-orders-on-a-symbol-trade

        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nz- cancelAllOrders() requires a symbol argumentr0   rT  )r   r0   r  r    privateDeleteOpenapiV1OpenOrdersr  r@  )r  rT  rI  r   r  rJ  s         r!  cancel_all_orderszcoinsph.cancel_all_orders  s     >#DGG.]$]^^[[(F &tGH88Wf9UV  622r"  r  c           
      b   | j                  |d      }| j                  |d      }| j                  ||      }| j                  |dd      }| j                  |dd       }| j                  |d      }t	        j
                  |d      rd }| j                  i d|d	| j                  |d	      d
|d| j                  |      dd d| j                  | j                  |d            d|d   d| j                  | j                  |d            d| j                  | j                  |d            d| j                  | j                  |d            d| j                  |d      d|dd d| j                  |d      d| j                  |d      d| j                  |d      dd d d ||d|      S )Nr  rT  r  transactTimefillsr%  r   r0   r9  r  r  lastTradeTimestampr]  r<  r   r   rz  r   r  ry  origQtyr   cummulativeQuoteQtyfilledexecutedQty	remaining)r3  r   tradesr1  )rA  r  safe_integer_2rV  r+   	string_eq
safe_orderr  parse_order_statusparse_order_typeparse_order_time_in_forceparse_order_side)r  r  r   r0   r  r  rT  r   s           r!  r0  zcoinsph.parse_order  s/   J eY/##E84!!(F3''v~F	6''{;\3/L  
" 
T--e_E 
  
 Y/	 

 !$ 
 d--d.>.>uh.OP 
 fX& 
 D))$*:*:5&*IJ 
 499$:J:J5R_:`a 
 D))$*:*:5&*IJ 
 T%%eW5 
 L 
 t 
 d&&ui8 
 D$$U,AB 
  d&&um<! 
" # 
$ + 
, - 	r"  c                 2    ddd}| j                  |||      S )Nr  r  )r#  r"  rA  r  r]  statusess      r!  r[  zcoinsph.parse_order_sideE  &    
 &&99r"  c                 2    ddd}| j                  |||      S )Nr#  r"  )r  r  r]  r^  s      r!  r'  zcoinsph.encode_order_sideL  r`  r"  c                 <    dddddddd}| j                  |||      S )Nr   r   )r  r  r  r   r  r!  r  r]  r^  s      r!  rY  zcoinsph.parse_order_typeS  s5    "!&#!(
 &&99r"  c                 <    dddddddd}| j                  |||      S )	Nr  r  r  r   r  r!  r  )r   r   limit_maker	stop_lossstop_loss_limittake_profittake_profit_limitr]  r^  s      r!  r&  zcoinsph.encode_order_type_  s5    ($0(!4
 &&99r"  r]  c                 :    ddddddd}| j                  |||      S )Nr  closedcanceledrejected)NEWFILLEDCANCELEDPARTIALLY_FILLEDPARTIALLY_CANCELEDREJECTEDr]  r^  s      r!  rX  zcoinsph.parse_order_statusk  s2    " &","
 &&99r"  c                 4    dddd}| j                  |||      S )Nr   r   r   )r   r   r   r]  r^  s      r!  rZ  z!coinsph.parse_order_time_in_forcev  s)    

 &&99r"  c                     | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  |di       }| j                  ||      S )aU  
        fetch the trading fees for a market

        https://coins-docs.github.io/rest-api/#trade-fee-user_data

        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `fee structure <https://docs.ccxt.com/#/?id=fee-structure>`
        rT  r0   r   )r  r    privateGetOpenapiV1AssetTradeFeer  r  parse_trading_fee)r  rT  rI  r   r  rJ  
tradingFees          r!  fetch_trading_feezcoinsph.fetch_trading_fee~  sr     	V$fTl
 88Wf9UV ^^Ha4
%%j&99r"  c                     | j                          | j                  |      }i }t        dt        |            D ]   }| j	                  ||         }|d   }|||<   " |S )aU  
        fetch the trading fees for multiple markets

        https://coins-docs.github.io/rest-api/#trade-fee-user_data

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `fee structures <https://docs.ccxt.com/#/?id=fee-structure>` indexed by market symbols
        r   rT  )r  ru  r?  r@  rv  )r  rI  rJ  rK  rL  r3  rT  s          r!  fetch_trading_feeszcoinsph.fetch_trading_fees  sn     	88@ q#h-( 	!A((!5C]F F6N	! r"  r3  c                     | j                  |d      }| j                  ||      }|d   }||| j                  |d      | j                  |d      d d dS )NrT  makerCommissiontakerCommission)r1  rT  r   r   r   r   )rA  r  rF  )r  r3  r   r  rT  s        r!  rv  zcoinsph.parse_trading_fee  sj     ##C2!!(F3!%%c+<=%%c+<=
 	
r"  r;  addressc                    | j                  | j                  d      }| j                  |dd      }|rt        | j                  dz         | j                  |d      }| j                  ||      }	|	t        | j                  dz         | j                          | j                  |      }
|
d   | j                  |      |	|d}|||d	<   | j                  |d      }| j                  | j                  ||            }| j                  ||
      S )
a  
        make a withdrawal to coins_ph account

        https://coins-docs.github.io/rest-api/#withdrawuser_data

        :param str code: unified currency code
        :param float amount: the amount to withdraw
        :param str address: not used by coinsph withdraw()
        :param str tag:
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
        r   r   Tz withdraw() makes a withdrawals only to coins_ph account, add .options['withdraw']['warning'] = False to make a withdrawal to your coins_ph accountr'  z% withdraw() require network parameterr0   )r$  ry  r'  r~  withdrawOrderId)rV  r   rC  r!   r0   rA  network_code_to_idr   r  r  r-  r  'privatePostOpenapiWalletV1WithdrawApplyr  parse_transaction)r  r;  ry  r~  tagrI  r   r   rQ  	networkIdr  r  rJ  s                r!  r   zcoinsph.withdraw  s    //$,,
;..)T:   ,A  "A  B  B&&vy9++K>	TWW'NNOO==&TN++F3 	
 ?),G%&69-??GU[@\]%%h99r"  c                     | j                          d}i }|| j                  |      }|d   |d<   |||d<   |||d<   | j                  | j                  ||            }| j	                  ||||      S )a  
        fetch all deposits made to an account

        https://coins-docs.github.io/rest-api/#deposit-history-user_data

        :param str code: unified currency code
        :param int [since]: the earliest time in ms to fetch deposits for
        :param int [limit]: the maximum number of deposits structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
        Nr0   r$  r  r   )r  r  'privateGetOpenapiWalletV1DepositHistoryr  parse_transactionsr  r;  r  r   rI  r  r  rJ  s           r!  fetch_depositszcoinsph.fetch_deposits  s     	}}T*H&tnGFO#(GK $GG??GU[@\]: &&x5%HHr"  c                     | j                          d}i }|| j                  |      }|d   |d<   |||d<   |||d<   | j                  | j                  ||            }| j	                  ||||      S )a  
        fetch all withdrawals made from an account

        https://coins-docs.github.io/rest-api/#withdraw-history-user_data

        :param str code: unified currency code
        :param int [since]: the earliest time in ms to fetch withdrawals for
        :param int [limit]: the maximum number of withdrawals structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
        Nr0   r$  r  r   )r  r  (privateGetOpenapiWalletV1WithdrawHistoryr  r  r  s           r!  fetch_withdrawalszcoinsph.fetch_withdrawals'  s     	}}T*H&tnGFO#(GK $GG@@WV\A]^F &&x5%HHr"  transactionr  c                    | j                  |d      }| j                  |d      }| j                  |d      }|t        |      dk  rd }| j                  |d      }| j                  |d      }| j                  ||      }d }	| j                  |dd      }	d }
d }| j                  |d	      }| j                  |d
      }|d}n|d}| j	                  | j                  |d            }| j                  |d      }| j                  |d      }d }|||d}| j                  |d      }|dk(  }i d|d|d|d|	d| j                  |	      d|d|d|dd d|d|dd d|d|d|d|d|
|d |dS ) Nr0   r~  
addressTagr   txIdr$  
insertTime	applyTimer  depositOrderId
withdrawalrQ   r]  ry  transactionFee)r  r   r'  Internalr1  txidr  r  	addressToaddressFromr  tagTotagFromr<  r  r^  )internalcommentr3  )rA  r@  rB  rU  parse_transaction_statusrF  r  )r  r  r  r0   r~  r  r  r  r;  r  r^  r<  r  r  r]  ry  r  r3  r'  r  s                       r!  r  zcoinsph.parse_transactionc  sC   J k40"";	:{L9?3x!|V4%%k6:
&&z8<	''\;O	**;8IJ))+7GH&D'D..t/?/?X/VW!!+x8"";0@A#W5C"";	:j(
K
"
 D
 	

 Y/
 w
 w
 
 4
 3
 S
 t
 D
 f
 
  f!
" w#
$ !)
 	
r"  c                 6    ddddd}| j                  |||      S )Npendingr\  failed)r   123r]  r^  s      r!  r  z coinsph.parse_transaction_status  s,    	
 &&99r"  c                 Z   | j                  |d      }| j                  ||      }|t        | j                  dz         | j	                          | j                  |      }|d   |d}| j                  |d      }| j                  | j                  ||            }| j                  ||      S )a  
        fetch the deposit address for a currency associated with self account

        https://coins-docs.github.io/rest-api/#deposit-address-user_data

        :param str code: unified currency code
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.network]: network for fetch deposit address
        :returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
        r'  z0 fetchDepositAddress() require network parameterr0   )r$  r'  )
rA  r  r   r0   r  r  r  'privateGetOpenapiWalletV1DepositAddressr  parse_deposit_address)r  r;  rI  rQ  r  r  r  rJ  s           r!  fetch_deposit_addresszcoinsph.fetch_deposit_address  s     &&vy9++K>	TWW'YYZZ==&TN 
 69-??GU[@\] ))(H==r"  c                     | j                  |d      }| j                  ||      }||d | j                  |d      | j                  |d      dS )Nr$  r~  r  )r1  r  r'  r~  r  )rA  rB  )r  depositAddressr  r  parsedCurrencys        r!  r  zcoinsph.parse_deposit_address  s[     %%nf=
00XF"&''	B##NLA
 	
r"  c                 `   d}t        |j                               }t        dt        |            D ]S  }||   }t	        ||   t               s|dk7  r|dz  }||   }| j                  ||      }| j                  ||      }||z  }U | j                  |      }t        |      dk7  r|dz   |z   S |S )N r   &)listkeysr?  r@  
isinstancer  parse_array_param	urlencode)	r  queryencodedArrayParamsr  rL  key
innerArrayencodedArrayParamencodedQuerys	            r!  url_encode_queryzcoinsph.url_encode_query  s    EJJL!q#d)$ 	8Aq'C%*d+6&#-&"3Z
		%-$($:$::s$K!"&77"	8 ~~e,|!#%(:::%%r"  c                     | j                  |      }|j                  dd      }|j                  dd      }|dz   |z   }|S )N[z%5B]z%5D=)jsonreplace)r  arrayr  stringifiedArrayurlEncodedParams        r!  r  zcoinsph.parse_array_param  sL    99U++33C?+33C?)&66r"  r   GETc                    | j                   d   |   }| j                  || j                  |            }| j                  ||      }	|dz   |	z   }|dk(  r| j	                          | j                         |d<   | j                  |d      }
|
#| j                  | j                  d      }|||d<   | j                  |      }| j                  | j                  |      | j                  | j                        t        j                        }|dz   |z   dz   |z   }d| j                  i}n'| j                  |      }t        |      d	k7  r|d|z   z  }||||d
S )Nr   ro  r   r  
recvWindow?z&signature=zX-COINS-APIKEYr   )r`  r   bodyheaders)r   r  extract_paramsimplode_paramsr=  r  rg  r   r  hmacencodesecrethashlibsha256apiKeyr@  )r  rW  r   r   rI  r  r  r`  r  endpointr  defaultRecvWindow	signatures                r!  signzcoinsph.sign  sW   iis#		&$"5"5d";<&&tV4Ci(")++-!%!2!2!4E+**5,?J!$($5$5dllL$Q!$0*;E,'))%0E		$++e"4dkk$++6NPWP^P^_I)e#m3i?C $++G ))%0E5zQsU{"fdwOOr"  reasonr`  r   r  r  c
                    |y | j                  |dd       }
|
g|
dk7  rb|
dk7  r]| j                  dz   |z   }| j                  | j                  d   ||       | j	                  | j                  d   |
|       t        |      y )Nr;  200r    r  r  )rA  r0   throw_broadly_matched_exceptionr  throw_exactly_matched_exceptionr   )r  r;  r  r`  r   r  r  rJ  requestHeadersrequestBodyresponseCodefeedbacks               r!  handle_errorszcoinsph.handle_errors'  s    ''&$?$<5+@|WZGZww}t+H001I4QYZ001I<Yab))r"  )N)K__name__
__module____qualname__r   r  r   rR  rZ  rc  r
   rh  r   r   r  r   r   r  strr   r  dictr  r   r  r  r  r  r   r  r   r  r  r	  r   r  r  r   r   floatr   r6  r=  r   rA  rD  rG  rJ  r0  r[  r'  rY  r&  rX  rZ  r   rx  r   rz  rv  r   r   r  r  r   r  r  r	   r  r  r  r  r  intr  __classcell__)r   s   @r!  r-   r-      s   U# Un ') xZ xt MO 2, #% 
$ !# 9s 9 $& F$v, FP 04B <W <7 <B 02 13 1f 1:L4 L L6 L\ :>b "s "3 "Y "H 26DW[df ;L# ;Lc ;LQT ;Lkoptku ;Lz
 
4 
 6:UW %A3 %As %A# %A\`af\g %AN -1tRV_a Ac A AC A8 9=4^bkm XS X# XS XX[ X(P Pv P Pd $&  ,(  ,D) )" gksu h23 h2i h2y h2RW h2`c h2T 26b *c *3 *, /3TXac A A3 Ac Ahlmrhs A* 154VZce A# AS APS Ajnotju A8 37r *s *C *, /32 3 3*c cv c cJ::
:
:	: 	:: 57 : :;N :8 )+ { @
T 
6 
EX 
( DHPR !:S !:% !:# !:Wb !:F *.Dt\^ 4I3 4Ic 4I 4Icghsct 4Il -1tRV_a :Ic :I :IC :Ifjkvfw :IxU
T U
X U
Q\ U
n:s : 79 ># >^ >@
h 
R` 
$ &( &$ &eBSW P2	# 	s 	 	c 	TX 	`c 	r"  r-   )2ccxt.base.exchanger   ccxt.abstract.coinsphr   r  ccxt.base.typesr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   typingr   ccxt.base.errorsr   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   ccxt.base.decimal_to_precisionr*   ccxt.base.preciser+   r-    r"  r!  <module>r     s}    ( -  _  _  _  _  _  _  * 0 - . ' & . + ) * 5 - ) . 1 ( 4 %Q h Q r"  