Skip to content

Commit 3b043d3

Browse files
authored
Docs (#21) (#22)
* 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
1 parent e3dc1b0 commit 3b043d3

File tree

13 files changed

+508
-123
lines changed

13 files changed

+508
-123
lines changed

BinanceWatch/BinanceManager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def update_universal_transfers(self, transfer_filter: Optional[str] = None):
8484
pbar = tqdm(total=len(transfers_types))
8585
for transfer_type in transfers_types:
8686
pbar.set_description(f"fetching transfer type {transfer_type}")
87-
latest_time = self.db.get_last_universal_transfer(transfer_type=transfer_type) + 1
87+
latest_time = self.db.get_last_universal_transfer_time(transfer_type=transfer_type) + 1
8888
current = 1
8989
while True:
9090
universal_transfers = self.client.query_universal_transfer_history(type=transfer_type,

BinanceWatch/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
__version__ = "0.1.0"
1+
__version__ = "0.1.1"
22
__author__ = 'EtWnn'

BinanceWatch/storage/BinanceDataBase.py

Lines changed: 137 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,16 @@ def get_universal_transfers(self, transfer_type: Optional[str] = None, asset: Op
5454
:type end_time: Optional[int]
5555
:return: The raw rows selected as saved in the database
5656
:rtype: List[Tuple]
57+
58+
.. code-block:: python
59+
60+
[
61+
(1206491332, # transfer id
62+
'MAIN_MARGIN', # transfer type
63+
1589121841000, # time
64+
'BNB', # asset
65+
10.594112), # amount
66+
]
5767
"""
5868
table = tables.UNIVERSAL_TRANSFER_TABLE
5969

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

79-
def get_last_universal_transfer(self, transfer_type: str):
89+
def get_last_universal_transfer_time(self, transfer_type: str) -> int:
8090
"""
8191
return the latest time when a universal transfer was made
8292
If None, return the millistamp corresponding to 2017/01/01
@@ -148,6 +158,15 @@ def get_margin_interests(self, margin_type: str, asset: Optional[str] = None, st
148158
:type end_time: Optional[int]
149159
:return: The raw rows selected as saved in the database
150160
:rtype: List[Tuple]
161+
162+
.. code-block:: python
163+
164+
[
165+
1559415215400, # time
166+
'BNB', # asset
167+
0.51561, # interest
168+
'PERIODIC_CONVERTED'), # interest type
169+
]
151170
"""
152171
if margin_type == 'cross':
153172
table = tables.CROSS_MARGIN_INTEREST_TABLE
@@ -255,6 +274,16 @@ def get_repays(self, margin_type: str, asset: Optional[str] = None, start_time:
255274
:type end_time: Optional[int]
256275
:return: The raw rows selected as saved in the database
257276
:rtype: List[Tuple]
277+
278+
.. code-block:: python
279+
280+
[
281+
(8289451654, # transaction id
282+
1559415215400, # time
283+
'USDT', # asset
284+
145.5491462, # principal
285+
0.51561), # interest
286+
]
258287
"""
259288
if margin_type == 'cross':
260289
table = tables.CROSS_MARGIN_REPAY_TABLE
@@ -278,7 +307,7 @@ def get_repays(self, margin_type: str, asset: Optional[str] = None, start_time:
278307
end_time))
279308
return self.get_conditions_rows(table, conditions_list=conditions_list)
280309

281-
def get_last_repay_time(self, asset: str, margin_type: str):
310+
def get_last_repay_time(self, asset: str, margin_type: str) -> int:
282311
"""
283312
return the latest time when a repay was made on a defined asset
284313
If None, return the millistamp corresponding to 2017/01/01
@@ -358,6 +387,15 @@ def get_loans(self, margin_type: str, asset: Optional[str] = None, start_time: O
358387
:type end_time: Optional[int]
359388
:return: The raw rows selected as saved in the database
360389
:rtype: List[Tuple]
390+
391+
.. code-block:: python
392+
393+
[
394+
(8289451654, # transaction id
395+
1559415215400, # time
396+
'USDT', # asset
397+
145.5491462), # amount
398+
]
361399
"""
362400
if margin_type == 'cross':
363401
table = tables.CROSS_MARGIN_LOAN_TABLE
@@ -381,7 +419,7 @@ def get_loans(self, margin_type: str, asset: Optional[str] = None, start_time: O
381419
end_time))
382420
return self.get_conditions_rows(table, conditions_list=conditions_list)
383421

384-
def get_last_loan_time(self, asset: str, margin_type: str):
422+
def get_last_loan_time(self, asset: str, margin_type: str) -> int:
385423
"""
386424
return the latest time when an loan was made on a defined asset
387425
If None, return the millistamp corresponding to 2017/01/01
@@ -442,7 +480,7 @@ def get_lending_redemptions(self, lending_type: Optional[str] = None, asset: Opt
442480
"""
443481
return lending redemptions stored in the database. Asset type and time filters can be used
444482
445-
:param lending_type:fetch only redemptions from this lending type
483+
:param lending_type: fetch only redemptions from this lending type
446484
:type lending_type: Optional[str]
447485
:param asset: fetch only redemptions from this asset
448486
:type asset: Optional[str]
@@ -452,6 +490,15 @@ def get_lending_redemptions(self, lending_type: Optional[str] = None, asset: Opt
452490
:type end_time: Optional[int]
453491
:return: The raw rows selected as saved in the database
454492
:rtype: List[Tuple]
493+
494+
.. code-block:: python
495+
496+
[
497+
1612841562000, # time
498+
'DAILY', # lending type
499+
'LTC', # asset
500+
1.89151684), # amount
501+
]
455502
"""
456503
conditions_list = []
457504
table = tables.LENDING_REDEMPTION_TABLE
@@ -473,7 +520,7 @@ def get_lending_redemptions(self, lending_type: Optional[str] = None, asset: Opt
473520
end_time))
474521
return self.get_conditions_rows(table, conditions_list=conditions_list)
475522

476-
def get_last_lending_redemption_time(self, lending_type: Optional[str] = None):
523+
def get_last_lending_redemption_time(self, lending_type: Optional[str] = None) -> int:
477524
"""
478525
return the latest time when an lending redemption was made.
479526
If None, return the millistamp corresponding to 2017/01/01
@@ -530,7 +577,7 @@ def get_lending_purchases(self, lending_type: Optional[str] = None, asset: Optio
530577
"""
531578
return lending purchases stored in the database. Asset type and time filters can be used
532579
533-
:param lending_type:fetch only purchases from this lending type
580+
:param lending_type: fetch only purchases from this lending type
534581
:type lending_type: Optional[str]
535582
:param asset: fetch only purchases from this asset
536583
:type asset: Optional[str]
@@ -540,6 +587,16 @@ def get_lending_purchases(self, lending_type: Optional[str] = None, asset: Optio
540587
:type end_time: Optional[int]
541588
:return: The raw rows selected as saved in the database
542589
:rtype: List[Tuple]
590+
591+
.. code-block:: python
592+
593+
[
594+
(58516828, # purchase id
595+
1612841562000, # time
596+
'DAILY', # lending type
597+
'LTC', # asset
598+
1.89151684), # amount
599+
]
543600
"""
544601
conditions_list = []
545602
table = tables.LENDING_PURCHASE_TABLE
@@ -561,7 +618,7 @@ def get_lending_purchases(self, lending_type: Optional[str] = None, asset: Optio
561618
end_time))
562619
return self.get_conditions_rows(table, conditions_list=conditions_list)
563620

564-
def get_last_lending_purchase_time(self, lending_type: Optional[str] = None):
621+
def get_last_lending_purchase_time(self, lending_type: Optional[str] = None) -> int:
565622
"""
566623
return the latest time when an lending purchase was made.
567624
If None, return the millistamp corresponding to 2017/01/01
@@ -616,7 +673,7 @@ def get_lending_interests(self, lending_type: Optional[str] = None, asset: Optio
616673
"""
617674
return lending interests stored in the database. Asset type and time filters can be used
618675
619-
:param lending_type:fetch only interests from this lending type
676+
:param lending_type: fetch only interests from this lending type
620677
:type lending_type: Optional[str]
621678
:param asset: fetch only interests from this asset
622679
:type asset: Optional[str]
@@ -626,6 +683,16 @@ def get_lending_interests(self, lending_type: Optional[str] = None, asset: Optio
626683
:type end_time: Optional[int]
627684
:return: The raw rows selected as saved in the database
628685
:rtype: List[Tuple]
686+
687+
.. code-block:: python
688+
689+
[
690+
(1619846515000, # time
691+
'DAILY', # lending type
692+
'DOT', # asset
693+
0.00490156) # amount
694+
]
695+
629696
"""
630697
conditions_list = []
631698
table = tables.LENDING_INTEREST_TABLE
@@ -647,7 +714,7 @@ def get_lending_interests(self, lending_type: Optional[str] = None, asset: Optio
647714
end_time))
648715
return self.get_conditions_rows(table, conditions_list=conditions_list)
649716

650-
def get_last_lending_interest_time(self, lending_type: Optional[str] = None):
717+
def get_last_lending_interest_time(self, lending_type: Optional[str] = None) -> int:
651718
"""
652719
return the latest time when an interest was received.
653720
If None, return the millistamp corresponding to 2017/01/01
@@ -680,7 +747,6 @@ def add_dust(self, tran_id: str, time: int, asset: str, asset_amount: float, bnb
680747
auto_commit: bool = True):
681748
"""
682749
add dust operation to the database
683-
https://binance-docs.github.io/apidocs/spot/en/#dustlog-user_data
684750
685751
:param tran_id: id of the transaction (non unique)
686752
:type tran_id: str
@@ -716,6 +782,17 @@ def get_spot_dusts(self, asset: Optional[str] = None, start_time: Optional[int]
716782
:type end_time: Optional[int]
717783
:return: The raw rows selected as saved in the database
718784
:rtype: List[Tuple]
785+
786+
.. code-block:: python
787+
788+
[
789+
(82156485284, # transaction id
790+
1605489113400, # time
791+
'TRX', # asset
792+
102.78415879, # asset amount
793+
0.09084498, # bnb amount
794+
0.00171514), # bnb fee
795+
]
719796
"""
720797
conditions_list = []
721798
table = tables.SPOT_DUST_TABLE
@@ -766,6 +843,16 @@ def get_spot_dividends(self, asset: Optional[str] = None, start_time: Optional[i
766843
:type end_time: Optional[int]
767844
:return: The raw rows selected as saved in the database
768845
:rtype: List[Tuple]
846+
847+
.. code-block:: python
848+
849+
[
850+
(8945138941, # dividend id
851+
1594513589000, # time
852+
'TRX', # asset
853+
0.18745654), # amount
854+
]
855+
769856
"""
770857
conditions_list = []
771858
table = tables.SPOT_DIVIDEND_TABLE
@@ -842,6 +929,18 @@ def get_spot_withdraws(self, asset: Optional[str] = None, start_time: Optional[i
842929
:type end_time: Optional[int]
843930
:return: The raw rows selected as saved in the database
844931
:rtype: List[Tuple]
932+
933+
.. code-block:: python
934+
935+
[
936+
('84984dcqq5z11gyjfa', # withdraw id
937+
'aazd8949vredqs56dz', # transaction id
938+
1599138389000, # withdraw time
939+
'XTZ', # asset
940+
57.0194, # amount
941+
0.5), # fee
942+
]
943+
845944
"""
846945
conditions_list = []
847946
table = tables.SPOT_WITHDRAW_TABLE
@@ -912,6 +1011,16 @@ def get_spot_deposits(self, asset: Optional[str] = None, start_time: Optional[in
9121011
:type end_time: Optional[int]
9131012
:return: The raw rows selected as saved in the database
9141013
:rtype: List[Tuple]
1014+
1015+
.. code-block:: python
1016+
1017+
[
1018+
('azdf5e6a1d5z', # transaction id
1019+
1589479004000, # deposit time
1020+
'LTC', # asset
1021+
14.25), # amount
1022+
]
1023+
9151024
"""
9161025
conditions_list = []
9171026
table = tables.SPOT_DEPOSIT_TABLE
@@ -934,7 +1043,8 @@ def get_last_spot_deposit_time(self) -> int:
9341043
fetch the latest time a deposit has been made on the spot account. If None is found, return the millistamp
9351044
corresponding to 2017/1/1
9361045
937-
:return:
1046+
:return: last deposit millistamp
1047+
:rtype: int
9381048
"""
9391049
table = tables.SPOT_DEPOSIT_TABLE
9401050
selection = f"MAX({table.insertTime})"
@@ -971,7 +1081,7 @@ def add_trade(self, trade_type: str, trade_id: int, trade_time: int, asset: str,
9711081
:type price: float
9721082
:param fee: amount kept by the exchange
9731083
:type fee: float
974-
:param fee_asset:token unit for the fee
1084+
:param fee_asset: token unit for the fee
9751085
:type fee_asset: str
9761086
:param is_buyer: if the trade is a buy or a sell
9771087
:type is_buyer: bool
@@ -1006,6 +1116,21 @@ def get_trades(self, trade_type: str, start_time: Optional[int] = None, end_time
10061116
:type ref_asset: Optional[str]
10071117
:return: The raw rows selected as saved in the database
10081118
:rtype: List[Tuple]
1119+
1120+
.. code-block:: python
1121+
1122+
[
1123+
(384518832, # trade_id
1124+
1582892988052, # trade time
1125+
'BTC', # asset
1126+
'USDT', # ref asset
1127+
0.0015, # asset quantity
1128+
9011.2, # asset price to ref asset
1129+
0.01425, # fee
1130+
'USDT', # fee asset
1131+
0), # is_buyer
1132+
]
1133+
10091134
"""
10101135
if trade_type == 'spot':
10111136
table = tables.SPOT_TRADE_TABLE

0 commit comments

Comments
 (0)