Skip to content

Commit

Permalink
Docs (#21) (#22)
Browse files Browse the repository at this point in the history
* remove links in comments for BinanceDataBase

* add missing with spaces in doc strings

* add code example for docs

* switch from README.md to README.rst

* add sphinx docs

* increase version to 0.1.1

* update documentation links

* correct maj
  • Loading branch information
EtWnn authored Mar 24, 2021
1 parent e3dc1b0 commit 3b043d3
Show file tree
Hide file tree
Showing 13 changed files with 508 additions and 123 deletions.
2 changes: 1 addition & 1 deletion BinanceWatch/BinanceManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def update_universal_transfers(self, transfer_filter: Optional[str] = None):
pbar = tqdm(total=len(transfers_types))
for transfer_type in transfers_types:
pbar.set_description(f"fetching transfer type {transfer_type}")
latest_time = self.db.get_last_universal_transfer(transfer_type=transfer_type) + 1
latest_time = self.db.get_last_universal_transfer_time(transfer_type=transfer_type) + 1
current = 1
while True:
universal_transfers = self.client.query_universal_transfer_history(type=transfer_type,
Expand Down
2 changes: 1 addition & 1 deletion BinanceWatch/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = "0.1.0"
__version__ = "0.1.1"
__author__ = 'EtWnn'
149 changes: 137 additions & 12 deletions BinanceWatch/storage/BinanceDataBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ def get_universal_transfers(self, transfer_type: Optional[str] = None, asset: Op
:type end_time: Optional[int]
:return: The raw rows selected as saved in the database
:rtype: List[Tuple]
.. code-block:: python
[
(1206491332, # transfer id
'MAIN_MARGIN', # transfer type
1589121841000, # time
'BNB', # asset
10.594112), # amount
]
"""
table = tables.UNIVERSAL_TRANSFER_TABLE

Expand All @@ -76,7 +86,7 @@ def get_universal_transfers(self, transfer_type: Optional[str] = None, asset: Op
end_time))
return self.get_conditions_rows(table, conditions_list=conditions_list)

def get_last_universal_transfer(self, transfer_type: str):
def get_last_universal_transfer_time(self, transfer_type: str) -> int:
"""
return the latest time when a universal transfer was made
If None, return the millistamp corresponding to 2017/01/01
Expand Down Expand Up @@ -148,6 +158,15 @@ def get_margin_interests(self, margin_type: str, asset: Optional[str] = None, st
:type end_time: Optional[int]
:return: The raw rows selected as saved in the database
:rtype: List[Tuple]
.. code-block:: python
[
1559415215400, # time
'BNB', # asset
0.51561, # interest
'PERIODIC_CONVERTED'), # interest type
]
"""
if margin_type == 'cross':
table = tables.CROSS_MARGIN_INTEREST_TABLE
Expand Down Expand Up @@ -255,6 +274,16 @@ def get_repays(self, margin_type: str, asset: Optional[str] = None, start_time:
:type end_time: Optional[int]
:return: The raw rows selected as saved in the database
:rtype: List[Tuple]
.. code-block:: python
[
(8289451654, # transaction id
1559415215400, # time
'USDT', # asset
145.5491462, # principal
0.51561), # interest
]
"""
if margin_type == 'cross':
table = tables.CROSS_MARGIN_REPAY_TABLE
Expand All @@ -278,7 +307,7 @@ def get_repays(self, margin_type: str, asset: Optional[str] = None, start_time:
end_time))
return self.get_conditions_rows(table, conditions_list=conditions_list)

def get_last_repay_time(self, asset: str, margin_type: str):
def get_last_repay_time(self, asset: str, margin_type: str) -> int:
"""
return the latest time when a repay was made on a defined asset
If None, return the millistamp corresponding to 2017/01/01
Expand Down Expand Up @@ -358,6 +387,15 @@ def get_loans(self, margin_type: str, asset: Optional[str] = None, start_time: O
:type end_time: Optional[int]
:return: The raw rows selected as saved in the database
:rtype: List[Tuple]
.. code-block:: python
[
(8289451654, # transaction id
1559415215400, # time
'USDT', # asset
145.5491462), # amount
]
"""
if margin_type == 'cross':
table = tables.CROSS_MARGIN_LOAN_TABLE
Expand All @@ -381,7 +419,7 @@ def get_loans(self, margin_type: str, asset: Optional[str] = None, start_time: O
end_time))
return self.get_conditions_rows(table, conditions_list=conditions_list)

def get_last_loan_time(self, asset: str, margin_type: str):
def get_last_loan_time(self, asset: str, margin_type: str) -> int:
"""
return the latest time when an loan was made on a defined asset
If None, return the millistamp corresponding to 2017/01/01
Expand Down Expand Up @@ -442,7 +480,7 @@ def get_lending_redemptions(self, lending_type: Optional[str] = None, asset: Opt
"""
return lending redemptions stored in the database. Asset type and time filters can be used
:param lending_type:fetch only redemptions from this lending type
:param lending_type: fetch only redemptions from this lending type
:type lending_type: Optional[str]
:param asset: fetch only redemptions from this asset
:type asset: Optional[str]
Expand All @@ -452,6 +490,15 @@ def get_lending_redemptions(self, lending_type: Optional[str] = None, asset: Opt
:type end_time: Optional[int]
:return: The raw rows selected as saved in the database
:rtype: List[Tuple]
.. code-block:: python
[
1612841562000, # time
'DAILY', # lending type
'LTC', # asset
1.89151684), # amount
]
"""
conditions_list = []
table = tables.LENDING_REDEMPTION_TABLE
Expand All @@ -473,7 +520,7 @@ def get_lending_redemptions(self, lending_type: Optional[str] = None, asset: Opt
end_time))
return self.get_conditions_rows(table, conditions_list=conditions_list)

def get_last_lending_redemption_time(self, lending_type: Optional[str] = None):
def get_last_lending_redemption_time(self, lending_type: Optional[str] = None) -> int:
"""
return the latest time when an lending redemption was made.
If None, return the millistamp corresponding to 2017/01/01
Expand Down Expand Up @@ -530,7 +577,7 @@ def get_lending_purchases(self, lending_type: Optional[str] = None, asset: Optio
"""
return lending purchases stored in the database. Asset type and time filters can be used
:param lending_type:fetch only purchases from this lending type
:param lending_type: fetch only purchases from this lending type
:type lending_type: Optional[str]
:param asset: fetch only purchases from this asset
:type asset: Optional[str]
Expand All @@ -540,6 +587,16 @@ def get_lending_purchases(self, lending_type: Optional[str] = None, asset: Optio
:type end_time: Optional[int]
:return: The raw rows selected as saved in the database
:rtype: List[Tuple]
.. code-block:: python
[
(58516828, # purchase id
1612841562000, # time
'DAILY', # lending type
'LTC', # asset
1.89151684), # amount
]
"""
conditions_list = []
table = tables.LENDING_PURCHASE_TABLE
Expand All @@ -561,7 +618,7 @@ def get_lending_purchases(self, lending_type: Optional[str] = None, asset: Optio
end_time))
return self.get_conditions_rows(table, conditions_list=conditions_list)

def get_last_lending_purchase_time(self, lending_type: Optional[str] = None):
def get_last_lending_purchase_time(self, lending_type: Optional[str] = None) -> int:
"""
return the latest time when an lending purchase was made.
If None, return the millistamp corresponding to 2017/01/01
Expand Down Expand Up @@ -616,7 +673,7 @@ def get_lending_interests(self, lending_type: Optional[str] = None, asset: Optio
"""
return lending interests stored in the database. Asset type and time filters can be used
:param lending_type:fetch only interests from this lending type
:param lending_type: fetch only interests from this lending type
:type lending_type: Optional[str]
:param asset: fetch only interests from this asset
:type asset: Optional[str]
Expand All @@ -626,6 +683,16 @@ def get_lending_interests(self, lending_type: Optional[str] = None, asset: Optio
:type end_time: Optional[int]
:return: The raw rows selected as saved in the database
:rtype: List[Tuple]
.. code-block:: python
[
(1619846515000, # time
'DAILY', # lending type
'DOT', # asset
0.00490156) # amount
]
"""
conditions_list = []
table = tables.LENDING_INTEREST_TABLE
Expand All @@ -647,7 +714,7 @@ def get_lending_interests(self, lending_type: Optional[str] = None, asset: Optio
end_time))
return self.get_conditions_rows(table, conditions_list=conditions_list)

def get_last_lending_interest_time(self, lending_type: Optional[str] = None):
def get_last_lending_interest_time(self, lending_type: Optional[str] = None) -> int:
"""
return the latest time when an interest was received.
If None, return the millistamp corresponding to 2017/01/01
Expand Down Expand Up @@ -680,7 +747,6 @@ def add_dust(self, tran_id: str, time: int, asset: str, asset_amount: float, bnb
auto_commit: bool = True):
"""
add dust operation to the database
https://binance-docs.github.io/apidocs/spot/en/#dustlog-user_data
:param tran_id: id of the transaction (non unique)
:type tran_id: str
Expand Down Expand Up @@ -716,6 +782,17 @@ def get_spot_dusts(self, asset: Optional[str] = None, start_time: Optional[int]
:type end_time: Optional[int]
:return: The raw rows selected as saved in the database
:rtype: List[Tuple]
.. code-block:: python
[
(82156485284, # transaction id
1605489113400, # time
'TRX', # asset
102.78415879, # asset amount
0.09084498, # bnb amount
0.00171514), # bnb fee
]
"""
conditions_list = []
table = tables.SPOT_DUST_TABLE
Expand Down Expand Up @@ -766,6 +843,16 @@ def get_spot_dividends(self, asset: Optional[str] = None, start_time: Optional[i
:type end_time: Optional[int]
:return: The raw rows selected as saved in the database
:rtype: List[Tuple]
.. code-block:: python
[
(8945138941, # dividend id
1594513589000, # time
'TRX', # asset
0.18745654), # amount
]
"""
conditions_list = []
table = tables.SPOT_DIVIDEND_TABLE
Expand Down Expand Up @@ -842,6 +929,18 @@ def get_spot_withdraws(self, asset: Optional[str] = None, start_time: Optional[i
:type end_time: Optional[int]
:return: The raw rows selected as saved in the database
:rtype: List[Tuple]
.. code-block:: python
[
('84984dcqq5z11gyjfa', # withdraw id
'aazd8949vredqs56dz', # transaction id
1599138389000, # withdraw time
'XTZ', # asset
57.0194, # amount
0.5), # fee
]
"""
conditions_list = []
table = tables.SPOT_WITHDRAW_TABLE
Expand Down Expand Up @@ -912,6 +1011,16 @@ def get_spot_deposits(self, asset: Optional[str] = None, start_time: Optional[in
:type end_time: Optional[int]
:return: The raw rows selected as saved in the database
:rtype: List[Tuple]
.. code-block:: python
[
('azdf5e6a1d5z', # transaction id
1589479004000, # deposit time
'LTC', # asset
14.25), # amount
]
"""
conditions_list = []
table = tables.SPOT_DEPOSIT_TABLE
Expand All @@ -934,7 +1043,8 @@ def get_last_spot_deposit_time(self) -> int:
fetch the latest time a deposit has been made on the spot account. If None is found, return the millistamp
corresponding to 2017/1/1
:return:
:return: last deposit millistamp
:rtype: int
"""
table = tables.SPOT_DEPOSIT_TABLE
selection = f"MAX({table.insertTime})"
Expand Down Expand Up @@ -971,7 +1081,7 @@ def add_trade(self, trade_type: str, trade_id: int, trade_time: int, asset: str,
:type price: float
:param fee: amount kept by the exchange
:type fee: float
:param fee_asset:token unit for the fee
:param fee_asset: token unit for the fee
:type fee_asset: str
:param is_buyer: if the trade is a buy or a sell
:type is_buyer: bool
Expand Down Expand Up @@ -1006,6 +1116,21 @@ def get_trades(self, trade_type: str, start_time: Optional[int] = None, end_time
:type ref_asset: Optional[str]
:return: The raw rows selected as saved in the database
:rtype: List[Tuple]
.. code-block:: python
[
(384518832, # trade_id
1582892988052, # trade time
'BTC', # asset
'USDT', # ref asset
0.0015, # asset quantity
9011.2, # asset price to ref asset
0.01425, # fee
'USDT', # fee asset
0), # is_buyer
]
"""
if trade_type == 'spot':
table = tables.SPOT_TRADE_TABLE
Expand Down
Loading

0 comments on commit 3b043d3

Please sign in to comment.