def order_cancel(order_id=None): timestamp = my_functions.get_current_timestamp() params = { 'order_id': order_id, 'timestamp': timestamp, } params_string = my_functions.generate_params_string(params) sign = my_functions.generate_hmac_sha256_hex(global_constant.secret_key, params_string) url = '{}/open-api/order/cancel'.format(global_constant.server_base_url) params['api_key'] = global_constant.api_key params['sign'] = sign try: r = requests.post(url=url, params=params) formatted_string = r.text.replace("'", '"') rows = json.loads(formatted_string) return rows # return json.dumps(rows) except: return {'ret_msg': 'error'}
def predicted_funding_rate_fee(symbol=None): timestamp = my_functions.get_current_timestamp() params = { 'symbol': symbol, 'timestamp': timestamp, } params_string = my_functions.generate_params_string(params) sign = my_functions.generate_hmac_sha256_hex(global_constant.secret_key, params_string) url = '{}/open-api/funding/predicted-funding'.format( global_constant.server_base_url) params['api_key'] = global_constant.api_key params['sign'] = sign try: r = requests.get(url=url, params=params) formatted_string = r.text.replace("'", '"') rows = json.loads(formatted_string) return rows # return json.dumps(rows) except: return {'ret_msg': 'error'}
def position_change(margin=None, symbol=None): timestamp = my_functions.get_current_timestamp() params = { 'margin': margin, 'symbol': symbol, 'timestamp': timestamp, } params_string = my_functions.generate_params_string(params) sign = my_functions.generate_hmac_sha256_hex(global_constant.secret_key, params_string) url = '{}/position/change-position-margin'.format( global_constant.server_base_url) params['api_key'] = global_constant.api_key params['sign'] = sign try: r = requests.post(url=url, params=params) formatted_string = r.text.replace("'", '"') rows = json.loads(formatted_string) return rows # return json.dumps(rows) except: return {'ret_msg': 'error'}
def on_ws_open(ws): my_functions.eprint("### opened ###") expires = my_functions.get_current_timestamp() signature_param = 'GET/realtime{}'.format(expires) signature = my_functions.generate_hmac_sha256_hex( global_constant.secret_key, signature_param) params = { 'op': 'auth', 'args': [global_constant.api_key, expires, signature] } ws_query = json.dumps(params) ws.send(ws_query) # ws.send('{"op":"subscribe","args":["position"]}') ws.send('{"op": "subscribe", "args": ["orderBook25.BTCUSD"]}')
def stop_order_create(base_price=None, order_link_id=None, order_type=None, price=None, qty=None, side=None, symbol=None, stop_px=None, time_in_force=None): timestamp = my_functions.get_current_timestamp() params = { 'base_price': base_price, 'order_link_id': order_link_id, 'order_type': order_type, 'price': price, 'qty': qty, 'side': side, 'stop_px': stop_px, 'symbol': symbol, 'time_in_force': time_in_force, 'timestamp': timestamp, } params_string = my_functions.generate_params_string(params) sign = my_functions.generate_hmac_sha256_hex(global_constant.secret_key, params_string) url = '{}/open-api/stop-order/create'.format( global_constant.server_base_url) params['api_key'] = global_constant.api_key params['sign'] = sign try: r = requests.post(url=url, params=params) formatted_string = r.text.replace("'", '"') rows = json.loads(formatted_string) return rows # return json.dumps(rows) except: return {'ret_msg': 'error'}
def order_list(order_id=None, order_link_id=None, symbol=None, sort=None, order=None, page=None, limit=None, order_status=None): timestamp = my_functions.get_current_timestamp() params = { 'limit': limit, 'order': order, 'order_id': order_id, 'order_link_id': order_link_id, 'order_status': order_status, 'page': page, 'sort': sort, 'symbol': symbol, 'timestamp': timestamp, } params_string = my_functions.generate_params_string(params) sign = my_functions.generate_hmac_sha256_hex(global_constant.secret_key, params_string) url = '{}/open-api/order/list'.format(global_constant.server_base_url) params['api_key'] = global_constant.api_key params['sign'] = sign try: r = requests.get(url=url, params=params) formatted_string = r.text.replace("'", '"') rows = json.loads(formatted_string) return rows # return json.dumps(rows) except: return {'ret_msg': 'error'}