diff --git a/hex b/hex index 2034a4c..250ee50 100755 --- a/hex +++ b/hex @@ -59,6 +59,10 @@ Options: --backup_postgresql, Run the full backup with pg_dumpall for the exchange PostgreSQL database. --flush_redis, Run the full flush of Redis stored data. It could be helpful in certain situation If the exchange doesnt work properly. --upgrade_api_only, Do zero-downtime rolling upgrade for API contianers on Kubernetes. + --add_coin, Add new currency on exchange. + --remove_coin, Remove exisiting currency from exhcnage. + --add_trading_pair, Add new trading pair on ehchange. + --remove_trading_pair, Remove existing trading pair from exchange. version : Print out current installed version of hex-cli. @@ -188,7 +192,7 @@ if [[ "$1" == 'dev' ]]; then # Running database jobs for local db. if [[ ! "$LOCAL_COMMAND" ]] && [[ "$LOCAL_DATABASE_INIT" == true ]]; then - local_database_init start; + local_database_init dev; exit 0; @@ -366,6 +370,42 @@ elif [[ "$1" == "launch" ]]; then source $SCRIPTPATH/tools_generator.sh load_config_variables; + # Check Activation code is available + if [[ ! "$HEX_SECRET_ACTIVATION_CODE" ]]; then + + echo "*** hex-cli failed to detect your activation code for the exchange. ***" + echo "*** Reading it manually... ***" + echo "What is your activation code?" + read activation_code + + echo "*** Your activation code is : $activation_code" + echo "*** Is the value correct? (y/n) ***" + read answer + + if [[ "$answer" = "${answer#[Yy]}" ]] ;then + echo "*** Exiting... ***" + exit 0; + fi + + for i in ${CONFIG_FILE_PATH[@]}; do + + if command grep -q "HEX_SECRET_ACTIVATION_CODE" $i > /dev/null ; then + SECRET_FILE_PATH=$i + sed -i.bak "s/HEX_SECRET_ACTIVATION_CODE=$HEX_SECRET_ACTIVATION_CODE/HEX_SECRET_ACTIVATION_CODE=$activation_code/" $SECRET_FILE_PATH + rm $SECRET_FILE_PATH.bak + fi + + done + + for i in ${CONFIG_FILE_PATH[@]}; do + source $i + done; + + source $SCRIPTPATH/tools_generator.sh + load_config_variables; + + fi + if [[ "$USE_KUBERNETES" ]]; then @@ -634,16 +674,23 @@ elif [[ "$1" == "launch" ]]; then generate_local_env; - fi - + fi + + # Generating docker-compose yaml for exchange if [[ "$ENVIRONMENT_DOCKER_COMPOSE_GENERATE_YAML_ENABLE" == true ]]; then generate_local_docker_compose $ENVIRONMENT_DOCKER_COMPOSE_RUN_MODE; fi - generate_nginx_upstream $LOCAL_DEPLOYMENT_MODE; + # Generating nginx upstream.conf for exchange + if [[ "$ENVIRONMENT_DOCKER_COMPOSE_GENERATE_NGINX_UPSTREAM" == true ]]; then + + generate_nginx_upstream $LOCAL_DEPLOYMENT_MODE; + + fi + # Generating nginx configurations for custom plugin if [[ "$ENVIRONMENT_CUSTOM_PLUGINS_AUTOCONFIGURE_ENABLE" == "true" ]]; then generate_nginx_config_for_plugin; @@ -654,6 +701,7 @@ elif [[ "$1" == "launch" ]]; then fi + # Actual part of running docker-compose command docker-compose -f $TEMPLATE_GENERATE_PATH/local/$ENVIRONMENT_EXCHANGE_NAME-docker-compose.yaml $LOCAL_COMMAND # Running database init @@ -1188,14 +1236,14 @@ elif [[ "$1" == "upgrade" ]]; then if [[ "$ENVIRONMENT_KUBERNETES_GENERATE_SECRET_ENABLE" == true ]]; then - echo "Generating Kubernetes Configmap" + echo "Generating Kubernetes Secret" generate_kubernetes_secret; fi if [[ "$ENVIRONMENT_KUBERNETES_GENERATE_INGRESS_ENABLE" == true ]]; then - echo "Generating Kubernetes Configmap" + echo "Generating Kubernetes Ingress" generate_kubernetes_ingress; fi @@ -1303,7 +1351,12 @@ elif [[ "$1" == "upgrade" ]]; then fi - generate_nginx_upstream $LOCAL_DEPLOYMENT_MODE; + # Generating nginx upstream.conf for exchange + if [[ "$ENVIRONMENT_DOCKER_COMPOSE_GENERATE_NGINX_UPSTREAM" == true ]]; then + + generate_nginx_upstream $LOCAL_DEPLOYMENT_MODE; + + fi if [[ "$ENVIRONMENT_CUSTOM_PLUGINS_AUTOCONFIGURE_ENABLE" == "true" ]]; then @@ -1494,6 +1547,11 @@ elif [[ "$1" == "toolbox" ]]; then echo "hex-cli will use your Kubernetes cluster as a target." shift; continue ;; + --dev) + IS_DEVELOP=true + echo "hex-cli is configured as dev mode for development purpose." + shift; continue + ;; --upgrade_backends) UPGRADE_BACKENDS=true TOOLBOX_ENABLE=true @@ -1518,6 +1576,30 @@ elif [[ "$1" == "toolbox" ]]; then echo "hex-cli will rolling-upgrade API containers only for Kubernetes." shift; continue ;; + --add_coin) + ADD_COIN=true + TOOLBOX_ENABLE=true + echo "hex-cli will proceed to add new coin on your existing exchange." + shift; continue + ;; + --add_trading_pair) + ADD_TRADING_PAIR=true + TOOLBOX_ENABLE=true + echo "hex-cli will proceed to add new trading pair on your existing exchange." + shift; continue + ;; + --remove_coin) + REMOVE_COIN=true + TOOLBOX_ENABLE=true + echo "hex-cli will proceed to remove coin on your existing exchange." + shift; continue + ;; + --remove_trading_pair) + REMOVE_TRADING_PAIR=true + TOOLBOX_ENABLE=true + echo "hex-cli will proceed to remove trading pair on your existing exchange." + shift; continue + ;; --no_verify) RUN_WITH_VERIFY=false echo "Running it wihtout verify the config." @@ -1548,6 +1630,28 @@ elif [[ "$1" == "toolbox" ]]; then INIT_PATH_CHECK=$HEX_CLI_INIT_PATH/.hex fi + + # PATH overriding for develop + if [[ "$IS_DEVELOP" ]]; then + + if [[ "$HEX_CODEBASE_PATH" ]]; then + + CONFIG_FILE_PATH=$HEX_CODEBASE_PATH/tools/hex-cli-settings/* + TEMPLATE_GENERATE_PATH=$HEX_CODEBASE_PATH/tools/hex-cli-templates + INIT_PATH_CHECK=$HEX_CODEBASE_PATH/.hex + DOCKER_COMPOSE_NAME_PREFIX=$(basename "$HEX_CODEBASE_PATH") + + elif [[ ! "$HEX_CODEBASE_PATH" ]]; then + + CONFIG_FILE_PATH=$(pwd)/tools/hex-cli-settings/* + TEMPLATE_GENERATE_PATH=$(pwd)/tools/hex-cli-templates + INIT_PATH_CHECK=$(pwd)/.hex + HEX_CODEBASE_PATH=$(pwd) + DOCKER_COMPOSE_NAME_PREFIX=$(basename "$HEX_CODEBASE_PATH") + + fi + + fi #Quit if necessary flags are missing if [[ ! "$CONFIG_FILE_PATH" ]] || [[ ! -f "$INIT_PATH_CHECK" ]]; then @@ -1894,6 +1998,43 @@ elif [[ "$1" == "toolbox" ]]; then exit 1; fi + + + elif [[ "$ADD_COIN" ]]; then + + echo "*** Warning: Adding new coin requires full restart of the exchange! ***" + echo "*** Please double confirm that you are good to proceed ***" + + add_coin_input; + + add_coin_exec; + + elif [[ "$REMOVE_COIN" ]]; then + + echo "*** Warning: Removing new coin requires full restart of the exchange! ***" + echo "*** Please double confirm that you are good to proceed ***" + + remove_coin_input; + + remove_coin_exec; + + elif [[ "$ADD_TRADING_PAIR" ]]; then + + echo "*** Warning: Adding new pair requires full restart of the exchange! ***" + echo "*** Please double confirm that you are good to proceed ***" + + add_pair_input; + + add_pair_exec; + + elif [[ "$REMOVE_TRADING_PAIR" ]]; then + + echo "*** Warning: Removing new pair requires full restart of the exchange! ***" + echo "*** Please double confirm that you are good to proceed ***" + + remove_pair_input; + + remove_pair_exec; fi diff --git a/kubernetes/helm-chart/bitholla-hex-server/templates/deployment.yaml b/kubernetes/helm-chart/bitholla-hex-server/templates/deployment.yaml index 04296e7..dba7452 100644 --- a/kubernetes/helm-chart/bitholla-hex-server/templates/deployment.yaml +++ b/kubernetes/helm-chart/bitholla-hex-server/templates/deployment.yaml @@ -1,3 +1,5 @@ +{{- if eq .Values.job.enable false }} + apiVersion: extensions/v1beta1 kind: Deployment metadata: @@ -88,4 +90,6 @@ spec: {{- if .Values.imagePullSecrets }} imagePullSecrets: {{ toYaml .Values.imagePullSecrets | indent 8 }} +{{- end }} + {{- end }} \ No newline at end of file diff --git a/kubernetes/helm-chart/bitholla-hex-server/templates/job.yaml b/kubernetes/helm-chart/bitholla-hex-server/templates/job.yaml new file mode 100644 index 0000000..783e20c --- /dev/null +++ b/kubernetes/helm-chart/bitholla-hex-server/templates/job.yaml @@ -0,0 +1,137 @@ +{{- if .Values.job.enable }} + +apiVersion: batch/v1 +kind: Job +metadata: + labels: + app: {{.Release.Name}} + role: {{.Release.Namespace}} + name: {{.Release.Name}} + namespace: {{.Release.Namespace}} +spec: + template: + spec: + +{{- if .Values.nodeSelector }} + nodeSelector: +{{ toYaml .Values.nodeSelector | indent 8 }} +{{- end }} + + containers: + - name: {{.Release.Name}} + image: {{.Values.imageRegistry}}:{{.Values.dockerTag}} + command: ["/bin/bash", "-c"] + +{{- if eq .Values.job.mode "add_coin" }} + + args: + - node tools/dbs/addCoin.js; + +{{- else if eq .Values.job.mode "remove_coin" }} + + args: + - node tools/dbs/removeCoin.js; + +{{- else if eq .Values.job.mode "add_pair" }} + + args: + - node tools/dbs/addPair.js; + +{{- else if eq .Values.job.mode "remove_pair" }} + + args: + - node tools/dbs/removePair.js; + +{{- end }} + + imagePullPolicy: Always + + envFrom: + - configMapRef: + name: {{.Values.envName}} + - secretRef: + name: {{.Values.secretName}} + + env: + +{{- if eq .Values.job.mode "add_coin" }} + + - name: DEPLOYMENT_MODE + value: {{.Values.DEPLOYMENT_MODE}} + - name: COIN_SYMBOL + value: {{.Values.job.env.coin_symbol}} + - name: COIN_FULLNAME + value: {{.Values.job.env.coin_fullname}} + - name: COIN_ALLOW_DEPOSIT + value: {{.Values.job.env.coin_allow_deposit | quote }} + - name: COIN_ALLOW_WITHDRAWAL + value: {{.Values.job.env.coin_allow_withdrawal | quote }} + - name: COIN_WITHDRAWAL_FEE + value: {{.Values.job.env.coin_withdrawal_fee | quote }} + - name: COIN_MIN + value: {{.Values.job.env.coin_min | quote }} + - name: COIN_MAX + value: {{.Values.job.env.coin_max | quote }} + - name: COIN_INCREMENT_UNIT + value: {{.Values.job.env.coin_increment_unit | quote }} + - name: COIN_DEPOSIT_LIMITS + value: {{.Values.job.env.coin_deposit_limits | quote}} + - name: COIN_WITHDRAWAL_LIMITS + value: {{.Values.job.env.coin_withdrawal_limits | quote }} + - name: COIN_ACTIVE + value: {{.Values.job.env.coin_active | quote }} + +{{- else if eq .Values.job.mode "remove_coin" }} + + - name: COIN_SYMBOL + value: {{.Values.job.env.coin_symbol}} + +{{- else if eq .Values.job.mode "add_pair" }} + + - name: PAIR_NAME + value: {{.Values.job.env.pair_name}} + - name: PAIR_BASE + value: {{.Values.job.env.pair_base}} + - name: PAIR_2 + value: {{.Values.job.env.pair_2}} + - name: TAKER_FEES + value: {{.Values.job.env.taker_fees | quote }} + - name: MAKER_FEES + value: {{.Values.job.env.maker_fees | quote }} + - name: MIN_SIZE + value: {{.Values.job.env.min_size | quote }} + - name: MAX_SIZE + value: {{.Values.job.env.max_size | quote }} + - name: MIN_PRICE + value: {{.Values.job.env.min_price | quote }} + - name: MAX_PRICE + value: {{.Values.job.env.max_price | quote }} + - name: INCREMENT_SIZE + value: {{.Values.job.env.increment_size | quote }} + - name: INCREMENT_PRICE + value: {{.Values.job.env.increment_price | quote }} + - name: PAIR_ACTIVE + value: {{.Values.job.env.pair_active | quote }} + +{{- else if eq .Values.job.mode "remove_pair" }} + + - name: PAIR_NAME + value: {{.Values.job.env.pair_name}} + +{{- end }} + + resources: + limits: + memory: "300Mi" + cpu: "100m" + requests: + memory: "50Mi" + cpu: "15m" + +{{- if .Values.imagePullSecrets }} + imagePullSecrets: +{{ toYaml .Values.imagePullSecrets | indent 8 }} +{{- end }} + restartPolicy: Never + backoffLimit: 0 +{{- end }} \ No newline at end of file diff --git a/kubernetes/helm-chart/bitholla-hex-server/templates/service.yaml b/kubernetes/helm-chart/bitholla-hex-server/templates/service.yaml index aa84f47..214a3d7 100755 --- a/kubernetes/helm-chart/bitholla-hex-server/templates/service.yaml +++ b/kubernetes/helm-chart/bitholla-hex-server/templates/service.yaml @@ -1,3 +1,5 @@ +{{- if eq .Values.job.enable false }} + kind: Service apiVersion: v1 metadata: @@ -17,4 +19,6 @@ spec: selector: app: {{.Release.Name}} +{{- end }} + diff --git a/kubernetes/helm-chart/bitholla-hex-server/values.yaml b/kubernetes/helm-chart/bitholla-hex-server/values.yaml index e6ca295..83ce5e1 100755 --- a/kubernetes/helm-chart/bitholla-hex-server/values.yaml +++ b/kubernetes/helm-chart/bitholla-hex-server/values.yaml @@ -29,5 +29,19 @@ autoScaling: APM_URL: +podRestart_webhook_url: + + +job: + enable: false + mode: #add_coin + #remove_coin + #add_pair + #remove_pair + env: + coin_symbol: + pair_name: + + + -podRestart_webhook_url: \ No newline at end of file diff --git a/settings/configmap b/settings/configmap index 331ca19..1a9e558 100644 --- a/settings/configmap +++ b/settings/configmap @@ -21,13 +21,14 @@ ENVIRONMENT_KUBERNETES_REDIS_NODESELECTOR="{}" ENVIRONMENT_KUBERNETES_INFLUXDB_NODESELECTOR="{}" ENVIRONMENT_KUBERNETES_EXCHANGE_NODESELECTOR="{}" -ENVIRONMENT_DOCKER_IMAGE_REGISTRY=bitholla/hollaex -ENVIRONMENT_DOCKER_IMAGE_VERSION=1.18.4 +ENVIRONMENT_DOCKER_IMAGE_REGISTRY=bitholla/hex-core +ENVIRONMENT_DOCKER_IMAGE_VERSION=1.19.1 ENVIRONMENT_KUBERNETES_API_SERVER_REPLICAS=2 ENVIRONMENT_DOCKER_COMPOSE_GENERATE_ENV_ENABLE=true ENVIRONMENT_DOCKER_COMPOSE_GENERATE_YAML_ENABLE=true +ENVIRONMENT_DOCKER_COMPOSE_GENERATE_NGINX_UPSTREAM=true ENVIRONMENT_KUBERNETES_GENERATE_CONFIGMAP_ENABLE=true ENVIRONMENT_KUBERNETES_GENERATE_SECRET_ENABLE=true @@ -49,10 +50,6 @@ ENVIRONMENT_KUBERNETES_RESTART_NOTIFICATION_WEBHOOK_URL= #### CONFIGMAP VALUES FOR KUBERNETES #### #### Set `ENVIRONMENT_KUBERNETES_GENERATE_CONFIGMAP_ENABLE` as `true` to generate Configmap file #### -#UNCOMMENT APM RELATED ENVS IF YOU DONT WANT TO USE ELASTIC APM -#HEX_CONFIGMAP_APM_ENABLED=true -#HEX_CONFIGMAP_ELASTIC_APM_SERVER_URL=http://es-apm-server.elasticsearch:8200 - HEX_CONFIGMAP_NODE_ENV=production HEX_CONFIGMAP_DEPLOYMENT_MODE=all HEX_CONFIGMAP_PORT=10010 @@ -66,48 +63,6 @@ HEX_CONFIGMAP_USER_LEVEL_NUMBER=4 HEX_CONFIGMAP_MAX_TRADES=50 -HEX_CONFIGMAP_BTC_EUR_INCREMENT_PRICE=1 -HEX_CONFIGMAP_BTC_EUR_INCREMENT_SIZE=0.0001 -HEX_CONFIGMAP_BTC_EUR_MIN_PRICE=500 -HEX_CONFIGMAP_BTC_EUR_MAX_PRICE=50000 -HEX_CONFIGMAP_BTC_EUR_MIN_SIZE=0.0001 -HEX_CONFIGMAP_BTC_EUR_MAX_SIZE=21000000 - -HEX_CONFIGMAP_ETH_EUR_INCREMENT_PRICE=1 -HEX_CONFIGMAP_ETH_EUR_INCREMENT_SIZE=0.001 -HEX_CONFIGMAP_ETH_EUR_MIN_PRICE=10 -HEX_CONFIGMAP_ETH_EUR_MAX_PRICE=10000 -HEX_CONFIGMAP_ETH_EUR_MIN_SIZE=0.001 -HEX_CONFIGMAP_ETH_EUR_MAX_SIZE=20000000 - -HEX_CONFIGMAP_ETH_BTC_INCREMENT_PRICE=0.00001 -HEX_CONFIGMAP_ETH_BTC_INCREMENT_SIZE=0.001 -HEX_CONFIGMAP_ETH_BTC_MIN_PRICE=0.0001 -HEX_CONFIGMAP_ETH_BTC_MAX_PRICE=10 -HEX_CONFIGMAP_ETH_BTC_MIN_SIZE=0.001 -HEX_CONFIGMAP_ETH_BTC_MAX_SIZE=1000 - -HEX_CONFIGMAP_BCH_EUR_INCREMENT_PRICE=1 -HEX_CONFIGMAP_BCH_EUR_INCREMENT_SIZE=0.001 -HEX_CONFIGMAP_BCH_EUR_MIN_PRICE=10 -HEX_CONFIGMAP_BCH_EUR_MAX_PRICE=10000 -HEX_CONFIGMAP_BCH_EUR_MIN_SIZE=0.001 -HEX_CONFIGMAP_BCH_EUR_MAX_SIZE=20000000 - -HEX_CONFIGMAP_BCH_BTC_INCREMENT_PRICE=0.00001 -HEX_CONFIGMAP_BCH_BTC_INCREMENT_SIZE=0.001 -HEX_CONFIGMAP_BCH_BTC_MIN_PRICE=0.0001 -HEX_CONFIGMAP_BCH_BTC_MAX_PRICE=10 -HEX_CONFIGMAP_BCH_BTC_MIN_SIZE=0.001 -HEX_CONFIGMAP_BCH_BTC_MAX_SIZE=1000 - -HEX_CONFIGMAP_XRP_EUR_INCREMENT_PRICE=0.0001 -HEX_CONFIGMAP_XRP_EUR_INCREMENT_SIZE=1 -HEX_CONFIGMAP_XRP_EUR_MIN_PRICE=0.001 -HEX_CONFIGMAP_XRP_EUR_MAX_PRICE=100 -HEX_CONFIGMAP_XRP_EUR_MIN_SIZE=1 -HEX_CONFIGMAP_XRP_EUR_MAX_SIZE=1000000 - HEX_CONFIGMAP_SENDER_EMAIL=support@bitholla.com HEX_CONFIGMAP_SUPPORT_EMAIL=support@bitholla.com @@ -133,9 +88,8 @@ HEX_CONFIGMAP_ALLOWED_DOMAINS= HEX_CONFIGMAP_S3_BUCKETS= HEX_CONFIGMAP_ID_DOCS_BUCKET= -HEX_CONFIGMAP_FIAT_CURRENCY_NAME=Euro -HEX_CONFIGMAP_CURRENCIES=eur,btc,eth,bch,xrp -HEX_CONFIGMAP_PAIRS='btc-eur,eth-eur,eth-btc,bch-eur,bch-btc,xrp-eur' +HEX_CONFIGMAP_CURRENCIES=hex,usdt +HEX_CONFIGMAP_PAIRS='hex-usdt' HEX_CONFIGMAP_WALLI_ENDPOINT_BTC=https://walli.testnet.hollaex.com HEX_CONFIGMAP_WALLI_ENDPOINT_ETH=https://walli.testnet.hollaex.com diff --git a/settings/secret b/settings/secret index 193c3e8..2c6cb96 100644 --- a/settings/secret +++ b/settings/secret @@ -7,6 +7,8 @@ ENVIRONMENT_KUBERNETES_DOCKER_HUB_EMAIL= #### SECRET VALUES FOR KUBERNETES #### #### Set `ENVIRONMENT_KUBERNETES_GENERATE_SECRET_ENABLE` as `true` to generate Secret file #### +HEX_SECRET_ACTIVATION_CODE= + HEX_SECRET_REDIS_HOST=$ENVIRONMENT_EXCHANGE_NAME-redis HEX_SECRET_REDIS_PORT=6379 HEX_SECRET_REDIS_PASSWORD=hex @@ -43,11 +45,8 @@ HEX_SECRET_INFLUX_PORT=8086 HEX_SECRET_INFLUX_USER=hex HEX_SECRET_INFLUX_PASSWORD=hex -HEX_SECRET_WALLI_KEY= -HEX_SECRET_WALLI_SECRET= - -HEX_SECRET_WALLA_KEY= -HEX_SECRET_WALLA_SECRET= +HEX_SECRET_VAULT_KEY= +HEX_SECRET_VAULT_SECRET= HEX_SECRET_FRESHDESK_KEY= HEX_SECRET_FRESHDESK_AUTH= @@ -59,5 +58,4 @@ HEX_SECRET_SUPERVISOR_PASSWORD= HEX_SECRET_SUPPORT_PASSWORD= HEX_SECRET_KYC_PASSWORD= HEX_SECRET_QUICK_TRADE_SECRET= -HEX_SECRET_API_KEYS= HEX_SECRET_SECRET= \ No newline at end of file diff --git a/tools_generator.sh b/tools_generator.sh index 6b2bd61..01ba71e 100644 --- a/tools_generator.sh +++ b/tools_generator.sh @@ -197,16 +197,13 @@ if [[ "$LOCAL_DEPLOYMENT_MODE" == "all" ]]; then # Generate local nginx conf cat > $TEMPLATE_GENERATE_PATH/local/nginx/conf.d/upstream.conf < $TEMPLATE_GENERATE_PATH/local/nginx/conf.d/upstream.conf < $TEMPLATE_GENERATE_PATH/local/nginx/conf.d/upstream.conf < $TEMPLATE_GENERATE_PATH/local/nginx/conf.d/upstream.conf <> $TEMPLATE_GENERATE_PATH/local/${ENVIRONMENT_EXCHANGE_NAME}-docker-compose.yaml <> $TEMPLATE_GENERATE_PATH/local/${ENVIRONMENT_EXCHANGE_NAME}-docker-compose.yaml <> $TEMPLATE_GENERATE_PATH/local/${ENVIRONMENT_EXCHANGE_NAME}-docker-compose.yaml <> $TEMPLATE_GENERATE_PATH/local/${ENVIRONMENT_EXCHANGE_NAME}-docker-compose.yaml <&2 echo "Error: Length of input array needs to be at least 2."; + return 1; + fi + + if [[ $((len%2)) -eq 1 ]]; then + >&2 echo "Error: Length of input array needs to be even (key/value pairs)."; + return 1; + fi + + local data=""; + local foo=0; + for i in "${arr[@]}"; do + local char="," + if [ $((++foo%2)) -eq 0 ]; then + char=":"; + fi + + local first="${i:0:1}"; # read first charc + + local app="\"$i\"" + + if [[ "$first" == "^" ]]; then + app="${i:1}" # remove first char + fi + + data="$data$char$app"; + + done + + data="${data:1}"; # remove first char + echo "{$data}"; # add braces around the string +} + +function add_coin_input() { + + echo "*** What is a symbol of your new coin? [Default: eth] ***" + read answer + + COIN_SYMBOL=${answer:-eth} + + echo "*** What is a full name of your new coin? [Default: Ethereum] ***" + read answer + + COIN_FULLNAME=${answer:-Ethereum} + + echo "*** Are you going to allow deposit to your new coin? (y/n) [Default: y] ***" + read answer + + if [[ ! "$answer" = "${answer#[Nn]}" ]]; then + + COIN_ALLOW_DEPOSIT='false' + + else + + COIN_ALLOW_DEPOSIT='true' + + fi + + echo "*** Are you going to allow withdrawal to your new coin? (y/n) [Default: y] ***" + read answer + + if [[ ! "$answer" = "${answer#[Nn]}" ]]; then + + COIN_ALLOW_WITHDRAWAL='false' + + else + + COIN_ALLOW_WITHDRAWAL='true' + + fi + + echo "*** What is the fee of new coin withdrawal? [Default: 0.001] ***" + read answer + + COIN_WITHDRAWAL_FEE=${answer:-0.001} + + echo "*** What is the minimum price of the new coin? [Default: 0.001] ***" + read answer + + COIN_MIN=${answer:-0.001} + + echo "*** What is the maximum price of the new coin? [Default: 10000] ***" + read answer + + COIN_MAX=${answer:-10000} + + echo "*** What is the increment size of the new coin? [Default: 0.001] ***" + read answer + + COIN_INCREMENT_UNIT=${answer:-0.001} + + # Checking user level setup on settings file is set or not + if [[ ! "$HEX_CONFIGMAP_USER_LEVEL_NUMBER" ]]; then + + echo "*** Warning: Settings value - HEX_CONFIGMAP_USER_LEVEL_NUMBER is not configured. Please confirm your settings files. ***" + exit 1; + + fi + + # Side-by-side printer + function print_deposit_array_side_by_side() { #LEVEL FRIST, VALUE NEXT. + for ((i=0; i<=${#RANGE_DEPOSIT_LIMITS_LEVEL[@]}; i++)); do + printf '%s %s\n' "${RANGE_DEPOSIT_LIMITS_LEVEL[i]}" "${VALUE_DEPOSIT_LIMITS_LEVEL[i]}" + done + } + + # Side-by-side printer + function print_withdrawal_array_side_by_side() { #LEVEL FRIST, VALUE NEXT. + for ((i=0; i<=${#RANGE_WITHDRAWAL_LIMITS_LEVEL[@]}; i++)); do + printf '%s %s\n' "${RANGE_WITHDRAWAL_LIMITS_LEVEL[i]}" "${VALUE_WITHDRAWAL_LIMITS_LEVEL[i]}" + done + } + + # Asking deposit limit of new coin per level + for i in $(seq 1 $HEX_CONFIGMAP_USER_LEVEL_NUMBER); + + do echo "*** What is a deposit limit for user on LEVEL $i? ***" && read answer && export DEPOSIT_LIMITS_LEVEL_$i=$answer + + done; + + read -ra RANGE_DEPOSIT_LIMITS_LEVEL <<< $(set -o posix ; set | grep "DEPOSIT_LIMITS_LEVEL_" | cut -c22 ) + read -ra VALUE_DEPOSIT_LIMITS_LEVEL <<< $(set -o posix ; set | grep "DEPOSIT_LIMITS_LEVEL_" | cut -f2 -d "=" ) + + COIN_DEPOSIT_LIMITS=$(join_array_to_json $(print_deposit_array_side_by_side)) + + # Asking withdrawal limit of new coin per level + for i in $(seq 1 $HEX_CONFIGMAP_USER_LEVEL_NUMBER); + + do echo "*** What is a withdrawal limit for user on LEVEL $i? ***" && read answer && export WITHDRAWAL_LIMITS_LEVEL_$i=$answer + + done; + + read -ra RANGE_WITHDRAWAL_LIMITS_LEVEL <<< $(set -o posix ; set | grep "WITHDRAWAL_LIMITS_LEVEL_" | cut -c25 ) + read -ra VALUE_WITHDRAWAL_LIMITS_LEVEL <<< $(set -o posix ; set | grep "WITHDRAWAL_LIMITS_LEVEL_" | cut -f2 -d "=" ) + + COIN_WITHDRAWAL_LIMITS=$(join_array_to_json $(print_withdrawal_array_side_by_side)) + + echo "*** Are you going to active the new coin you just configured? (y/n) [Default: y] ***" + read answer + + if [[ ! "$answer" = "${answer#[Nn]}" ]]; then + + COIN_ACTIVE='false' + + else + + COIN_ACTIVE='true' + + fi + + function print_coin_add_deposit_level(){ + + for i in $(set -o posix ; set | grep "DEPOSIT_LIMITS_LEVEL_"); + + do echo -e "$i" + + done; + + } + + function print_coin_add_withdrawal_level(){ + + for i in $(set -o posix ; set | grep "WITHDRAWAL_LIMITS_LEVEL_"); + + do echo -e "$i" + + done; + + } + + echo "*********************************************" + echo "Symbol: $COIN_SYMBOL" + echo "Full name: $COIN_FULLNAME" + echo "Allow deposit: $COIN_ALLOW_DEPOSIT" + echo "Allow withdrawal: $COIN_ALLOW_WITHDRAWAL" + echo "Minimum price: $COIN_MIN" + echo "Maximum price: $COIN_MAX" + echo "Increment size: $COIN_INCREMENT_UNIT" + echo -e "Deposit limits per level:\n$(print_coin_add_deposit_level;)" + echo -e "Withdrawal limits per level:\n$(print_coin_add_withdrawal_level;)" + echo "Activation: $COIN_ACTIVE" + echo "*********************************************" + + echo "*** Are the values are all correct? (y/n) ***" + read answer + + if [[ "$answer" = "${answer#[Yy]}" ]]; then + + echo "*** You chose false. Please confirm the values and re-run the command. ***" + exit 1; + + fi +} + + +function add_coin_exec() { + + if [[ "$USE_KUBERNETES" ]]; then + + + function generate_kubernetes_add_coin_values() { + + # Generate Kubernetes Configmap + cat > $TEMPLATE_GENERATE_PATH/kubernetes/config/add-coin.yaml < /dev/null ; then + CONFIGMAP_FILE_PATH=$i + HEX_CONFIGMAP_CURRENCIES_OVERRIDE="${HEX_CONFIGMAP_CURRENCIES},${COIN_SYMBOL}" + sed -i.bak "s/$HEX_CONFIGMAP_CURRENCIES/$HEX_CONFIGMAP_CURRENCIES_OVERRIDE/" $CONFIGMAP_FILE_PATH + rm $CONFIGMAP_FILE_PATH.bak + fi + + done + + else + + echo "*** Failed to add new coin $COIN_SYMBOL! Please try again.***" + + kubectl logs --namespace $ENVIRONMENT_EXCHANGE_NAME job/$ENVIRONMENT_EXCHANGE_NAME-add-coin-$COIN_SYMBOL + helm del --purge $ENVIRONMENT_EXCHANGE_NAME-add-coin-$COIN_SYMBOL + + fi + + elif [[ ! "$USE_KUBERNETES" ]]; then + + if [[ ! $ENVIRONMENT_DOCKER_COMPOSE_RUN_MODE == "all" ]]; then + + IFS=',' read -ra CONTAINER_PREFIX <<< "-${ENVIRONMENT_DOCKER_COMPOSE_RUN_MODE}" + + fi + + # Overriding container prefix for develop server + if [[ "$IS_DEVELOP" ]]; then + + CONTAINER_PREFIX= + + fi + + echo "*** Adding new coin $COIN_SYMBOL on local exchange ***" + if command docker exec --env "COIN_FULLNAME=${COIN_FULLNAME}" \ + --env "COIN_SYMBOL=${COIN_SYMBOL}" \ + --env "COIN_ALLOW_DEPOSIT=${COIN_ALLOW_DEPOSIT}" \ + --env "COIN_ALLOW_WITHDRAWAL=${COIN_ALLOW_WITHDRAWAL}" \ + --env "COIN_WITHDRAWAL_FEE=${COIN_WITHDRAWAL_FEE}" \ + --env "COIN_MIN=${COIN_MIN}" \ + --env "COIN_MAX=${COIN_MAX}" \ + --env "COIN_INCREMENT_UNIT=${COIN_INCREMENT_UNIT}" \ + --env "COIN_DEPOSIT_LIMITS=${COIN_DEPOSIT_LIMITS}" \ + --env "COIN_WITHDRAWAL_LIMITS=${COIN_WITHDRAWAL_LIMITS}" \ + --env "COIN_ACTIVE=${COIN_ACTIVE}" \ + ${DOCKER_COMPOSE_NAME_PREFIX}_${ENVIRONMENT_EXCHANGE_NAME}-server${CONTAINER_PREFIX[0]}_1 \ + node tools/dbs/addCoin.js; then + + echo "*** Running database triggers ***" + docker exec ${DOCKER_COMPOSE_NAME_PREFIX}_${ENVIRONMENT_EXCHANGE_NAME}-server${CONTAINER_PREFIX[0]}_1 node tools/dbs/runTriggers.js + + if [[ "$IS_DEVELOP" ]]; then + + # Restarting containers after database init jobs. + echo "Restarting containers to apply database changes." + docker-compose -f $HEX_CODEBASE_PATH/.$ENVIRONMENT_EXCHANGE_NAME-docker-compose.yaml restart + + else + + # Restarting containers after database init jobs. + echo "Restarting containers to apply database changes." + docker-compose -f $TEMPLATE_GENERATE_PATH/local/$ENVIRONMENT_EXCHANGE_NAME-docker-compose.yaml restart + + fi + + echo "*** Updating settings file to add new $COIN_SYMBOL. ***" + for i in ${CONFIG_FILE_PATH[@]}; do + + if command grep -q "ENVIRONMENT_DOCKER_" $i > /dev/null ; then + CONFIGMAP_FILE_PATH=$i + HEX_CONFIGMAP_CURRENCIES_OVERRIDE="${HEX_CONFIGMAP_CURRENCIES},${COIN_SYMBOL}" + sed -i.bak "s/$HEX_CONFIGMAP_CURRENCIES/$HEX_CONFIGMAP_CURRENCIES_OVERRIDE/" $CONFIGMAP_FILE_PATH + rm $CONFIGMAP_FILE_PATH.bak + fi + + done + + else + + echo "*** Failed to add new coin $COIN_SYMBOL on local exchange. Please confirm your input values and try again. ***" + exit 1; + + fi + + # Restarting containers after database init jobs. + echo "Restarting containers to apply database changes." + docker-compose -f $TEMPLATE_GENERATE_PATH/local/$ENVIRONMENT_EXCHANGE_NAME-docker-compose.yaml restart + + fi + +} + +function remove_coin_input() { + + echo "*** What is a symbol of your want to remove? ***" + read answer + + COIN_SYMBOL=$answer + + if [[ -z "$answer" ]]; then + + echo "*** Your value is empty. Please confirm your input and run the command again. ***" + exit 1; + + fi + + echo "*********************************************" + echo "Symbol: $COIN_SYMBOL" + echo "*********************************************" + + echo "*** Are the sure you want to remove this coin from your exchange? (y/n) ***" + read answer + + if [[ "$answer" = "${answer#[Yy]}" ]]; then + + echo "*** You chose false. Please confirm the values and run the command again. ***" + exit 1; + + fi + +} + +function remove_coin_exec() { + + if [[ "$USE_KUBERNETES" ]]; then + + echo "*** Removing existing coin $COIN_SYMBOL on Kubernetes ***" + + if command helm install --name $ENVIRONMENT_EXCHANGE_NAME-remove-coin-$COIN_SYMBOL \ + --namespace $ENVIRONMENT_EXCHANGE_NAME \ + --set job.enable="true" \ + --set job.mode="remove_coin" \ + --set job.env.coin_symbol="$COIN_SYMBOL" \ + --set DEPLOYMENT_MODE="api" \ + --set imageRegistry="$ENVIRONMENT_DOCKER_IMAGE_REGISTRY" \ + --set dockerTag="$ENVIRONMENT_DOCKER_IMAGE_VERSION" \ + --set envName="$ENVIRONMENT_EXCHANGE_NAME-env" \ + --set secretName="$ENVIRONMENT_EXCHANGE_NAME-secret" \ + -f $TEMPLATE_GENERATE_PATH/kubernetes/config/nodeSelector-hex.yaml \ + -f $SCRIPTPATH/kubernetes/helm-chart/bitholla-hex-server/values.yaml \ + $SCRIPTPATH/kubernetes/helm-chart/bitholla-hex-server; then + + echo "*** Kubernetes Job has been created for removing existing coin $COIN_SYMBOL. ***" + + echo "*** Waiting until Job get completely run ***" + sleep 30; + + else + + echo "*** Failed to create Kubernetes Job for removing existing coin $COIN_SYMBOL, Please confirm your input values and try again. ***" + helm del --purge $ENVIRONMENT_EXCHANGE_NAME-remove-coin-$COIN_SYMBOL + + fi + + if [[ $(kubectl get jobs $ENVIRONMENT_EXCHANGE_NAME-remove-coin-$COIN_SYMBOL \ + --namespace $ENVIRONMENT_EXCHANGE_NAME \ + -o jsonpath='{.status.conditions[?(@.type=="Complete")].status}') == "True" ]]; then + + echo "*** Coin $COIN_SYMBOL has been successfully removed on your exchange! ***" + kubectl logs --namespace $ENVIRONMENT_EXCHANGE_NAME job/$ENVIRONMENT_EXCHANGE_NAME-remove-coin-$COIN_SYMBOL + + echo "*** Restarting containers... ***" + kubectl delete pods --namespace $ENVIRONMENT_EXCHANGE_NAME -l role=$ENVIRONMENT_EXCHANGE_NAME + + echo "*** Removing created Kubernetes Job for removing existing coin... ***" + helm del --purge $ENVIRONMENT_EXCHANGE_NAME-remove-coin-$COIN_SYMBOL + + echo "*** Updating settings file to remove $COIN_SYMBOL. ***" + for i in ${CONFIG_FILE_PATH[@]}; do + + if command grep -q "ENVIRONMENT_DOCKER_" $i > /dev/null ; then + CONFIGMAP_FILE_PATH=$i + if [[ "$COIN_SYMBOL" == "hex" ]]; then + HEX_CONFIGMAP_CURRENCIES_OVERRIDE=$(echo "${HEX_CONFIGMAP_CURRENCIES//$COIN_SYMBOL,}") + else + HEX_CONFIGMAP_CURRENCIES_OVERRIDE=$(echo "${HEX_CONFIGMAP_CURRENCIES//,$COIN_SYMBOL}") + fi + sed -i.bak "s/$HEX_CONFIGMAP_CURRENCIES/$HEX_CONFIGMAP_CURRENCIES_OVERRIDE/" $CONFIGMAP_FILE_PATH + rm $CONFIGMAP_FILE_PATH.bak + fi + + done + + else + + echo "*** Failed to remove existing coin $COIN_SYMBOL! Please try again.***" + + kubectl logs --namespace $ENVIRONMENT_EXCHANGE_NAME job/$ENVIRONMENT_EXCHANGE_NAME-remove-coin-$COIN_SYMBOL + helm del --purge $ENVIRONMENT_EXCHANGE_NAME-remove-coin-$COIN_SYMBOL + + fi + + elif [[ ! "$USE_KUBERNETES" ]]; then + + if [[ ! $ENVIRONMENT_DOCKER_COMPOSE_RUN_MODE == "all" ]]; then + + IFS=',' read -ra CONTAINER_PREFIX <<< "-${ENVIRONMENT_DOCKER_COMPOSE_RUN_MODE}" + + fi + + # Overriding container prefix for develop server + if [[ "$IS_DEVELOP" ]]; then + + CONTAINER_PREFIX= + + fi + + echo "*** Removing new coin $COIN_SYMBOL on local docker ***" + if command docker exec --env "COIN_SYMBOL=${COIN_SYMBOL}" \ + ${DOCKER_COMPOSE_NAME_PREFIX}_${ENVIRONMENT_EXCHANGE_NAME}-server${CONTAINER_PREFIX[0]}_1 \ + node tools/dbs/removeCoin.js; then + + + if [[ "$IS_DEVELOP" ]]; then + + # Restarting containers after database init jobs. + echo "Restarting containers to apply database changes." + docker-compose -f $HEX_CODEBASE_PATH/.$ENVIRONMENT_EXCHANGE_NAME-docker-compose.yaml restart + + else + + # Restarting containers after database init jobs. + echo "Restarting containers to apply database changes." + docker-compose -f $TEMPLATE_GENERATE_PATH/local/$ENVIRONMENT_EXCHANGE_NAME-docker-compose.yaml restart + + fi + + echo "*** Updating settings file to remove $COIN_SYMBOL. ***" + for i in ${CONFIG_FILE_PATH[@]}; do + + if command grep -q "ENVIRONMENT_DOCKER_" $i > /dev/null ; then + CONFIGMAP_FILE_PATH=$i + if [[ "$COIN_SYMBOL" == "hex" ]]; then + HEX_CONFIGMAP_CURRENCIES_OVERRIDE=$(echo "${HEX_CONFIGMAP_CURRENCIES//$COIN_SYMBOL,}") + else + HEX_CONFIGMAP_CURRENCIES_OVERRIDE=$(echo "${HEX_CONFIGMAP_CURRENCIES//,$COIN_SYMBOL}") + fi + sed -i.bak "s/$HEX_CONFIGMAP_CURRENCIES/$HEX_CONFIGMAP_CURRENCIES_OVERRIDE/" $CONFIGMAP_FILE_PATH + rm $CONFIGMAP_FILE_PATH.bak + fi + + done + + else + + echo "*** Failed to remove coin $COIN_SYMBOL on local exchange. Please confirm your input values and try again. ***" + exit 1; + + fi + + fi + +} + +function add_pair_input() { + + echo "*** What is a full name of your new trading pair? [Default: eth-usdt] ***" + read answer + + PAIR_NAME=${answer:-eth-usdt} + PAIR_BASE=$(echo $PAIR_NAME | cut -f1 -d '-') + PAIR_2=$(echo $PAIR_NAME | cut -f2 -d '-') + + # Checking user level setup on settings file is set or not + if [[ ! "$HEX_CONFIGMAP_USER_LEVEL_NUMBER" ]]; then + + echo "*** Warning: Settings value - HEX_CONFIGMAP_USER_LEVEL_NUMBER is not configured. Please confirm your settings files. ***" + exit 1; + + fi + + # Side-by-side printer + function print_taker_fees_array_side_by_side() { #LEVEL FRIST, VALUE NEXT. + for ((i=0; i<=${#RANGE_TAKER_FEES_LEVEL[@]}; i++)); do + printf '%s %s\n' "${RANGE_TAKER_FEES_LEVEL[i]}" "${VALUE_TAKER_FEES_LEVEL[i]}" + done + } + + # Side-by-side printer + function print_maker_fees_array_side_by_side() { #LEVEL FRIST, VALUE NEXT. + for ((i=0; i<=${#RANGE_MAKER_FEES_LEVEL[@]}; i++)); do + printf '%s %s\n' "${RANGE_MAKER_FEES_LEVEL[i]}" "${VALUE_MAKER_FEES_LEVEL[i]}" + done + } + + # Asking deposit limit of new coin per level + for i in $(seq 1 $HEX_CONFIGMAP_USER_LEVEL_NUMBER); + + do echo "*** What is a taker fee for user on LEVEL $i? ***" && read answer && export TAKER_FEES_LEVEL_$i=$answer + + done; + + read -ra RANGE_TAKER_FEES_LEVEL <<< $(set -o posix ; set | grep "TAKER_FEES_LEVEL_" | cut -c18 ) + read -ra VALUE_TAKER_FEES_LEVEL <<< $(set -o posix ; set | grep "TAKER_FEES_LEVEL_" | cut -f2 -d "=" ) + + TAKER_FEES=$(join_array_to_json $(print_taker_fees_array_side_by_side)) + + # Asking withdrawal limit of new coin per level + for i in $(seq 1 $HEX_CONFIGMAP_USER_LEVEL_NUMBER); + + do echo "*** What is a maker fee for user on LEVEL $i? ***" && read answer && export MAKER_FEES_LEVEL_$i=$answer + + done; + + read -ra RANGE_MAKER_FEES_LEVEL <<< $(set -o posix ; set | grep "MAKER_FEES_LEVEL_" | cut -c18 ) + read -ra VALUE_MAKER_FEES_LEVEL <<< $(set -o posix ; set | grep "MAKER_FEES_LEVEL_" | cut -f2 -d "=" ) + + MAKER_FEES=$(join_array_to_json $(print_maker_fees_array_side_by_side)) + + echo "*** What is the minimum size for trading of the new pair? [Default: 0.001] ***" + read answer + + MIN_SIZE=${answer:-0.001} + + echo "*** What is the maximum size for trading of the new pair? [Default: 20000000] ***" + read answer + + MAX_SIZE=${answer:-20000000} + + echo "*** What is the minimum price of the new pair? [Default: 0.0001] ***" + read answer + + MIN_PRICE=${answer:-0.0001} + + echo "*** What is the maximum price for trading of the new pair? [Default: 10] ***" + read answer + + MAX_PRICE=${answer:-10} + + echo "*** What is the increment size of the new pair? [Default: 0.001] ***" + read answer + + INCREMENT_SIZE=${answer:-0.001} + + echo "*** What is the increment price of the new pair? [Default: 1] ***" + read answer + + INCREMENT_PRICE=${answer:-1} + + echo "*** Are you going to active the new pair you just configured? (y/n) [Default: y] ***" + read answer + + if [[ ! "$answer" = "${answer#[Nn]}" ]]; then + + PAIR_ACTIVE=false + + else + + PAIR_ACTIVE=true + + fi + + function print_taker_fees_deposit_level(){ + + for i in $(set -o posix ; set | grep "TAKER_FEES_LEVEL_"); + + do echo -e "$i" + + done; + + } + + function print_maker_fees_withdrawal_level(){ + + for i in $(set -o posix ; set | grep "MAKER_FEES_LEVEL_"); + + do echo -e "$i" + + done; + + } + + echo "*********************************************" + echo "Full name: $PAIR_NAME" + echo "First currency: $PAIR_BASE" + echo "Second currency: $PAIR_2" + echo -e "Taker fees per level:\n$(print_taker_fees_deposit_level;)" + echo -e "Maker limits per level:\n$(print_maker_fees_withdrawal_level;)" + echo "Minimum size: $MIN_SIZE" + echo "Maximum size: $MAX_SIZE" + echo "Minimum price: $MIN_PRICE" + echo "Maximum price: $MAX_PRICE" + echo "Increment size: $INCREMENT_SIZE" + echo "Increment price: $INCREMENT_PRICE" + echo "Activation: $PAIR_ACTIVE" + echo "*********************************************" + + echo "*** Are the values are all correct? (y/n) ***" + read answer + + if [[ "$answer" = "${answer#[Yy]}" ]]; then + + echo "*** You chose false. Please confirm the values and re-run the command. ***" + exit 1; + + fi + +} + + +function add_pair_exec() { + + if [[ "$USE_KUBERNETES" ]]; then + + function generate_kubernetes_add_pair_values() { + + # Generate Kubernetes Configmap + cat > $TEMPLATE_GENERATE_PATH/kubernetes/config/add-pair.yaml < /dev/null ; then + CONFIGMAP_FILE_PATH=$i + HEX_CONFIGMAP_PAIRS_OVERRIDE="${HEX_CONFIGMAP_PAIRS},${PAIR_NAME}" + sed -i.bak "s/$HEX_CONFIGMAP_PAIRS/$HEX_CONFIGMAP_PAIRS_OVERRIDE/" $CONFIGMAP_FILE_PATH + rm $CONFIGMAP_FILE_PATH.bak + fi + + done + + # Reading variable again + for i in ${CONFIG_FILE_PATH[@]}; do + source $i + done; + + source $SCRIPTPATH/tools_generator.sh + load_config_variables; + + echo "*** Upgrading exchange with latest settings... ***" + hex upgrade --kube --no_verify + + echo "*** Removing created Kubernetes Job for adding new coin... ***" + helm del --purge $ENVIRONMENT_EXCHANGE_NAME-add-pair-$PAIR_NAME + + else + + echo "*** Failed to add new pair $PAIR_NAME! Please try again.***" + + kubectl logs --namespace $ENVIRONMENT_EXCHANGE_NAME job/$ENVIRONMENT_EXCHANGE_NAME-add-pair-$PAIR_NAME + helm del --purge $ENVIRONMENT_EXCHANGE_NAME-add-pair-$PAIR_NAME + + fi + + elif [[ ! "$USE_KUBERNETES" ]]; then + + if [[ ! $ENVIRONMENT_DOCKER_COMPOSE_RUN_MODE == "all" ]]; then + + IFS=',' read -ra CONTAINER_PREFIX <<< "-${ENVIRONMENT_DOCKER_COMPOSE_RUN_MODE}" + + fi + + # Overriding container prefix for develop server + if [[ "$IS_DEVELOP" ]]; then + + CONTAINER_PREFIX= + + fi + + echo "*** Adding new pair $PAIR_NAME on local exchange ***" + if command docker exec --env "PAIR_NAME=${PAIR_NAME}" \ + --env "PAIR_BASE=${PAIR_BASE}" \ + --env "PAIR_2=${PAIR_2}" \ + --env "TAKER_FEES=${TAKER_FEES}" \ + --env "MAKER_FEES=${MAKER_FEES}" \ + --env "MIN_SIZE=${MIN_SIZE}" \ + --env "MAX_SIZE=${MAX_SIZE}" \ + --env "MIN_PRICE=${MIN_PRICE}" \ + --env "MAX_PRICE=${MAX_PRICE}" \ + --env "INCREMENT_SIZE=${INCREMENT_SIZE}" \ + --env "INCREMENT_PRICE=${INCREMENT_PRICE}" \ + --env "PAIR_ACTIVE=${PAIR_ACTIVE}" \ + ${DOCKER_COMPOSE_NAME_PREFIX}_${ENVIRONMENT_EXCHANGE_NAME}-server${CONTAINER_PREFIX[0]}_1 \ + node tools/dbs/addPair.js; then + + if [[ "$IS_DEVELOP" ]]; then + + # Restarting containers after database init jobs. + echo "Restarting containers to apply database changes." + docker-compose -f $HEX_CODEBASE_PATH/.$ENVIRONMENT_EXCHANGE_NAME-docker-compose.yaml restart + + else + + # Restarting containers after database init jobs. + echo "Restarting containers to apply database changes." + docker-compose -f $TEMPLATE_GENERATE_PATH/local/$ENVIRONMENT_EXCHANGE_NAME-docker-compose.yaml restart + + fi + + echo "*** Updating settings file to add new $PAIR_NAME. ***" + for i in ${CONFIG_FILE_PATH[@]}; do + + if command grep -q "ENVIRONMENT_DOCKER_" $i > /dev/null ; then + CONFIGMAP_FILE_PATH=$i + HEX_CONFIGMAP_PAIRS_OVERRIDE="${HEX_CONFIGMAP_PAIRS},${PAIR_NAME}" + sed -i.bak "s/$HEX_CONFIGMAP_PAIRS/$HEX_CONFIGMAP_PAIRS_OVERRIDE/" $CONFIGMAP_FILE_PATH + rm $CONFIGMAP_FILE_PATH.bak + fi + + done + + else + + echo "*** Failed to add new pair $PAIR_NAME on local exchange. Please confirm your input values and try again. ***" + exit 1; + + fi + + fi + +} + +function remove_pair_input() { + + echo "*** What is a name of your trading pair want to remove? ***" + read answer + + PAIR_NAME=$answer + + if [[ -z "$answer" ]]; then + + echo "*** Your value is empty. Please confirm your input and run the command again. ***" + exit 1; + + fi + + echo "*********************************************" + echo "Name: $PAIR_NAME" + echo "*********************************************" + + echo "*** Are the sure you want to remove this trading pair from your exchange? (y/n) ***" + read answer + + if [[ "$answer" = "${answer#[Yy]}" ]]; then + + echo "*** You chose false. Please confirm the values and run the command again. ***" + exit 1; + + fi + +} + +function remove_pair_exec() { + + if [[ "$USE_KUBERNETES" ]]; then + + echo "*** Removing existing pair $PAIR_NAME on Kubernetes ***" + + if command helm install --name $ENVIRONMENT_EXCHANGE_NAME-remove-pair-$PAIR_NAME \ + --namespace $ENVIRONMENT_EXCHANGE_NAME \ + --set job.enable="true" \ + --set job.mode="remove_pair" \ + --set job.env.pair_name="$PAIR_NAME" \ + --set DEPLOYMENT_MODE="api" \ + --set imageRegistry="$ENVIRONMENT_DOCKER_IMAGE_REGISTRY" \ + --set dockerTag="$ENVIRONMENT_DOCKER_IMAGE_VERSION" \ + --set envName="$ENVIRONMENT_EXCHANGE_NAME-env" \ + --set secretName="$ENVIRONMENT_EXCHANGE_NAME-secret" \ + -f $TEMPLATE_GENERATE_PATH/kubernetes/config/nodeSelector-hex.yaml \ + -f $SCRIPTPATH/kubernetes/helm-chart/bitholla-hex-server/values.yaml \ + $SCRIPTPATH/kubernetes/helm-chart/bitholla-hex-server; then + + echo "*** Kubernetes Job has been created for removing existing pair $PAIR_NAME. ***" + + echo "*** Waiting until Job get completely run ***" + sleep 30; + + else + + echo "*** Failed to create Kubernetes Job for removing existing pair $PAIR_NAME, Please confirm your input values and try again. ***" + helm del --purge $ENVIRONMENT_EXCHANGE_NAME-remove-pair-$PAIR_NAME + + fi + + if [[ $(kubectl get jobs $ENVIRONMENT_EXCHANGE_NAME-remove-pair-$PAIR_NAME \ + --namespace $ENVIRONMENT_EXCHANGE_NAME \ + -o jsonpath='{.status.conditions[?(@.type=="Complete")].status}') == "True" ]]; then + + echo "*** Pair $PAIR_NAME has been successfully removed on your exchange! ***" + kubectl logs --namespace $ENVIRONMENT_EXCHANGE_NAME job/$ENVIRONMENT_EXCHANGE_NAME-remove-pair-$PAIR_NAME + + echo "*** Removing existing $PAIR_NAME container from Kubernetes ***" + PAIR_BASE=$(echo $PAIR_NAME | cut -f1 -d '-') + PAIR_2=$(echo $PAIR_NAME | cut -f2 -d '-') + + helm del --purge $ENVIRONMENT_EXCHANGE_NAME-server-queue-$PAIR_BASE$PAIR_2 + + echo "*** Restarting containers... ***" + kubectl delete pods --namespace $ENVIRONMENT_EXCHANGE_NAME -l role=$ENVIRONMENT_EXCHANGE_NAME + + echo "*** Removing created Kubernetes Job for removing existing pair... ***" + helm del --purge $ENVIRONMENT_EXCHANGE_NAME-remove-pair-$PAIR_NAME + + echo "*** Updating settings file to add new $PAIR_NAME. ***" + for i in ${CONFIG_FILE_PATH[@]}; do + + if command grep -q "ENVIRONMENT_DOCKER_" $i > /dev/null ; then + CONFIGMAP_FILE_PATH=$i + if [[ "$PAIR_NAME" == "hex-usdt" ]]; then + HEX_CONFIGMAP_CURRENCIES_OVERRIDE=$(echo "${HEX_CONFIGMAP_PAIRS//$PAIR_NAME,}") + else + HEX_CONFIGMAP_CURRENCIES_OVERRIDE=$(echo "${HEX_CONFIGMAP_PAIRS//,$PAIR_NAME}") + fi + sed -i.bak "s/$HEX_CONFIGMAP_PAIRS/$HEX_CONFIGMAP_CURRENCIES_OVERRIDE/" $CONFIGMAP_FILE_PATH + rm $CONFIGMAP_FILE_PATH.bak + fi + + done + + else + + echo "*** Failed to remove existing pair $PAIR_NAME! Please try again.***" + + kubectl logs --namespace $ENVIRONMENT_EXCHANGE_NAME job/$ENVIRONMENT_EXCHANGE_NAME-remove-pair-$PAIR_NAME + helm del --purge $ENVIRONMENT_EXCHANGE_NAME-remove-pair-$PAIR_NAME + + fi + + elif [[ ! "$USE_KUBERNETES" ]]; then + + if [[ ! $ENVIRONMENT_DOCKER_COMPOSE_RUN_MODE == "all" ]]; then + + IFS=',' read -ra CONTAINER_PREFIX <<< "-${ENVIRONMENT_DOCKER_COMPOSE_RUN_MODE}" + + fi + + # Overriding container prefix for develop server + if [[ "$IS_DEVELOP" ]]; then + + CONTAINER_PREFIX= + + fi + + echo "*** Removing new pair $PAIR_NAME on local exchange ***" + if command docker exec --env "PAIR_NAME=${PAIR_NAME}" ${DOCKER_COMPOSE_NAME_PREFIX}_${ENVIRONMENT_EXCHANGE_NAME}-server${CONTAINER_PREFIX[0]}_1 node tools/dbs/removePair.js; then + + if [[ "$IS_DEVELOP" ]]; then + + # Restarting containers after database init jobs. + echo "Restarting containers to apply database changes." + docker-compose -f $HEX_CODEBASE_PATH/.$ENVIRONMENT_EXCHANGE_NAME-docker-compose.yaml restart + + else + + # Restarting containers after database init jobs. + echo "Restarting containers to apply database changes." + docker-compose -f $TEMPLATE_GENERATE_PATH/local/$ENVIRONMENT_EXCHANGE_NAME-docker-compose.yaml restart + + fi + + echo "*** Updating settings file to add new $PAIR_NAME. ***" + for i in ${CONFIG_FILE_PATH[@]}; do + + if command grep -q "ENVIRONMENT_DOCKER_" $i > /dev/null ; then + CONFIGMAP_FILE_PATH=$i + if [[ "$PAIR_NAME" == "hex-usdt" ]]; then + HEX_CONFIGMAP_CURRENCIES_OVERRIDE=$(echo "${HEX_CONFIGMAP_PAIRS//$PAIR_NAME,}") + else + HEX_CONFIGMAP_CURRENCIES_OVERRIDE=$(echo "${HEX_CONFIGMAP_PAIRS//,$PAIR_NAME}") + fi + sed -i.bak "s/$HEX_CONFIGMAP_PAIRS/$HEX_CONFIGMAP_CURRENCIES_OVERRIDE/" $CONFIGMAP_FILE_PATH + rm $CONFIGMAP_FILE_PATH.bak + fi + + done + + else + + echo "*** Failed to remove trading pair $PAIR_NAME on local exchange. Please confirm your input values and try again. ***" + exit 1; + + fi + + fi + +} \ No newline at end of file diff --git a/version b/version index 8e03717..a73b432 100644 --- a/version +++ b/version @@ -1 +1 @@ -1.5.1 \ No newline at end of file +1.5.2 \ No newline at end of file