|
@@ -86,19 +86,63 @@ def depot():
|
|
|
print(tabulate(response['data'], headers=['Object', 'Amount'], tablefmt="pipe"))
|
|
|
else:
|
|
|
if 'error_message' in response:
|
|
|
- print('Login failed with message:', response['error_message'])
|
|
|
+ print('Depot access failed with message:', response['error_message'])
|
|
|
else:
|
|
|
- print('Login failed.')
|
|
|
+ print('Depot access failed.')
|
|
|
|
|
|
|
|
|
def activate_key(key=''):
|
|
|
- if key is '':
|
|
|
+ if key == '':
|
|
|
print('Entering a game key may get you some money or other useful stuff.')
|
|
|
key = input('Key: ')
|
|
|
|
|
|
- if key is '':
|
|
|
+ if key == '':
|
|
|
print('Invalid key.')
|
|
|
|
|
|
response = client_request('activate_key', {"session_id": connection.session_id, 'key':key })
|
|
|
if 'error_message' in response:
|
|
|
- print('Key activation failed with message:', response['error_message'])
|
|
|
+ print('Key activation failed with message:', response['error_message'])
|
|
|
+
|
|
|
+
|
|
|
+def yn_dialog(msg):
|
|
|
+ while True:
|
|
|
+ result = input(msg + ' [y/n]: ')
|
|
|
+ if result == 'y':
|
|
|
+ return True
|
|
|
+ if result == 'n':
|
|
|
+ return False
|
|
|
+
|
|
|
+
|
|
|
+def buy(amount=None, object_name=None, limit='', stop_loss=''):
|
|
|
+ if object_name is None: # TODO list some available objects
|
|
|
+ object_name = input('Name of object to buy: ')
|
|
|
+ if amount is None:
|
|
|
+ print('Entering a game key may get you some money or other useful stuff.')
|
|
|
+ amount = input('Amount: ')
|
|
|
+ if limit != '':
|
|
|
+ set_limit = yn_dialog('Do you want to place a limit?')
|
|
|
+ if set_limit:
|
|
|
+ limit = input('Limit: ')
|
|
|
+ stop_loss = yn_dialog('Is this a stop-loss limit?')
|
|
|
+ response = client_request('order', {"buy": True,
|
|
|
+ "session_id": connection.session_id,
|
|
|
+ "amount":amount,
|
|
|
+ "ownable": object_name,
|
|
|
+ "limit": limit,
|
|
|
+ "stop_loss": stop_loss})
|
|
|
+ if 'error_message' in response:
|
|
|
+ print('Order placement failed with message:', response['error_message'])
|
|
|
+
|
|
|
+
|
|
|
+def orders():
|
|
|
+ response = client_request('orders', {"session_id": connection.session_id})
|
|
|
+ success = 'data' in response
|
|
|
+ if success:
|
|
|
+ print(tabulate(response['data'],
|
|
|
+ headers=['Buy?', 'Name', 'Amount', 'Limit', 'Stop Loss?', 'Orig. Order Size'],
|
|
|
+ tablefmt="pipe"))
|
|
|
+ else:
|
|
|
+ if 'error_message' in response:
|
|
|
+ print('Order access failed with message:', response['error_message'])
|
|
|
+ else:
|
|
|
+ print('Order access failed.')
|