From ad2147b281f8da25057710d381513927522ef9b0 Mon Sep 17 00:00:00 2001 From: rhettre Date: Sat, 27 Aug 2022 17:43:56 -0500 Subject: [PATCH] Gas Fee Estimation Adds functionality to estimate gas fees for ETH and ERC-20 withdrawal --- README.md | 4 ++++ gemini/private_client.py | 19 +++++++++++++++++++ tests/test_private_client.py | 7 ++++++- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 00cb15a..356922e 100644 --- a/README.md +++ b/README.md @@ -125,6 +125,10 @@ r.create_deposit_address("BTCUSD", label="Main Bitcoin Address") ```python r.withdraw_to_address("ETH", "0x0287b1B0032Dc42c16640F71BA06F1A87C3a7101", "20") ``` +- [gas_fee_estimation](https://docs.gemini.com/rest-api/#gas-fee-estimation) +```python +r.gas_fee_estimation("ETH", "0x0287b1B0032Dc42c16640F71BA06F1A87C3a7101", "20") +``` - [revive_hearbeat](https://docs.gemini.com/rest-api/#ticker) ```python r.revive_hearbeat() diff --git a/gemini/private_client.py b/gemini/private_client.py index 690d049..d9f4905 100644 --- a/gemini/private_client.py +++ b/gemini/private_client.py @@ -335,6 +335,25 @@ def withdraw_to_address(self, currency, address, amount): "amount": amount } return self.api_query('/v1/withdraw/{}'.format(currency), payload) + + @typeassert(currency=str, address=str, amount=str) + def gas_fee_estimation (self, currency, address, amount): + """ + This will allow you to estimate gas fees given a currency, address, and amount + + Args: + currency(str): ETH/AAVE etc see Symbols and Minimums Page: https://docs.gemini.com/rest-api/?python#symbols-and-minimums + address(str): The address you want the money to be sent to + amount(str): Amount you want to transfer + + Results: + dict: A dict of the following fields: currency, fee, isOverride, monthlyLimit, monthlyRemaining + """ + payload = { + "address": address, + "amount": amount + } + return self.api_query('/v1/withdraw/{}/feeEstimate'.format(currency), payload) # Transfers API @typeassert(limit_transfers=int, show_completed_deposit_advances=bool) diff --git a/tests/test_private_client.py b/tests/test_private_client.py index 0598c95..a46ea95 100644 --- a/tests/test_private_client.py +++ b/tests/test_private_client.py @@ -151,7 +151,12 @@ def test_withdraw_to_address(self): r = PrivateClient("PUBLIC_KEY", "PRIVATE_CLIENT") withdraw_to_address = r.withdraw_to_address("ETH", "200", "0x0287b1B0032Dc42c16640F71BA06F1A87C3a7101") assert type(withdraw_to_address) is dict - + + def gas_fee_estimation(self): + r = PrivateClient("PUBLIC_KEY", "PRIVATE_CLIENT") + gas_fee_estimation = r.gas_fee_estimation("ETH", "200", "0x0287b1B0032Dc42c16640F71BA06F1A87C3a7101") + assert type(gas_fee_estimation) is dict + def test_revive_heartbeat(self): r = client() revive_hearbeat = r.revive_hearbeat()