Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: multiprocessing in initialize_trade_thresholds #6

Closed
josefigueredo opened this issue Jan 8, 2021 · 1 comment
Closed

Feature: multiprocessing in initialize_trade_thresholds #6

josefigueredo opened this issue Jan 8, 2021 · 1 comment

Comments

@josefigueredo
Copy link

First of all thanks for sharing the project.

When I add a lot of alt coins the initialize_trade_thresholds is very slow. I added multi core support to speed it a little. Hope you find it useful.

import multiprocessing as mp

def get_coin_value(client, coin_dict, coin):
    coin_dict_price = float(get_market_ticker_price(client, coin_dict + 'USDT'))
    coin_price = float(get_market_ticker_price(client, coin + 'USDT'))
    return coin_dict, coin, coin_dict_price / coin_price

def add_coin(results):
    coin_dict = results[0]
    coin = results[1]
    price = results[2]
    g_state.coin_table[coin_dict][coin] = price

def initialize_trade_thresholds(client):
    '''
    Initialize the buying threshold of all the coins for trading between them
    '''
    global g_state
    
    pool = mp.Pool(processes=14) # core count - 2
    for coin_dict in g_state.coin_table.copy():
        for coin in supported_coin_list:
            if coin != coin_dict:
                pool.apply_async(get_coin_value, args = (client, coin_dict, coin, ), callback = add_coin)
    pool.close()
    pool.join()

    with open(g_state._table_backup_file, "w") as backup_file:
        json.dump(g_state.coin_table, backup_file)
@edeng23
Copy link
Owner

edeng23 commented Jan 8, 2021

Looks good :)
Do you mind opening a pull request?

@edeng23 edeng23 closed this as completed Jan 10, 2021
bobwng pushed a commit to bobwng/binance-trade-bot that referenced this issue Jul 7, 2021
fix: (ratio_adjust) use max 500 candles to init ratios
Knifa pushed a commit to Knifa/binance-trade-bot that referenced this issue Aug 2, 2021
Build locally in Docker compose and disable garbage
shroukkhan pushed a commit to shroukkhan/binance-trade-bot that referenced this issue Aug 1, 2023
python Import Error: cannot import name 'BaseResponse' from 'werkzeug.wrappers' and cannot import name 'escape' from 'jinja2'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants