
    ilO                         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 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	IndexTypeIntMarketNum	OrderBook	OrderSide	OrderTypeStrTickerTradeTradingFees)List)	TICK_SIZE)Precisec                   F    e Zd Z fdZdefdZi fdefdZd%ded	e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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	fdZd&d efd!Z d"d#i ddfd$Z! xZ"S )'bl3pc                 L   |                      t          t          |                                           dddg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d)dd*di d+dd,d
d-dd.dd/dd0dd1dd2d
d3d
d4dd5d
d6dd7dd8dd9dd:dd;dddd<d=d>d?id@g dAdBdCg dDidEg dFidGdH|                     dIdHdJdKdJdKdLdLd	d
dM
          it
          dN          S )ONr   BL3PNLi  1zAn exchange market by BitonicNLFCORSspotTmarginswapfutureoption	addMargincancelOrdercloseAllPositionsclosePositioncreateDepositAddresscreateOrdercreateReduceOnlyOrdercreateStopLimitOrdercreateStopMarketOrdercreateStopOrderfetchBalancefetchBorrowRateHistoriesfetchBorrowRateHistoryfetchCrossBorrowRatefetchCrossBorrowRatesfetchDepositAddressfetchDepositAddressesfetchDepositAddressesByNetworkfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchLeveragefetchMarginModefetchMarkOHLCVfetchOpenInterestHistoryfetchOrderBookfetchPositionfetchPositionModefetchPositionsfetchPositionsRiskfetchPremiumIndexOHLCVfetchTickerfetchTradesfetchTradingFeefetchTradingFeesfetchTransferfetchTransfersreduceMarginsetLeveragesetMarginModesetPositionMode)transferwszchttps://user-images.githubusercontent.com/1294454/28501752-60c21b82-6feb-11e7-818b-055ee6d0e754.jpgrestzhttps://api.bl3p.euzhttps://bl3p.eu)z6https://github.com/BitonicNL/bl3p-api/tree/master/docszhttps://bl3p.eu/apizhttps://bitonic.nl/en/api)logoapiwwwdocget)z{market}/tickerz{market}/orderbookz{market}/tradespost)z{market}/money/depth/fullz{market}/money/order/addz{market}/money/order/cancelz{market}/money/order/resultz{market}/money/ordersz{market}/money/orders/historyz{market}/money/trades/fetchzGENMKT/money/infozGENMKT/money/deposit_addressz GENMKT/money/new_deposit_addresszGENMKT/money/wallet/historyzGENMKT/money/withdraw)publicprivatezBTC/EURBTCEURBTCEURg{Gzd?)
idsymbolbasequotebaseIdquoteIdmakertakertyper   )r\   name	countries	rateLimitversioncommentprohasurlsrR   marketsprecisionMode)deep_extendsuperr   describesafe_market_structurer   )self	__class__s    O/var/www/html/crypto-bot/backend/venv/lib/python3.11/site-packages/ccxt/bl3p.pyrq   zbl3p.describe   s   dD 1 1 : : < <8666 %6 	6
 %6 %6 U6 t6 $U6  6 '6 t6 (6 '6 (6  "5!6" #6 6$ +E%6& )%'6( ')6* (+6, &u-6. (/60 1%162 &u364 #E566 *5768 $U96: "5;6< *5=6> +E?6@  A6B "5C6D !%E6 6 6F +EG6H !$I6J  K6L $UM6N !%O6P %eQ6R )%S6T tU6V tW6X "5Y6Z #D[6\  ]6^ !%_6` a6b uc6d  e6f "5g6 6h "k6 6 6p ~1 )            4 455XQZdity  FK  X]  hn  y  IO  Y]  7^  7^  _  _ 'Oh?
 h?
 h h h	    returnc                    |                      |di           }|                      |di           }d|i}t          | j                                                  }t	          dt          |                    D ]}||         }|                     |          }|d         }	|                      ||	i           }
|                      |
di           }|                      |
di           }|                                 }|                     |d          |d	<   |                     |d          |d
<   |||<   | 	                    |          S )Ndatawalletsinfor   r\   	availablebalancevaluefreetotal)

safe_valuelist
currencieskeysrangelencurrencyaccountsafe_stringsafe_balance)rs   responsery   rz   resultcodesicoder   
currencyIdwalletr|   r}   r   s                 ru   parse_balancezbl3p.parse_balance|   s0   x44//$	266$T_))++,,q#e**%% 
	# 
	#A8D}}T**H!$J__Wj"==FR@@Ioofi<<GllnnG"..y'BBGFO#//AAGG"F4LL  (((rv   c                 ~    |                                   |                     |          }|                     |          S )a  
        query for balance and get the amount of funds available for trading or funds locked in orders
        :see: https://github.com/BitonicNL/bl3p-api/blob/master/docs/authenticated_api/http.md#35---get-account-info--balance
        :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privatePostGENMKTMoneyInfor   )rs   paramsr   s      ru   fetch_balancezbl3p.fetch_balance   s=     	226::!!(+++rv   r         priceKey	amountKeycountOrIdKeyc                     |                      ||          }|                      ||          }|                     t          j        |d                    |                     t          j        |d                    gS )N100000.0z100000000.0)r   parse_numberr   
string_div)rs   bidaskr   r   r   pricesizes          ru   parse_bid_askzbl3p.parse_bid_ask   sr      22	22g0
CCDDg0}EEFF
 	
rv   Nr]   limitc           	          |                      |          }d|d         i}|                     |                     ||                    }|                     |d          }|                     ||d         ddddd	          S )
aZ  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
        :see: https://github.com/BitonicNL/bl3p-api/blob/master/docs/public_api/http.md#22---orderbook
        :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
        marketr\   ry   r]   Nbidsasks	price_int
amount_int)r   publicGetMarketOrderbookextend	safe_dictparse_order_book)rs   r]   r   r   r   requestr   	orderbooks           ru   fetch_order_bookzbl3p.fetch_order_book   s     V$$fTl
 00Wf1M1MNNNN8V44	$$Yx0@$PVXceqrrrrv   r   c                 @   |                      d |          }|                     |d          }|                     |d          }|                     |di           }|                     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|          S )N	timestamplastvolumer]   datetimehighlowbid	bidVolumeask	askVolumevwapopenclosepreviousClosechange
percentageaverage24h)
baseVolumequoteVolumer{   )safe_symbolsafe_timestampr   r   safe_tickeriso8601)rs   tickerr   r]   r   r   r   s          ru   parse_tickerzbl3p.parse_ticker   s     !!$//''<<	//266 !
f!
!
 Y//!
 D$$VV44	!

 4##FE22!
 4##FE22!
 !
 4##FE22!
 !
 D!
 D!
 T!
 D!
 T!
 d!
  $!!
" t#!
$ **6599)!
 !
 !
* +  	rv   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://github.com/BitonicNL/bl3p-api/blob/master/docs/public_api/http.md#21---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>`
        r   r\   )r   publicGetMarketTickerr   r   )rs   r]   r   r   r   r   s         ru   fetch_tickerzbl3p.fetch_ticker   s`     V$$fTl
 ++DKK,H,HII    000rv   c                    |                      |d          }|                     |d          }|                      |d          }|                      |d          }|                     d |          }|                     ||||                     |          |d         d d d d t          j        |d          t          j        |d          d d d|          S )	Ntrade_iddater   r   r]   100000	100000000)r\   r{   r   r   r]   rd   sideordertakerOrMakerr   amountcostfee)r   safe_integersafe_market
safe_trader   r   r   )rs   trader   r\   r   r   r   s          ru   parse_tradezbl3p.parse_trade   s     eZ00%%eV44	  44!!%66!!$//"Y//X& 'x88(== 
  
   	rv   sincec                     |                      |          }|                     |                     d|d         i|                    }|                     |d         d         |||          }|S )aK  
        get the list of most recent trades for a particular symbol
        :see: https://github.com/BitonicNL/bl3p-api/blob/master/docs/public_api/http.md#23---last-1000-trades
        :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>`
        r   r\   ry   trades)r   publicGetMarketTradesr   parse_trades)rs   r]   r   r   r   r   r   r   s           ru   fetch_tradeszbl3p.fetch_trades  su     V$$--dkkfTl;
/ /  " ""8F#3H#=vueTTrv   c                    |                                   |                     |          }|                     |di           }|                     |d          }|                     t          j        |d                    }i }t          dt          | j	                            D ]}| j	        |         }||||ddd||<   |S )a  
        fetch the trading fees for multiple markets
        :see: https://github.com/BitonicNL/bl3p-api/blob/master/docs/authenticated_api/http.md#35---get-account-info--balance
        :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
        ry   	trade_fee100r   TF)r{   r]   rb   rc   r   	tierBased)
r   r   r   r   r   r   r   r   r   symbols)	rs   r   r   ry   	feeStringr   r   r   r]   s	            ru   fetch_trading_feeszbl3p.fetch_trading_fees:  s     	226::: x44$$T;77	 29e D DEEq#dl++,, 		 		A\!_F "" F6NN rv   rd   r   r   r   c                    |                      |          }|                     |          }|                     |          }	|d         t          t          j        |d                    |d         |dk    rdndd}
|dk    r%t          t          j        |	d	                    |
d
<   |                     |                     |
|                    }|                     |d         d          }|                     ||d|          S )a  
        create a trade order
        :see: https://github.com/BitonicNL/bl3p-api/blob/master/examples/nodejs/example.md#21---create-an-order
        :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
         *
         * EXCHANGE SPECIFIC PARAMETERS
        :param int [params.amount_funds]: maximal EUR amount to spend(*1e5)
        :param str [params.fee_currency]: 'EUR' or 'BTC'
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r\   r   r_   buyr   r   )r   r   fee_currencyrd   r   r   r   ry   order_id)r{   r\   )	r   number_to_stringintr   
string_mulprivatePostMarketMoneyOrderAddr   r   
safe_order)rs   r]   rd   r   r   r   r   r   amountStringpriceStringr   r   orderIds                ru   create_orderzbl3p.create_ordero  s     V$$,,V44++E22Tlg0{KKLL"7O"emmEE%	
 
 7??!$W%7Z%P%P!Q!QE+66t{{5&7Q7QRR""8F#3Z@@ 
  
   	rv   r\   c                 \    d|i}|                      |                     ||                    S )a  
        cancels an open order
        :see: https://github.com/BitonicNL/bl3p-api/blob/master/docs/authenticated_api/http.md#22---cancel-an-order
        :param str id: order id
        :param str symbol: unified symbol of the market the order was made in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r   )!privatePostMarketMoneyOrderCancelr   )rs   r\   r]   r   r   s        ru   cancel_orderzbl3p.cancel_order  s4     
 55dkk'66R6RSSSrv   r   c                    |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     |d          }|                     ||          S )a  
        create a currency deposit address
        :see: https://github.com/BitonicNL/bl3p-api/blob/master/docs/authenticated_api/http.md#32---create-a-new-deposit-address
        :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   r\   ry   )r   r   'privatePostGENMKTMoneyNewDepositAddressr   r   parse_deposit_address)rs   r   r   r   r   r   ry   s          ru   create_deposit_addresszbl3p.create_deposit_address  s     	==&&
 ??GU[@\@\]] ~~h//))$999rv   r   c                     |                      |d          }|                     |           ||                      |d          |d d dS )Naddressr   )r{   r   r  tagnetwork)r   check_address)rs   depositAddressr   r  s       ru   r   zbl3p.parse_deposit_address  s[     "">9==7###"((6::
 
 	
rv   rW   GETc                    |                      ||          }| j        d         d         dz   | j        z   dz   |z   }|                     ||                     |                    }	|dk    r|	r|d|                     |	          z   z  }n|                                  |                                 }
|                     |                     d|
i|	                    }| 	                    | j
                  }|dz   |z   }|                     |                     |          |t          j        d          }d	| j        |d
}||||dS )NrR   rP   /rW   ?nonce base64z!application/x-www-form-urlencoded)zContent-TypezRest-Keyz	Rest-Sign)urlmethodbodyheaders)implode_paramsrl   rh   omitextract_params	urlencodecheck_required_credentialsr  r   base64_to_binarysecrethmacencodehashlibsha512apiKey)rs   pathrR   r  r   r  r  r   r  queryr  r  auth	signatures                 ru   signz	bl3p.sign  sB   %%dF33iv&,t|;cAGK		&$"5"5d";";<<(?? 3sT^^E2222++---JJLLE>>$++w.>"F"FGGD**4;77FT>D(D		$++d"3"3VW^XVVI C K& G
 fdwOOOrv   )r   r   r   )N)#__name__
__module____qualname__rq   r   r   r   r   r   strr   r   r   r	   r   r   r   r   r   r   r   r   r   r   r   floatr
   r   r   r   r  r   r   r#  __classcell__)rt   s   @ru   r   r      s       i i i i iV) ) ) ) )$ $& 	, 	,( 	, 	, 	, 	,
 
i 
	 
en 
 
 
 
 :>b s ss s3 sY s s s s") )6 )V ) ) ) )V 02 1 13 1f 1 1 1 1<  5    @ 6:UW  3 s # \`af\g    > )+ 3 3{ 3 3 3 3j gksu    3  i  y  RW  `c        D 37r T Ts TC T T T T 8: : :3 : : : :2
 
h 
 
 
 
  &eBSW P P P P P P P Prv   r   )ccxt.base.exchanger   ccxt.abstract.bl3pr   r  ccxt.base.typesr   r   r   r   r	   r
   r   r   r   r   r   r   r   typingr   ccxt.base.decimal_to_precisionr   ccxt.base.preciser   r    rv   ru   <module>r1     sh   ( ' ' ' ' ' * * * * * *  N  N  N  N  N  N  N  N  N  N  N  N  N  N  N  N  N  N  N  N  N  N  N  N  N  N  N  N  N  N       4 4 4 4 4 4 % % % % % %MP MP MP MP MP8[ MP MP MP MP MPrv   