Sqlite inb bash si vous insérez des données, dites-moi de ne pas avoir de table

la programmation

[ad_1]

Salut, pourquoi mon code me dit Erreur : lors de la préparation, aucune table de ce type : BinanceCex

j’ai la table, je suis sûr que j’ai peut-être fait une erreur dans le script bash ?

Frapper
#!/bin/bash
set -x


#RunProgram() {
    # Aggiungi qui la logica per eseguire il programma
#}

# Funzione per inserire dati JSON nella tabella SQLite
insert_dataBinance() {
       sqlite3 ConfigDb.db "INSERT INTO BinanceCex (id_symbol, symbol, base, quote, info_symbol, info_status, info_baseAsset, info_baseAssetPrecision, info_quoteAsset, info_quotePrecision,
        info_quoteAssetPrecision, info_baseCommissionPrecision, info_quoteCommissionPrecision, info_orderType_0, info_orderType_1,
        info_orderType_2, info_orderType_3, info_orderType_4, info_icebergAllowed, info_ocoAllowed, info_quoteOrderQtyMarketAllowed,
        info_allowTrailingStop, info_cancelReplaceAllowed, info_isSpotTradingAllowed, info_isMarginTradingAllowed, info_filters_0_filterType,
        info_filters_0_minPrice, info_filters_0_maxPrice, info_filters_0_tickSize, info_filters_1_filterType, info_filters_1_minQty,
        info_filters_1_maxQty, info_filters_1_stepSize, info_filters_2_filterType, info_filters_2_limit, info_filters_3_filterType,
        info_filters_3_maxQty, info_filters_3_stepSize, info_filters_4_filterType, info_filters_4_minTrailingAboveDelta,
        info_filters_4_maxTrailingAboveDelta, info_filters_4_minTrailingBelowDelta, info_filters_4_maxTrailingBelowDelta,
        info_filters_5_filterType, info_filters_5_bidMultiplierUp, info_filters_5_bidMultiplierDown, info_filters_5_askMultiplierUp,
        info_filters_5_askMultiplierDown, info_filters_5_avgPriceMins, info_filters_6_filterType, info_filters_6_minNotional,
        info_filters_6_applyMinToMarket, info_filters_6_maxNotional, info_filters_6_applyMaxToMarket, info_filters_6_avgPriceMins,
        info_filters_7_filterType, info_filters_7_maxNumOrders, info_filters_8_filterType, info_filters_8_maxNumAlgoOrders,
        info_permissions_0, info_permissions_1, info_filters_3_minQty, info_permissions_2, info_permissions_3, info_permissions_4,
        info_permissions_5, info_permissions_6, info_permissions_7, info_permissions_8, info_permissions_9, info_permissions_10,
        info_permissions_11, info_permissions_12, info_permissions_13, info_permissions_14, info_permissions_15, info_permissions_16,
        info_permissions_17, info_permissions_18, info_permissions_19, info_permissions_20, info_permissions_21, info_permissions_22,
        info_defaultSelfTradePreventionMode, info_allowedSelfTradePreveMode_0, info_allowedSelfTradePreveMode_1,
        info_allowedSelfTradePreveMode_2, limits_amount_min, limits_amount_max, limits_price_min, limits_price_max, limits_cost,
        precision_amount, precision_price)
        VALUES ('$1', '$2', '$3', '$4', '$5', '$6', '$7', '$8', '$9', '$10', '$11',
            '$12', '$13', '$14', '$15', '$16', '$17', '$18', '$19', '$20', '$21',
            '$22', '$23', '$24', '$25', '$26', '$27', '$28', '$29', '$30', '$31',
            '$32', '$33', '$34', '$35', '$36', '$37', '$38', '$39', '$40', '$41', 
            '$42', '$43', '$44', '$45', '$46', '$47', '$48', '$49', '$50', '$51',
            '$52', '$53', '$54', '$55', '$56', '$57', '$58', '$59', '$60', '$61', 
            '$62', '$63', '$64', '$65', '$66', '$67', '$68', '$69', '$70', '$71',
            '$72', '$73', '$74', '$75', '$76', '$77', '$78', '$79', '$80', '$81', 
            '$83', '$84', '$85', '$86', '$87', '$88', '$89', '$90', '$91', '$92', '$93');"
}

Extract() {
    
    # -- BINANCE CEX -------------------------------------------------------------------
    BINANCE_Markets="http://localhost:3000/exchange/binance/markets"
    COINBASE_Markets="http://localhost:3000/exchange/coinbase/markets"
    KRAKEN_Markets="http://localhost:3000/exchange/kraken/markets"
    BYBIT_Markets="http://localhost:3000/exchange/bybit/markets"
	
    json_dataBINCEX=$(curl -X GET "$BINANCE_Markets" -H "accept: application/json")
    # Estrai i dati 
    contatore=0
    while true; do
		id_symbol=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].id")
		if [ "$id_symbol" == "null" ]; then
			echo "La variabile 'id_symbol' è nulla. Uscita dal ciclo."
			break
		fi
		symbol=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].symbol")
		base=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].base")
		quote=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].quote")
		info_symbol=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.symbol")
		info_status=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.status")
		info_baseAsset=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.baseAsset")
		info_baseAssetPrecision=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.baseAssetPrecision")
		info_quoteAsset=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.quoteAsset")
		info_quotePrecision=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.quotePrecision")
		info_quoteAssetPrecision=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.quoteAssetPrecision")
		info_baseCommissionPrecision=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.baseCommissionPrecision")
		info_quoteCommissionPrecision=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.quoteCommissionPrecision")
		
		info_orderTypes0=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.orderTypes[0]")
		info_orderTypes1=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.orderTypes[1]")
		info_orderTypes2=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.orderTypes[2]")
		info_orderTypes3=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.orderTypes[3]")
		info_orderTypes4=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.orderTypes[4]")
		info_icebergAllowed=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.icebergAllowed")
		info_ocoAllowed=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.ocoAllowed")
		info_quoteOrderQtyMarketAllowed=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.quoteOrderQtyMarketAllowed")
		info_allowTrailingStop=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.allowTrailingStop")
		info_cancelReplaceAllowed=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.cancelReplaceAllowed")
		info_isSpotTradingAllowed=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.isSpotTradingAllowed")
		info_isMarginTradingAllowed=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.isMarginTradingAllowed")
		info_filters0filtertype=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.filters[0].filterType")
		info_filters0minPrice=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.filters[0].minPrice")
		info_filters0maxPrice=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.filters[0].maxPrice")
		info_filters0tickSize=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.filters[0].tickSize")
		info_filters1filtertype=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.filters[0].filterType")
		info_filters1minQty=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.filters[0].minQty")
		info_filters1maxQty=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.filters[0].maxQty")
		info_filters1stepSize=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.filters[0].stepSize")
		info_filters2filtertype=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.filters[0].filterType")
		info_filters2limit=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.filters[0].limit")
		info_filters3filtertype=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.filters[0].filterType")
		info_filters3minQty=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.filters[0].minQty")
		info_filters3maxQty=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.filters[0].maxQty")
		info_filters3stepSize=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.filters[0].stepSize")
		info_filters4filtertype=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.filters[0].filterType")
		info_filters4minTrailingAboveDelta=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.filters[0].minTrailingAboveDelta")
		info_filters4maxTrailingAboveDelta=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.filters[0].maxTrailingAboveDelta")
		info_filters4minTrailingBelowDelta=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.filters[0].minTrailingBelowDelta")
		info_filters4maxTrailingBelowDelta=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.filters[0].maxTrailingBelowDelta")
		info_filters5filtertype=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.filters[0].filterType")
		info_filters5bidMultiplierUp=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.filters[0].bidMultiplierUp")
		info_filters5bidMultiplierDown=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.filters[0].bidMultiplierDown")
		info_filters5askMultiplierUp=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.filters[0].askMultiplierUp")
		info_filters5askMultiplierDown=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.filters[0].askMultiplierDown")
		info_filters5avgPriceMins=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.filters[0].avgPriceMins")
		info_filters6filtertype=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.filters[0].filterType")
		info_filters6minNotional=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.filters[0].minNotional")
		info_filters6applyMinToMarket=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.filters[0].applyMinToMarket")
		info_filters6maxNotional=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.filters[0].maxNotional")
		info_filters6applyMaxToMarket=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.filters[0].applyMaxToMarket")
		info_filters6avgPriceMins=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.filters[0].avgPriceMins")
		info_filters7filtertype=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.filters[0].filterType")
		info_filters7maxNumOrders=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.filters[0].maxNumOrders")
		info_filters8filtertype=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.filters[0].filterType")
		info_filters8maxNumAlgoOrders=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.filters[0].maxNumAlgoOrders")
		info_permissions0=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.permissions[0]")
		info_permissions1=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.permissions[1]")
		info_permissions2=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.permissions[2]")
		info_permissions3=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.permissions[3]")
		info_permissions4=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.permissions[4]")
		info_permissions5=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.permissions[5]")
		info_permissions6=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.permissions[6]")
		info_permissions7=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.permissions[7]")
		info_permissions8=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.permissions[8]")
		info_permissions9=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.permissions[9]")
		info_permissions10=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.permissions[10]")
		info_permissions11=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.permissions[11]")
		info_permissions12=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.permissions[12]")
		info_permissions13=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.permissions[13]")
		info_permissions14=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.permissions[14]")
		info_permissions15=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.permissions[15]")
		info_permissions16=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.permissions[16]")
		info_permissions17=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.permissions[17]")
		info_permissions18=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.permissions[18]")
		info_permissions19=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.permissions[19]")
		info_permissions20=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.permissions[20]")
		info_permissions21=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.permissions[21]")
		info_permissions22=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.permissions[22]")
		info_defaultSelfTradePreventionMode=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.defaultSelfTradePreventionMode")
		info_allowedSelfTradePreventionModes0=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.allowedSelfTradePreventionModes[0]")
		info_allowedSelfTradePreventionModes1=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.allowedSelfTradePreventionModes[1]")
		info_allowedSelfTradePreventionModes2=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].info.allowedSelfTradePreventionModes[2]")
		limits_amountMin=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].limits.amount.min")
		limits_amountMax=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].limits.amount.max")
		limits_priceMin=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].limits.price.min")
		limits_priceMax=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].limits.price.max")
		limits_cost=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].limits.cost")
		limits_precisionAmount=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].limits.precision.amount")
		limits_precisionPrice=$(echo "$json_dataBINCEX" | jq -r ".[$contatore].limits.precision.price")

		# Chiamata alla funzione per inserire i dati
insert_dataBinance "$id_symbol" "$symbol" "$base" "$quote" "$info_symbol" "$info_status" "$info_baseAsset" "$info_baseAssetPrecision" "$info_quoteAsset" \
					"$info_quotePrecision" "$info_quoteAssetPrecision" "info_baseCommissionPrecision" "info_quoteCommissionPrecision" "info_orderTypes0" "info_orderTypes1" "info_orderTypes2" \
					"info_orderTypes3" "info_orderTypes4" "info_icebergAllowed" "info_ocoAllowed" "info_quoteOrderQtyMarketAllowed" "info_allowTrailingStop" "info_cancelReplaceAllowed" \
					"info_isSpotTradingAllowed" "info_isMarginTradingAllowed" "info_filters0filtertype" "info_filters0minPrice" "info_filters0maxPrice" "info_filters0tickSize" \
					"info_filters1filtertype" "info_filters1minQty" "info_filters1maxQty" "info_filters1stepSize" "info_filters2filtertype" "info_filters2limit" "info_filters3filtertype" \
					"info_filters3minQty" "info_filters3maxQty" "info_filters3stepSize" "info_filters4filtertype" "info_filters4minTrailingAboveDelta" "info_filters4maxTrailingAboveDelta" \
					"info_filters4minTrailingBelowDelta" "info_filters4maxTrailingBelowDelta" "info_filters5filtertype" "info_filters5bidMultiplierUp" "info_filters5bidMultiplierDown" \
					"info_filters5askMultiplierUp" "info_filters5askMultiplierDown" "info_filters5avgPriceMins" "info_filters6filtertype" "info_filters6minNotional" "info_filters6applyMinToMarket" \
					"info_filters6maxNotional" "info_filters6applyMaxToMarket" "info_filters6avgPriceMins" "info_filters7filtertype" "info_filters7maxNumOrders" "info_filters8filtertype" \
					"info_filters8maxNumAlgoOrders" "info_permissions0" "info_permissions1" "info_permissions2" "info_permissions3" "info_permissions4" "info_permissions5" "info_permissions6" \
					"info_permissions7" "info_permissions8" "info_permissions9" "info_permissions10" "info_permissions11" "info_permissions12" "info_permissions13" "info_permissions14" \
					"info_permissions15" "info_permissions16" "info_permissions17" "info_permissions18" "info_permissions19" "info_permissions20" "info_permissions21" "info_permissions22" \
					"info_defaultSelfTradePreventionMode" "info_allowedSelfTradePreventionModes0" "info_allowedSelfTradePreventionModes1" "info_allowedSelfTradePreventionModes2" \
					"limits_amountMin" "limits_amountMax" "limits_priceMin" "limits_priceMax" "limits_cost" "limits_precisionAmount" "limits_precisionPrice" 

		echo "$id_symbol"

		 ((contatore++))
		
	done
  
}




RecoveDataExchange() {
    # Recupera la data dalla tabella StampExchange in SQLite
    data=$(sqlite3 ConfigDB.db "SELECT data FROM StampExchange WHERE id = 1;")

    if [ -z "$data" ]; then
        # Se la data è vuota, inserisci la data di oggi e lancia la funzione Extract
        oggi=$(date +"%Y-%m-%d")
        sqlite3 ConfigDB.db "INSERT INTO StampExchange (id, data) VALUES (1, '$oggi');"
        Extract 
    else
        # Se c'è una data, confrontala con la data di oggi
        oggi=$(date +"%Y-%m-%d")
        if [ "$data" == "$oggi" ]; then
            # Se sono uguali, lancia RunProgram
            #RunProgram
            Extract
        else
            # Se sono diversi, cancella la vecchia data, inserisci quella nuova e lancia Extract
            sqlite3 ConfigDB.db "DELETE FROM StampExchange WHERE id = 1;"
            sqlite3 ConfigDB.db "INSERT INTO StampExchange (id, data) VALUES (1, '$oggi');"
            Extract
        fi
    fi
}
set +x
# Funzione per controllare se una porta è aperta
check_port() {
    host="$1"
    port="$2"
    
    # Utilizza netcat per verificare se la porta è aperta
    nc -z "$host" "$port"
    return $?
}

# Controlla se la porta 3000 è aperta
check_port "127.0.0.1" 3000

if [ $? -eq 0 ]; then
    echo "La porta 3000 è già aperta."
    RecoveDataExchange
else
    # Se la porta non è aperta, esegui il comando Docker
    echo "La porta 3000 non è aperta. Tentativo di avviare il container Docker..."
    docker run -p 3000:3000 docker.io/ccxtrest/ccxt-rest

    # Controlla di nuovo se la porta è aperta dopo aver avviato il container Docker
    check_port "127.0.0.1" 3000

    if [ $? -eq 0 ]; then
        echo "Il container Docker è stato avviato con successo."
    else
        echo "Errore: Impossibile avviare il container Docker o aprire la porta 3000."
        exit 1
    fi
fi

# Continua con il resto dello script...
# Puoi inserire qui il codice aggiuntivo che desideri eseguire

Ce que j’ai essayé :

j’essaye d’insérer aussi avec EOF

Solution 2

Etes-vous sûr d’avoir le BinanceCex table dans le fichier SQLite ConfigDB.db?
Vérifiez votre fichier de base de données

Terminal
$[k5054@localhost]$  sqlite3 ConfigDB.db .schema
CREATE TABLE BinanceCex( id int,  ... );
CREATE TABLE StampExchange( ... );
$[k5054@localhost]$ 

Êtes-vous sûr que le fichier de base de données est ConfigDB.db et non Config.db ou Config.db ? N’oubliez pas que la casse est importante sous Linux, donc configdb.db, ConfigDB.db et ConfigDB.DB sont tous des fichiers différents.

Suggestion : utilisez une variable pour contenir le nom de votre base de données et les noms de tables

Frapper
database="ConfigDB.db"
b_cex="BinanceCex"
stamp_ex="StampExchange"

sqlite3 $database "Insert into $b_cex values ( ... )"

Maintenant, si vous découvrez que la table devrait être appelée BinanceExchangeplutôt que BinanceCexil vous suffit de modifier votre code dans un emplacement.

Solution 1

[ad_2]

コメント

Titre et URL copiés