Guest User

Untitled

a guest
Dec 10th, 2018
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. import json
  2. import websocket
  3. import logging
  4. logging.basicConfig()
  5.  
  6. nextIvalue = 0
  7.  
  8. def call_service(ws, service_name, data, level=0):
  9. global nextIvalue
  10. frame = {
  11. 'm': level,
  12. 'i': nextIvalue,
  13. 'n': service_name,
  14. 'o': json.dumps(data)
  15. }
  16. nextIvalue += 2
  17. str = json.dumps(frame)
  18. print '< %s' % str
  19. ws.send(str)
  20.  
  21. def on_error(ws, error):
  22. print('!> %s' % error)
  23.  
  24. def show_info(ws, data):
  25. print('> %s' % data)
  26. ws.close()
  27.  
  28. def get_info(ws, data):
  29. auth = json.loads(json.loads(data)['o'])
  30. if (auth['Authenticated']):
  31. ws.on_message = show_info
  32. # Escolha as permissões que você deseja dar a esta chave.
  33. # Você pode criar várias chaves. Por exemplo, uma apenas com opções de depósito e trading
  34. call_service(ws, 'AddUserAPIKey', {'UserId': auth['UserId'], 'Permissions': ['Trading', 'Withdraw', 'Deposit']})
  35. else:
  36. ws.close()
  37.  
  38. def start_talking(ws):
  39. ws.on_message = get_info
  40. call_service(ws, 'WebAuthenticateUser', {
  41. 'UserName': 'your@email.com',
  42. 'Password': 'your-password'
  43. })
  44.  
  45. def main():
  46. ws = websocket.WebSocketApp('wss://api.coinext.com.br/WSGateway/',
  47. on_error=on_error,
  48. on_open=start_talking)
  49. ws.run_forever()
  50.  
  51. if __name__ == "__main__":
  52. main()
Add Comment
Please, Sign In to add comment