2
2
import asyncio
3
3
import itertools
4
4
import time
5
- from typing import TYPE_CHECKING , Any , Dict , List , Optional
5
+ from typing import TYPE_CHECKING , Any , Dict , List , Optional , Tuple
6
6
7
7
import pandas as pd
8
8
13
13
from hummingbot .client .ui .completer import load_completer
14
14
from hummingbot .client .ui .interface_utils import format_df_for_printout
15
15
from hummingbot .connector .connector_status import get_connector_status
16
- from hummingbot .core .gateway import docker_ipc , get_gateway_paths
16
+ from hummingbot .core .gateway import get_gateway_paths
17
17
from hummingbot .core .gateway .gateway_http_client import GatewayHttpClient
18
18
from hummingbot .core .gateway .gateway_status_monitor import GatewayStatus
19
19
from hummingbot .core .utils .async_utils import safe_ensure_future
@@ -68,11 +68,6 @@ def gateway_config(self,
68
68
else :
69
69
safe_ensure_future (self ._show_gateway_configuration (key ), loop = self .ev_loop )
70
70
71
- @staticmethod
72
- async def check_gateway_image (docker_repo : str , docker_tag : str ) -> bool :
73
- image_list : List = await docker_ipc ("images" , name = f"{ docker_repo } :{ docker_tag } " , quiet = True )
74
- return len (image_list ) > 0
75
-
76
71
async def _test_connection (self ):
77
72
# test that the gateway is running
78
73
if await self ._get_gateway_instance ().ping_gateway ():
@@ -103,26 +98,6 @@ async def _generate_certs(
103
98
self .notify (f"Gateway SSL certification files are created in { certs_path } ." )
104
99
self ._get_gateway_instance ().reload_certs (self .client_config_map )
105
100
106
- async def _generate_gateway_confs (
107
- self , # type: HummingbotApplication
108
- container_id : str , conf_path : str = "/usr/src/app/conf"
109
- ):
110
- try :
111
- cmd : str = f"./setup/generate_conf.sh { conf_path } "
112
- exec_info = await docker_ipc (method_name = "exec_create" ,
113
- container = container_id ,
114
- cmd = cmd ,
115
- user = "hummingbot" )
116
-
117
- await docker_ipc (method_name = "exec_start" ,
118
- exec_id = exec_info ["Id" ],
119
- detach = True )
120
- return
121
- except asyncio .CancelledError :
122
- raise
123
- except Exception :
124
- raise
125
-
126
101
async def ping_gateway_api (self , max_wait : int ) -> bool :
127
102
"""
128
103
Try to reach the gateway API for up to max_wait seconds
@@ -139,35 +114,7 @@ async def ping_gateway_api(self, max_wait: int) -> bool:
139
114
140
115
return True
141
116
142
- async def ping_gateway_docker_and_api (self , max_wait : int ) -> bool :
143
- """
144
- Try to reach the docker and then the gateway API for up to max_wait seconds
145
- """
146
- now = int (time .time ())
147
- docker_live = await self .ping_gateway_docker ()
148
- while not docker_live :
149
- later = int (time .time ())
150
- if later - now > max_wait :
151
- return False
152
- await asyncio .sleep (0.5 )
153
- docker_live = await self .ping_gateway_docker ()
154
-
155
- return await self .ping_gateway_api (max_wait )
156
-
157
- async def ping_gateway_docker (self ) -> bool :
158
- try :
159
- await docker_ipc ("version" )
160
- return True
161
- except Exception :
162
- return False
163
-
164
117
async def _gateway_status (self ):
165
- can_reach_docker = await self .ping_gateway_docker ()
166
- if not can_reach_docker :
167
- self .notify ("\n Error: It looks like you do not have Docker installed or running. Gateway commands will not "
168
- "work without it. Please install or start Docker and restart Hummingbot." )
169
- return
170
-
171
118
if self ._gateway_monitor .gateway_status is GatewayStatus .ONLINE :
172
119
try :
173
120
status = await self ._get_gateway_instance ().get_gateway_status ()
@@ -232,7 +179,10 @@ async def _gateway_connect(
232
179
available_networks : List [Dict [str , Any ]] = connector_config [0 ]["available_networks" ]
233
180
trading_type : str = connector_config [0 ]["trading_type" ][0 ]
234
181
additional_spenders : List [str ] = connector_config [0 ].get ("additional_spenders" , [])
235
- additional_prompts : Dict [str , str ] = connector_config [0 ].get ("additional_add_wallet_prompts" , {})
182
+ additional_prompts : Dict [str , str ] = connector_config [0 ].get ( # These will be stored locally.
183
+ "additional_add_wallet_prompts" , # If Gateway requires additional, prompts with secure info,
184
+ {} # a new attribute must be added (e.g. additional_secure_add_wallet_prompts)
185
+ )
236
186
237
187
# ask user to select a chain. Automatically select if there is only one.
238
188
chains : List [str ] = [d ['chain' ] for d in available_networks ]
@@ -286,7 +236,7 @@ async def _gateway_connect(
286
236
287
237
# if the user has no wallet, ask them to select one
288
238
if len (wallets ) < 1 or chain == "near" or len (additional_prompts ) != 0 :
289
- wallet_address = await self ._prompt_for_wallet_address (
239
+ wallet_address , additional_prompt_values = await self ._prompt_for_wallet_address (
290
240
chain = chain , network = network , additional_prompts = additional_prompts
291
241
)
292
242
@@ -311,9 +261,13 @@ async def _gateway_connect(
311
261
wallet_table : List [Dict [str , Any ]] = []
312
262
for w in wallets :
313
263
balances : Dict [str , Any ] = await self ._get_gateway_instance ().get_balances (
314
- chain , network , w , [native_token ]
264
+ chain , network , w , [native_token ], connector
265
+ )
266
+ balance = (
267
+ balances ['balances' ].get (native_token )
268
+ or balances ['balances' ]['total' ].get (native_token )
315
269
)
316
- wallet_table .append ({"balance" : balances [ 'balances' ][ native_token ] , "address" : w })
270
+ wallet_table .append ({"balance" : balance , "address" : w })
317
271
318
272
wallet_df : pd .DataFrame = build_wallet_display (native_token , wallet_table )
319
273
self .notify (wallet_df .to_string (index = False ))
@@ -332,7 +286,7 @@ async def _gateway_connect(
332
286
else :
333
287
while True :
334
288
try :
335
- wallet_address = await self ._prompt_for_wallet_address (
289
+ wallet_address , additional_prompt_values = await self ._prompt_for_wallet_address (
336
290
chain = chain , network = network , additional_prompts = additional_prompts
337
291
)
338
292
break
@@ -342,16 +296,24 @@ async def _gateway_connect(
342
296
# display wallet balance
343
297
native_token : str = native_tokens [chain ]
344
298
balances : Dict [str , Any ] = await self ._get_gateway_instance ().get_balances (
345
- chain , network , wallet_address , [native_token ]
299
+ chain , network , wallet_address , [native_token ], connector
346
300
)
347
- wallet_table : List [Dict [str , Any ]] = [{"balance" : balances ['balances' ][ native_token ] , "address" : wallet_address }]
301
+ wallet_table : List [Dict [str , Any ]] = [{"balance" : balances ['balances' ]. get ( native_token ) or balances [ 'balances' ][ 'total' ]. get ( native_token ) , "address" : wallet_address }]
348
302
wallet_df : pd .DataFrame = build_wallet_display (native_token , wallet_table )
349
303
self .notify (wallet_df .to_string (index = False ))
350
304
351
305
self .app .clear_input ()
352
306
353
307
# write wallets to Gateway connectors settings.
354
- GatewayConnectionSetting .upsert_connector_spec (connector , chain , network , trading_type , wallet_address , additional_spenders )
308
+ GatewayConnectionSetting .upsert_connector_spec (
309
+ connector_name = connector ,
310
+ chain = chain ,
311
+ network = network ,
312
+ trading_type = trading_type ,
313
+ wallet_address = wallet_address ,
314
+ additional_spenders = additional_spenders ,
315
+ additional_prompt_values = additional_prompt_values ,
316
+ )
355
317
self .notify (f"The { connector } connector now uses wallet { wallet_address } on { chain } -{ network } " )
356
318
357
319
# update AllConnectorSettings and fee overrides.
@@ -369,7 +331,7 @@ async def _prompt_for_wallet_address(
369
331
chain : str ,
370
332
network : str ,
371
333
additional_prompts : Dict [str , str ],
372
- ) -> Optional [str ]:
334
+ ) -> Tuple [ Optional [str ], Dict [ str , str ] ]:
373
335
self .app .clear_input ()
374
336
self .placeholder_mode = True
375
337
wallet_private_key = await self .app .prompt (
@@ -392,7 +354,7 @@ async def _prompt_for_wallet_address(
392
354
return
393
355
394
356
for field , prompt in additional_prompts .items ():
395
- value = await self .app .prompt (prompt = prompt )
357
+ value = await self .app .prompt (prompt = prompt , is_password = True )
396
358
self .app .clear_input ()
397
359
if self .app .to_stop_config :
398
360
return
@@ -402,7 +364,7 @@ async def _prompt_for_wallet_address(
402
364
chain , network , wallet_private_key , ** additional_prompt_values
403
365
)
404
366
wallet_address : str = response ["address" ]
405
- return wallet_address
367
+ return wallet_address , additional_prompt_values
406
368
407
369
async def _show_gateway_connector_tokens (
408
370
self , # type: HummingbotApplication
0 commit comments