else: order_id = trading_data.exec_order(base + quote, 'buy', 'market', amount) if order_id is not None: order_info = trading_data.get_order_info(order_id) else: print("order does not success ") exec_state = 0 max_profit = -1 time.sleep(0.1) except Exception as ex: print(traceback.format_exc()) bal_lock = Thread.Lock() bal = {} tract_done = False amount_list = [] def trading(dir_from, dir_to, tid, limit): global amount_list, bal,bal_lock, trading_data while (True): balance = 0 with bal_lock: balance = bal[dir_from] base = '' quote = '' for idx, row in pairs.iterrows(): if row['name'] == (dir_from + dir_to) or row['name'] == (dir_to + dir_from): base = row['base_currency']
def deposit(balance, lock): for i in range(100): time.sleep(0.01) lock.acquire() balance.value = balance.value + 1 lock.release() def withdraw(balance, lock): for i in range(100): time.sleep(0.01) lock.acquire() balance.value = balance.value - 1 lock.release() if __name__ == '__main__': balance = Thread.value('i', 200) lock = Thread.Lock() t1 = Thread(name='deposit_thread', target=deposit, args=(balance, lock)) t2 = Thread(name='withdraw_thread', target=withdraw, args=(balance, lock)) t1.start() t2.start() t1.join() t2.join() print("Thankuuuuuuu..............")