Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- URL = "https://api.bitso.com"
- API_KEY = api_key
- API_SECRET = api_secret
- HTTPmethod = "POST"
- RequestPath = f"/v3/orders/"
- nonce = str(int(round(time.time() * 9000)))
- print("Select Type of Order:")
- type_order_options = int(input("\n1) MARKET \n2) LIMIT \n >"))
- if type_order_options == 1:
- type_order = "market"
- elif type_order_options == 2:
- type_order = "limit"
- if type_order == "market":
- book_order = str(input("\nEnter Book:"))
- major_order = str(input("\nEnter Major:"))
- minor_order = str(input("\nEnter Minor:"))
- side_order = str(input("\nEnter Side Order:"))
- elif type_order == "limit":
- book_order = str(input("\nEnter Book:"))
- major_order = str(input("\nEnter Major:"))
- minor_order = str(input("\nEnter Minor:"))
- price_order = str(input("\nEnter Price Order:"))
- side_order = str(input("\nEnter Side Order:"))
- stop_order = str(input("\nEnter Stop Order:"))
- print("Time in Force:")
- time_in_force_options = int(
- input("\n1) goodtillcancelled \n2) fillorkill \n3) immediateorcancel \n4) postonly \n5) SKIP \n >"))
- if time_in_force_options == 1:
- time_in_force_order = "goodtillcancelled"
- elif time_in_force_options == 2:
- time_in_force_options = "fillorkill"
- elif time_in_force_options == 3:
- time_in_force_options = "immediateorcancel"
- elif time_in_force_options == 4:
- time_in_force_options = "postonly"
- elif time_in_force_options == 5:
- time_in_force_options = ""
- if minor_order == '':
- parameters = {'book': book_order, 'major': major_order, 'price': price_order,
- 'side': side_order, 'time_in_force_order': time_in_force_options, "type": type_order}
- elif major_order == '':
- parameters = {'book': book_order, 'minor': major_order, 'price': price_order,
- 'side': side_order, 'time_in_force_order': time_in_force_options, "type": type_order}
- concat_string = nonce + HTTPmethod + RequestPath
- if HTTPmethod == "POST":
- concat_string += json.dumps(parameters)
- signature = hmac.new(API_SECRET.encode('utf-8'), concat_string.encode('utf-8'),
- hashlib.sha256).hexdigest()
- AUTH_HEADER = 'Bitso %s:%s:%s' % (API_KEY, nonce, signature)
- headers = {"Authorization": AUTH_HEADER}
- if HTTPmethod == "GET":
- response = requests.get(URL + RequestPath, headers=headers)
- elif HTTPmethod == "POST":
- response = requests.post(URL + RequestPath, json=parameters, headers=headers)
- data = response.json()
- {'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