Advertisement
monchimon00

Untitled

Mar 8th, 2024
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. URL = "https://api.bitso.com"
  2. API_KEY = api_key
  3. API_SECRET = api_secret
  4. HTTPmethod = "POST"
  5. RequestPath = f"/v3/orders/"
  6. nonce = str(int(round(time.time() * 9000)))
  7. print("Select Type of Order:")
  8. type_order_options = int(input("\n1) MARKET \n2) LIMIT \n >"))
  9. if type_order_options == 1:
  10. type_order = "market"
  11. elif type_order_options == 2:
  12. type_order = "limit"
  13. if type_order == "market":
  14. book_order = str(input("\nEnter Book:"))
  15. major_order = str(input("\nEnter Major:"))
  16. minor_order = str(input("\nEnter Minor:"))
  17. side_order = str(input("\nEnter Side Order:"))
  18. elif type_order == "limit":
  19. book_order = str(input("\nEnter Book:"))
  20. major_order = str(input("\nEnter Major:"))
  21. minor_order = str(input("\nEnter Minor:"))
  22. price_order = str(input("\nEnter Price Order:"))
  23. side_order = str(input("\nEnter Side Order:"))
  24. stop_order = str(input("\nEnter Stop Order:"))
  25. print("Time in Force:")
  26. time_in_force_options = int(
  27. input("\n1) goodtillcancelled \n2) fillorkill \n3) immediateorcancel \n4) postonly \n5) SKIP \n >"))
  28. if time_in_force_options == 1:
  29. time_in_force_order = "goodtillcancelled"
  30. elif time_in_force_options == 2:
  31. time_in_force_options = "fillorkill"
  32. elif time_in_force_options == 3:
  33. time_in_force_options = "immediateorcancel"
  34. elif time_in_force_options == 4:
  35. time_in_force_options = "postonly"
  36. elif time_in_force_options == 5:
  37. time_in_force_options = ""
  38. if minor_order == '':
  39. parameters = {'book': book_order, 'major': major_order, 'price': price_order,
  40. 'side': side_order, 'time_in_force_order': time_in_force_options, "type": type_order}
  41. elif major_order == '':
  42. parameters = {'book': book_order, 'minor': major_order, 'price': price_order,
  43. 'side': side_order, 'time_in_force_order': time_in_force_options, "type": type_order}
  44. concat_string = nonce + HTTPmethod + RequestPath
  45. if HTTPmethod == "POST":
  46. concat_string += json.dumps(parameters)
  47. signature = hmac.new(API_SECRET.encode('utf-8'), concat_string.encode('utf-8'),
  48. hashlib.sha256).hexdigest()
  49.  
  50. AUTH_HEADER = 'Bitso %s:%s:%s' % (API_KEY, nonce, signature)
  51. headers = {"Authorization": AUTH_HEADER}
  52. if HTTPmethod == "GET":
  53. response = requests.get(URL + RequestPath, headers=headers)
  54. elif HTTPmethod == "POST":
  55. response = requests.post(URL + RequestPath, json=parameters, headers=headers)
  56. data = response.json()
  57.  
  58.  
  59.  
  60. {'success': False, 'error': {'code': '0207', 'message': 'Cannot perform request - nonce must be higher than 211103815062988512'}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement