commodities convert dict key to value, vice versa

This commit is contained in:
Justin 2023-06-12 16:31:08 +08:00 committed by GitHub
parent 5296819e48
commit 016068e393
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -173,8 +173,18 @@ def index():
stocks_settings = json.load(f)
f.close()
dict1 = {
"Aluminum": "ALU", "Brent Crude Oil": "BRENTOIL", "Coffee": "COFFEE", "Copper": "XCU", "Corn": "CORN", "Cotton": "COTTON", "Gold": "XAU",
"Palladium": "XPD", "Platinum": "XPT", "Rice": "RICE", "Silver": "XAG", "Soybean": "SOYBEAN", "Sugar": "SUGAR", "Wheat": "WHEAT",
"WTI Crude Oil": "WTIOIL", "Ethanol": "ETHANOL", "Crude Palm Oil": "CPO", "Natural Gas": "NG", "Cocoa": "COCOA", "Robusta": "ROBUSTA",
"Lumber": "LUMBER", "Rubber": "RUBBER", "Live Cattle": "CATTLE", "Lean Hog": "HOG"}
f = open('csv/commodities_settings.json', 'r')
commodities_settings = json.load(f)
try:
reversed_dict1 = {value: key for key, value in dict1.items()}
commodities_settings['symbols'] = [reversed_dict1[value] for value in commodities_settings['symbols']]
except:
pass
f.close()
f = open('csv/indices_settings.json', 'r')
@ -999,6 +1009,12 @@ def combine_dict(current_settings, input_symbols, current_key):
def save_trade_settings(input_settings):
commodities_dict = {
"Aluminum": "ALU", "Brent Crude Oil": "BRENTOIL", "Coffee": "COFFEE", "Copper": "XCU", "Corn": "CORN", "Cotton": "COTTON", "Gold": "XAU",
"Palladium": "XPD", "Platinum": "XPT", "Rice": "RICE", "Silver": "XAG", "Soybean": "SOYBEAN", "Sugar": "SUGAR", "Wheat": "WHEAT",
"WTI Crude Oil": "WTIOIL", "Ethanol": "ETHANOL", "Crude Palm Oil": "CPO", "Natural Gas": "NG", "Cocoa": "COCOA", "Robusta": "ROBUSTA",
"Lumber": "LUMBER", "Rubber": "RUBBER", "Live Cattle": "CATTLE", "Lean Hog": "HOG"
}
filename = input_settings['feature'].lower() + '_settings.json'
f = open('csv/' + filename, 'r')
@ -1016,7 +1032,12 @@ def save_trade_settings(input_settings):
if input_settings['feature'] == 'Stocks':
current_settings['prepost'] = input_settings['prepost']
if input_settings['feature'] == 'Stocks' or input_settings['feature'] == 'Crypto':
current_settings['chart'] = input_settings['chart']
current_settings['chart'] = input_settings['chart']
if input_settings['feature'] == 'Commodities':
try:
input_settings['symbols'] = [commodities_dict[symbol] for symbol in input_settings['symbols']]
except:
pass
current_settings = combine_dict(current_settings, input_settings['symbols'], 'symbols')