When training jukebox on notebooks, why is our training data is stuck at 0 for Sample length and min duration? - pytorch

Hps data:
/home/dotty/anaconda3/envs/JukVersionRoy/jukebox/train.py --hps=small_vqvae --name=small_vqvae --sample_length=9999999999999 --bs=2 --audio_files_dir=/home/dotty/anaconda3/envs/JukVersionRoy/jukebox/my-training-data --labels=False --train --aug_shift --aug_blend
Here
/
HPS ***************
{'rcall_command': '<unknown_rcall_command>', 'git_commit': '<unknown_git_commit>', 'name': '', 'debug_mem': False, 'debug_eval_files': False, 'debug_speed': False, 'debug_iters': 100, 'debug_batch': False, 'debug_grad_accum': False, 'debug_inputs': False, 'local_path': '', 'local_logdir': 'logs', 'max_len': 24, 'max_log': 32, 'save': True, 'save_iters': 20000, 'seed': 0, 'prior': False, 'log_steps': 100, 'func': '', 'audio_files_dir': '', 'finetune': '', 'english_only': False, 'bs': 1, 'bs_sample': 1, 'nworkers': 1, 'aug_shift': False, 'aug_blend': False, 'train_test_split': 0.9, 'train_shrink_factor': 1.0, 'test_shrink_factor': 1.0, 'p_unk': 0.1, 'min_duration': None, 'max_duration': None, 'n_tokens': 0, 'n_vocab': 0, 'use_tokens': False, 'curr_epoch': -1, 'restore_vqvae': '', 'levels': 2, 'downs_t': (1, 1), 'strides_t': (2, 2), 'hvqvae_multipliers': None, 'revival_threshold': 1.0, 'emb_width': 64, 'l_bins': 512, 'l_mu': 0.99, 'commit': 1.0, 'spectral': 0.0, 'multispectral': 1.0, 'loss_fn': 'l2', 'linf_k': 2048, 'lmix_l1': 0.0, 'lmix_l2': 0.0, 'lmix_linf': 0.0, 'use_bottleneck': True, 'depth': 3, 'width': 128, 'm_conv': 1.0, 'dilation_growth_rate': 1, 'dilation_cycle': None, 'vqvae_reverse_decoder_dilation': True, 'restore_prior': '', 'restore_prior_ddp': False, 'max_bow_genre_size': None, 'y_bins': 0, 'level': 0, 'cond_levels': None, 't_bins': 64, 'y_cond_as_bias': False, 'copy_input': False, 'merged_decoder': False, 'single_enc_dec': False, 'alignment_layer': None, 'alignment_head': None, 'n_ctx': 1024, 'prior_depth': 3, 'prior_width': 128, 'heads': 1, 'attn_order': 0, 'blocks': None, 'spread': None, 'attn_dropout': 0.0, 'resid_dropout': 0.0, 'emb_dropout': 0.0, 'zero_out': False, 'res_scale': False, 'pos_init': False, 'init_scale': 1.0, 'm_attn': 0.25, 'm_mlp': 1.0, 'c_res': 0, 'c_attn': 0, 'c_mlp': 0, 'cond_depth': 3, 'cond_width': 128, 'cond_m_conv': 1.0, 'cond_zero_out': False, 'cond_res_scale': False, 'cond_dilation_growth_rate': 1, 'cond_dilation_cycle': None, 'cond_c_res': 0, 'primed_chunk_size': None, 'selected_artists': '', 'temp_top': 1.0, 'temp_rest': 0.99, 'sample_length_in_seconds': 24, 'total_sample_length_in_seconds': 240, 'prime_loss_fraction': 0.1, 'restore_decoder': '', 'prime_depth': 3, 'prime_width': 128, 'prime_heads': 1, 'prime_attn_order': 0, 'prime_blocks': None, 'prime_spread': None, 'prime_attn_dropout': 0.0, 'prime_resid_dropout': 0.0, 'prime_emb_dropout': 0.0, 'prime_zero_out': False, 'prime_res_scale': False, 'prime_pos_init': False, 'prime_init_scale': 1.0, 'prime_m_attn': 0.25, 'prime_m_mlp': 1.0, 'prime_c_res': 0, 'prime_c_attn': 0, 'prime_c_mlp': 0, 'prime_rel_attn': False, 'prime_posemb_timescale': 10000, 'epochs': 10000, 'lr': 0.0003, 'clip': 1.0, 'beta1': 0.9, 'beta2': 0.999, 'ignore_grad_norm': 0, 'weight_decay': 0.0, 'eps': 1e-08, 'lr_warmup': 100.0, 'lr_decay': 10000000000.0, 'lr_gamma': 1.0, 'lr_scale': 1.0, 'lr_use_linear_decay': False, 'lr_start_linear_decay': 0, 'lr_use_cosine_decay': False, 'fp16': False, 'fp16_params': False, 'fp16_loss_scale': None, 'fp16_scale_window': 1000.0, 'fp16_opt': False, 'labels': True, 'labels_v3': False, 'dump': False, 'ema': True, 'ema_fused': True, 'cpu_ema': False, 'cpu_ema_freq': 100, 'reset_best_loss': False, 'reset_step': False, 'reset_opt': False, 'reset_shd': False, 'train': False, 'test': False, 'sample': False, 'sampler': 'ancestral', 'codes_logdir': '', 'date': None, 'labeller': 'top_genres', 'label_line': 0, 'iters_before_update': 1, 'grad_accum_iters': 0, 'mu': None, 'piped': False, 'pipe_depth': 8, 'break_train': 10000000000.0, 'break_test': 10000000000.0, 'exit_train': 10000000000.0, 'n_fft': 1024, 'hop_length': 256, 'window_size': 1024, 'sr': 44100, 'channels': 2, 'wav': '', 'n_inps': 1, 'n_hops': 2, 'n_segment': 1, 'n_total_segment': 1, 'n_segment_each': 1, 'prime_chunks': 4, 'sample_length': 0, 'sample_hop_length': 30000, 'max_silence_pad_length': 0, 'ignore_boundaries': False, 'use_nonrelative_specloss': True, 'multispec_loss_n_fft': (2048, 1024, 512), 'multispec_loss_hop_length': (240, 120, 50), 'multispec_loss_window_size': (1200, 600, 240), 'bucket': 128, 'ngpus': 16, 'argv': '/home/dotty/anaconda3/envs/JukVersionRoy/jukebox/train.py --hps=small_vqvae --name=small_vqvae --sample_length=9999999999999 --bs=2 --audio_files_dir=/home/dotty/anaconda3/envs/JukVersionRoy/jukebox/my-training-data --labels=False --train --aug_shift --aug_blend'}
SAMPLE LENGTH:
0
SAMPLE RATE:
44100
SAMPLE LENGTH / SAMPLE RATE:
0.0
MIN DURATION:
0
AssertionError Traceback (most recent call last)
/tmp/ipykernel_14312/1841762803.py in <module>
325
326
--> 327 run()
/tmp/ipykernel_14312/1841762803.py in run(hps, port, **kwargs)
283 print("HPS ***************")
284 print(hps)
--> 285 data_processor = DataProcessor(hps)
286
287 # Setup models
~/anaconda3/envs/JukVersionRoy/jukebox/data/data_processor.py in init(self, hps)
24 class DataProcessor():
25 def init(self, hps):
---> 26 self.dataset = FilesAudioDataset(hps)
27 duration = 1 if hps.prior else 600
28 hps.bandwidth = calculate_bandwidth(self.dataset, hps, duration=duration)
~/anaconda3/envs/JukVersionRoy/jukebox/data/files_dataset.py in init(self, hps)
24 print("MIN DURATION:")
25 print(self.min_duration)
---> 26 assert hps.sample_length / hps.sr < self.min_duration, f'Sample length {hps.sample_length} per sr {hps.sr} ({hps.sample_length / hps.sr:.2f}) should be shorter than min duration {self.min_duration}'
27 self.aug_shift = hps.aug_shift
28 self.labels = hps.labels
AssertionError: Sample length 0 per sr 44100 (0.00) should be shorter than min duration 0
Our files are not being read in, as the sample stayed at 44100 when we changed the files being read in. we went through all the files dataset.py, dataprocessor.py and audio_utils.py and could not finds where exactly the input files is being registered. Our path is correct. We are trying to sample length and min duration to be read in correctly.

Related

Understanding the config file of paraphrase mpnet base v2?

Here is the config file of the paraphrase mpnet transformer model and I would like to understand the meaning with examples of the hidden_size and num_hidden_layers parameters.
{
"_name_or_path": "old_models/paraphrase-mpnet-base-v2/0_Transformer",
"architectures": [
"MPNetModel"
],
"attention_probs_dropout_prob": 0.1,
"bos_token_id": 0,
"eos_token_id": 2,
"hidden_act": "gelu",
"hidden_dropout_prob": 0.1,
"hidden_size": 768,
"initializer_range": 0.02,
"intermediate_size": 3072,
"layer_norm_eps": 1e-05,
"max_position_embeddings": 514,
"model_type": "mpnet",
"num_attention_heads": 12,
"num_hidden_layers": 12,
"pad_token_id": 1,
"relative_attention_num_buckets": 32,
"transformers_version": "4.7.0",
"vocab_size": 30527
}

ERC20 Event Listener in Rust Programming

I am trying to program an erc20 event listener using Rust programming language and trying to get events from a particular block to the latest block. But even though I have specified from the block it just gives an output from the latest block, not from the specified block. Below is my code:
use hex_literal::hex;
use std::time;
use web3::{
contract::{Contract, Options},
futures::{future, StreamExt},
types::{FilterBuilder, Address},
};
use std::str::FromStr;
use web3::types::{BlockNumber, U64};
#[tokio::main]
async fn main() -> web3::contract::Result<()> {
let web3 = web3::Web3::new(web3::transports::WebSocket::new("wss:").await?);
let filter = FilterBuilder::default()
// this is BSC: TokenHub
.from_block(BlockNumber::Number(U64::from(15255440)))
.address(vec![Address::from_str("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2").unwrap()])
/* .topics(
// this is 'Transfer (index_topic_1 address from, index_topic_2 address to, uint256 value)' event
// use https://emn178.github.io/online-tools/keccak_256.html, and type in 'Transfer(address,address,uint256)'
// it will return result hash as used in next line
Some(vec![hex!("d282f389399565f3671145f5916e51652b60eee8e5c759293a2f5771b8ddfd2e").into()]),
None,
None,
None,
)*/
.build();
let sub = web3.eth_subscribe().subscribe_logs(filter).await?;
sub.for_each(|log| {
println!("{:?}", log);
future::ready(())
}).await;
Ok(())
}
Output is like:
Ok(Log { address: 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2, topics: [0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef, 0x000000000000000000000000007933790a4f00000099e9001629d9fe7775b800, 0x000000000000000000000000938625591adb4e865b882377e2c965f9f9b85e34],
data: Bytes([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 76, 65, 133, 173, 92, 182, 64, 0]),
block_hash: Some(0xa076bddbfd69560de59c9be11cf5ae6f8782ace08d96c4945f3d15d05e91100f),
block_number: Some(15256705),
transaction_hash:Some(0xdd603b88c60e5b5a1aaebedb53d38df626b72d6ec2a11530cf50a8957082f404),
transaction_index: Some(0),
log_index: Some(0),
transaction_log_index: None,
log_type: None,
removed: Some(false) })
Ok(Log { address: 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2, topics: [0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef, 0x0000000000000000000000002dfa8a0413255ecca71
3b6d1c1e28e634e021478, 0x000000000000000000000000938625591adb4e865b882377e2c965f9f9b85e34],
data: Bytes([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 76,81, 115, 63, 131, 0, 0]),
block_hash:Some(0xa076bddbfd69560de59c9be11cf5ae6f8782ace08d96c4945f3d15d05e91100f),
block_number: Some(15256705),
transaction_hash:Some(0xcf4b91c9c465e8c2b22126ad580e92988162bf51be7520e5cc6dfe9f878faa06),
transaction_index: Some(1),
log_index: Some(4),
transaction_log_index: None,
log_type: None,
removed: Some(false) })
Ok(Log { address: 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,
topics: [0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef, 0x000000000000000000000000938625591adb4e865b882377e2c965f9f9b85e34, 0x000000000000000000000000007933790a4f00000099e9001629d9fe7775b800],
data: Bytes([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 76, 170, 83, 197, 89, 150, 0, 0]),
block_hash: Some(0xa076bddbfd69560de59c9be11cf5ae6f8782ace08d96c4945f3d15d05e91100f),
block_number: Some(15256705),
transaction_hash:Some(0xd45f5b511cf832b407182751c451c32b27a203d8ab60136f9719cf61523b0e9a),
transaction_index: Some(2),
log_index: Some(9),
transaction_log_index: None,
log_type: None, removed: Some(false) })
Ok(Log { address: 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,
topics: [0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef, 0x000000000000000000000000000000000035b5e5ad9019092c665357240f594e, 0x0000000000000000000000002f8ac927aa94293461c75406e90ec0ccfb2748d9],
data: Bytes([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 90,
119, 187, 148, 242, 21, 156]),
block_hash: Some(0xa076bddbfd69560de59c9be11cf5ae6f8782ace08d96c4945f3d15d05e91100f),
block_number: Some(15256705),
transaction_hash:Some(0xd36df58ffe146202ffb9ef2e29e64380991a674c820bb8a1f6a776b9468baa86),
transaction_index: Some(3),
log_index: Some(12),
transaction_log_index: None,
log_type: None,
removed: Some(false) })
I got to the conclusion that the above code gives the output of the event that will happen. So when we add from_block: 15255440, the event has already happened. And in that particular block, no other event is going to happen. So you will get the output from the latest block.
To test this in code add this:
let filter = FilterBuilder::default()
// this is BSC: TokenHub
.from_block(BlockNumber::Number(U64::from(15257125)))
.to_block(BlockNumber::Number(U64::from(15257130)))
.address(vec![Address::from_str("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2").unwrap()])
.build();
Keep in mind to replace 15257125(i.e from_block) and 15257130(i.e. to_block) with the future block which has not been mined yet. And when that block will be mined you will get events between that two blocks.

Unrecognized configuration class <class 'transformers.models.bert.configuration_bert.BertConfig'> for this kind of AutoModel: AutoModelForSeq2SeqLM

Model type should be one of BartConfig, PLBartConfig, BigBirdPegasusConfig, M2M100Config, LEDConfig, BlenderbotSmallConfig, MT5Config, T5Config, PegasusConfig, MarianConfig, MBartConfig, BartConfig, BlenderbotConfig, FSMTConfig, XLMProphetNetConfig, ProphetNetConfig, EncoderDecoderConfig.
I am trying to load a fine-tuned Bert model for machine translation using AutoModelForSeq2SeqLM but it can't recognize the configuration class.
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, Seq2SeqTrainingArguments, Seq2SeqTrainer
model = AutoModelForSeq2SeqLM.from_pretrained('/content/drive/MyDrive/Models/CSE498')
Config File
{
"_name_or_path": "ckiplab/albert-tiny-chinese",
"architectures": [
"BertForMaskedLM"
],
"attention_probs_dropout_prob": 0.0,
"bos_token_id": 101,
"classifier_dropout": null,
"classifier_dropout_prob": 0.1,
"down_scale_factor": 1,
"embedding_size": 128,
"eos_token_id": 102,
"gap_size": 0,
"hidden_act": "gelu",
"hidden_dropout_prob": 0.0,
"hidden_size": 312,
"initializer_range": 0.02,
"inner_group_num": 1,
"intermediate_size": 1248,
"layer_norm_eps": 1e-12,
"max_position_embeddings": 512,
"model_type": "bert",
"net_structure_type": 0,
"num_attention_heads": 12,
"num_hidden_groups": 1,
"num_hidden_layers": 4,
"num_memory_blocks": 0,
"pad_token_id": 0,
"position_embedding_type": "absolute",
"tokenizer_class": "BertTokenizerFast",
"torch_dtype": "float32",
"transformers_version": "4.18.0",
"type_vocab_size": 2,
"use_cache": true,
"vocab_size": 30522
}
This is because BERT itself is not a seq2seq model. You can consider using a pre-trained BART instead.

Binance API: How do I get the quantity precision of a futures asset?

I want to get the price precision of any futures asset.
What I tried:
client.get_symbol_info(symbol='My Symbol')
But this returns the precision of the Spot and I need the precision of the futures.
So theres this Command:
client.futures_exchange_info()
Which return this:
{'timezone': 'UTC', 'serverTime': 1630437033153, 'futuresType': 'U_MARGINED', 'rateLimits': [{'rateLimitType': 'REQUEST_WEIGHT', 'interval': 'MINUTE', 'intervalNum': 1, 'limit': 2400},
{'rateLimitType': 'ORDERS', 'interval': 'MINUTE', 'intervalNum': 1, 'limit': 1200},
{'rateLimitType': 'ORDERS', 'interval': 'SECOND', 'intervalNum': 10, 'limit': 300}],
'exchangeFilters': [],
'assets': [{'asset': 'USDT', 'marginAvailable': True, 'autoAssetExchange': '-10000'},
{'asset': 'BTC', 'marginAvailable': True, 'autoAssetExchange': '-0.00100000'},
{'asset': 'BNB', 'marginAvailable': True, 'autoAssetExchange': '-10'},
{'asset': 'ETH', 'marginAvailable': True, 'autoAssetExchange': '-5'},
{'asset': 'BUSD', 'marginAvailable': True, 'autoAssetExchange': '-10000'}],
'symbols': [{'symbol': 'BTCUSDT', 'pair': 'BTCUSDT', 'contractType': 'PERPETUAL', 'deliveryDate': 4133404800000, 'onboardDate': 1569398400000, 'status': 'TRADING', 'maintMarginPercent': '2.5000', 'requiredMarginPercent': '5.0000', 'baseAsset': 'BTC', 'quoteAsset': 'USDT', 'marginAsset': 'USDT', 'pricePrecision': 2, 'quantityPrecision': 3, 'baseAssetPrecision': 8, 'quotePrecision': 8, 'underlyingType': 'COIN', 'underlyingSubType': [], 'settlePlan': 0, 'triggerProtect': '0.0500', 'liquidationFee': '0.012000', 'marketTakeBound': '0.05', 'filters': [{'minPrice': '556.72', 'maxPrice': '4529764', 'filterType': 'PRICE_FILTER', 'tickSize': '0.01'}, {'stepSize': '0.001', 'filterType': 'LOT_SIZE', 'maxQty': '1000', 'minQty': '0.001'}, {'stepSize': '0.001', 'filterType': 'MARKET_LOT_SIZE', 'maxQty': '200', 'minQty': '0.001'}, {'limit': 200, 'filterType': 'MAX_NUM_ORDERS'}, {'limit': 10, 'filterType': 'MAX_NUM_ALGO_ORDERS'}, {'notional': '5', 'filterType': 'MIN_NOTIONAL'}, {'multiplierDown': '0.9500', 'multiplierUp': '1.0500', 'multiplierDecimal': '4', 'filterType': 'PERCENT_PRICE'}], 'orderTypes': ['LIMIT', 'MARKET', 'STOP', 'STOP_MARKET', 'TAKE_PROFIT', 'TAKE_PROFIT_MARKET', 'TRAILING_STOP_MARKET'], 'timeInForce': ['GTC', 'IOC', 'FOK', 'GTX']},
{'symbol': 'ETHUSDT', 'pair': 'ETHUSDT', 'contractType': 'PERPETUAL', 'deliveryDate': 4133404800000, 'onboardDate': 1569398400000, 'status': 'TRADING', 'maintMarginPercent': '2.5000', 'requiredMarginPercent': '5.0000', 'baseAsset': 'ETH', 'quoteAsset': 'USDT', 'marginAsset': 'USDT', 'pricePrecision': 2, 'quantityPrecision': 3, 'baseAssetPrecision': 8, 'quotePrecision': 8, 'underlyingType': 'COIN', 'underlyingSubType': [], 'settlePlan': 0, 'triggerProtect': '0.0500', 'liquidationFee': '0.005000', 'marketTakeBound': '0.05', 'filters': [{'minPrice': '39.86', 'maxPrice': '306177', 'filterType': 'PRICE_FILTER', 'tickSize': '0.01'}, {'stepSize': '0.001', 'filterType': 'LOT_SIZE', 'maxQty': '10000', 'minQty': '0.001'}, {'stepSize': '0.001', 'filterType': 'MARKET_LOT_SIZE', 'maxQty': '2000', 'minQty': '0.001'}, {'limit': 200, 'filterType': 'MAX_NUM_ORDERS'}, {'limit': 10, 'filterType': 'MAX_NUM_ALGO_ORDERS'}, {'notional': '5', 'filterType': 'MIN_NOTIONAL'}, {'multiplierDown': '0.9500', 'multiplierUp': '1.0500', 'multiplierDecimal': '4', 'filterType': 'PERCENT_PRICE'}], 'orderTypes': ['LIMIT', 'MARKET', 'STOP', 'STOP_MARKET', 'TAKE_PROFIT', 'TAKE_PROFIT_MARKET', 'TRAILING_STOP_MARKET'], 'timeInForce': ['GTC', 'IOC', 'FOK', 'GTX']}...
and so on.
I need to access the Value of 'quantityPrecision':.
Is there a way to like filter this list for the symbol value like 'BTCUSDT' and then return the Value of 'quantityPrecision':?
Thanks in Advance for any help.
info = client.futures_exchange_info()
def get_precision(symbol):
for x in info['symbols']:
if x['symbol'] == symbol:
return x['quantityPrecision']
print(get_precision('LTCUSDT'))
async function getLimits(asset) {
var filtered = await client.futures_exchange_info()
return Object.values( filtered.symbols).filter(O => O.symbol===asset)[0]
}
getLimits("BTCUSDT")

how to convert data to standard json

messages=%5B%7B%22values%22%3A+%7B%22momentum%22%3A+%220.00%22%7D%2C+%22exchange%22%3A+%22binance%22%2C+%22market%22%3A+%22BNT%2FETH%22%2C+%22base_currency%22%3A+%22BNT%22%2C+%22quote_currency%22%3A+%22ETH%22%2C+%22indicator%22%3A+%22momentum%22%2C+%22indicator_number%22%3A+0%2C+%22analysis%22%3A+%7B%22config%22%3A+%7B%22enabled%22%3A+true%2C+%22alert_enabled%22%3A+true%2C+%22alert_frequency%22%3A+%22once%22%2C+%22signal%22%3A+%5B%22momentum%22%5D%2C+%22hot%22%3A+0%2C+%22cold%22%3A+0%2C+%22candle_period%22%3A+%224h%22%2C+%22period_count%22%3A+10%7D%2C+%22status%22%3A+%22hot%22%7D%2C+%22status%22%3A+%22hot%22%2C+%22last_status%22%3A+%22hot%22%2C+%22prices%22%3A+%22+Open%3A+0.000989+High%3A+0.000998+Low%3A+0.000980+Close%3A+0.000998%22%2C+%22lrsi%22%3A+%22%22%2C+%22creation_date%22%3A+%222020-05-10+16%3A16%3A23%22%2C+%22hot_cold_label%22%3A+%22%22%2C+%22indicator_label%22%3A+%22%22%2C+%22price_value%22%3A+%7B%22open%22%3A+0.000989%2C+%22high%22%3A+0.000998%2C+%22low%22%3A+0.00098%2C+%22close%22%3A+0.000998%7D%2C+%22decimal_format%22%3A+%22%25.6f%22%7D%2C+%7B%22values%22%3A+%7B%22leading_span_a%22%3A+%220.00%22%2C+%22leading_span_b%22%3A+%220.00%22%7D%2C+%22exchange%22%3A+%22binance%22%2C+%22market%22%3A+%22BNT%2FETH%22%2C+%22base_currency%22%3A+%22BNT%22%2C+%22quote_currency%22%3A+%22ETH%22%2C+%22indicator%22%3A+%22ichimoku%22%2C+%22indicator_number%22%3A+1%2C+%22analysis%22%3A+%7B%22config%22%3A+%7B%22enabled%22%3A+true%2C+%22alert_enabled%22%3A+true%2C+%22alert_frequency%22%3A+%22once%22%2C+%22signal%22%3A+%5B%22leading_span_a%22%2C+%22leading_span_b%22%5D%2C+%22hot%22%3A+true%2C+%22cold%22%3A+true%2C+%22candle_period%22%3A+%224h%22%2C+%22hot_label%22%3A+%22Bullish+Alert%22%2C+%22cold_label%22%3A+%22Bearish+Alert%22%2C+%22indicator_label%22%3A+%22ICHIMOKU+4+hr%22%2C+%22mute_cold%22%3A+false%7D%2C+%22status%22%3A+%22cold%22%7D%2C+%22status%22%3A+%22cold%22%2C+%22last_status%22%3A+%22cold%22%2C+%22prices%22%3A+%22+Open%3A+0.000989+High%3A+0.000998+Low%3A+0.000980+Close%3A+0.000998%22%2C+%22lrsi%22%3A+%22%22%2C+%22creation_date%22%3A+%222020-05-10+16%3A16%3A23%22%2C+%22hot_cold_label%22%3A+%22Bearish+Alert%22%2C+%22indicator_label%22%3A+%22ICHIMOKU+4+hr%22%2C+%22price_value%22%3A+%7B%22open%22%3A+0.000989%2C+%22high%22%3A+0.000998%2C+%22low%22%3A+0.00098%2C+%22close%22%3A+0.000998%7D%2C+%22decimal_format%22%3A+%22%25.6f%22%7D%2C+%7B%22values%22%3A+%7B%22bbp%22%3A+%220.96%22%2C+%22mfi%22%3A+%2298.05%22%7D%2C+%22exchange%22%3A+%22binance%22%2C+%22market%22%3A+%22BNT%2FETH%22%2C+%22base_currency%22%3A+%22BNT%22%2C+%22quote_currency%22%3A+%22ETH%22%2C+%22indicator%22%3A+%22bbp%22%2C+%22indicator_number%22%3A+1%2C+%22analysis%22%3A+%7B%22config%22%3A+%7B%22enabled%22%3A+true%2C+%22alert_enabled%22%3A+true%2C+%22alert_frequency%22%3A+%22once%22%2C+%22candle_period%22%3A+%224h%22%2C+%22period_count%22%3A+20%2C+%22hot%22%3A+0.09%2C+%22cold%22%3A+0.8%2C+%22std_dev%22%3A+2%2C+%22signal%22%3A+%5B%22bbp%22%2C+%22mfi%22%5D%2C+%22hot_label%22%3A+%22Lower+Band%22%2C+%22cold_label%22%3A+%22Upper+Band+BB%22%2C+%22indicator_label%22%3A+%22Bollinger+4+hr%22%2C+%22mute_cold%22%3A+false%7D%2C+%22status%22%3A+%22cold%22%7D%2C+%22status%22%3A+%22cold%22%2C+%22last_status%22%3A+%22cold%22%2C+%22prices%22%3A+%22+Open%3A+0.000989+High%3A+0.000998+Low%3A+0.000980+Close%3A+0.000998%22%2C+%22lrsi%22%3A+%22%22%2C+%22creation_date%22%3A+%222020-05-10+16%3A16%3A23%22%2C+%22hot_cold_label%22%3A+%22Upper+Band+BB%22%2C+%22indicator_label%22%3A+%22Bollinger+4+hr%22%2C+%22price_value%22%3A+%7B%22open%22%3A+0.000989%2C+%22high%22%3A+0.000998%2C+%22low%22%3A+0.00098%2C+%22close%22%3A+0.000998%7D%2C+%22decimal_format%22%3A+%22%25.6f%22%7D%5D
i need to convert this data in python3 to standard json for post json api
any solution ?
thanks
That looks like it's been URL form encoded.
Try
import urllib.parse
import json
# note **without** the message= part
stuff = "%5B%7B%22values%22%3A+%7B%22momentum%22%3A+%220.00%22%7D%2C+%22exchange%22%3A+%22binance%22%2C+%22market%22%3A+%22BNT%2FETH%22%2C+%22base_currency%22%3A+%22BNT%22%2C+%22quote_currency%22%3A+%22ETH%22%2C+%22indicator%22%3A+%22momentum%22%2C+%22indicator_number%22%3A+0%2C+%22analysis%22%3A+%7B%22config%22%3A+%7B%22enabled%22%3A+true%2C+%22alert_enabled%22%3A+true%2C+%22alert_frequency%22%3A+%22once%22%2C+%22signal%22%3A+%5B%22momentum%22%5D%2C+%22hot%22%3A+0%2C+%22cold%22%3A+0%2C+%22candle_period%22%3A+%224h%22%2C+%22period_count%22%3A+10%7D%2C+%22status%22%3A+%22hot%22%7D%2C+%22status%22%3A+%22hot%22%2C+%22last_status%22%3A+%22hot%22%2C+%22prices%22%3A+%22+Open%3A+0.000989+High%3A+0.000998+Low%3A+0.000980+Close%3A+0.000998%22%2C+%22lrsi%22%3A+%22%22%2C+%22creation_date%22%3A+%222020-05-10+16%3A16%3A23%22%2C+%22hot_cold_label%22%3A+%22%22%2C+%22indicator_label%22%3A+%22%22%2C+%22price_value%22%3A+%7B%22open%22%3A+0.000989%2C+%22high%22%3A+0.000998%2C+%22low%22%3A+0.00098%2C+%22close%22%3A+0.000998%7D%2C+%22decimal_format%22%3A+%22%25.6f%22%7D%2C+%7B%22values%22%3A+%7B%22leading_span_a%22%3A+%220.00%22%2C+%22leading_span_b%22%3A+%220.00%22%7D%2C+%22exchange%22%3A+%22binance%22%2C+%22market%22%3A+%22BNT%2FETH%22%2C+%22base_currency%22%3A+%22BNT%22%2C+%22quote_currency%22%3A+%22ETH%22%2C+%22indicator%22%3A+%22ichimoku%22%2C+%22indicator_number%22%3A+1%2C+%22analysis%22%3A+%7B%22config%22%3A+%7B%22enabled%22%3A+true%2C+%22alert_enabled%22%3A+true%2C+%22alert_frequency%22%3A+%22once%22%2C+%22signal%22%3A+%5B%22leading_span_a%22%2C+%22leading_span_b%22%5D%2C+%22hot%22%3A+true%2C+%22cold%22%3A+true%2C+%22candle_period%22%3A+%224h%22%2C+%22hot_label%22%3A+%22Bullish+Alert%22%2C+%22cold_label%22%3A+%22Bearish+Alert%22%2C+%22indicator_label%22%3A+%22ICHIMOKU+4+hr%22%2C+%22mute_cold%22%3A+false%7D%2C+%22status%22%3A+%22cold%22%7D%2C+%22status%22%3A+%22cold%22%2C+%22last_status%22%3A+%22cold%22%2C+%22prices%22%3A+%22+Open%3A+0.000989+High%3A+0.000998+Low%3A+0.000980+Close%3A+0.000998%22%2C+%22lrsi%22%3A+%22%22%2C+%22creation_date%22%3A+%222020-05-10+16%3A16%3A23%22%2C+%22hot_cold_label%22%3A+%22Bearish+Alert%22%2C+%22indicator_label%22%3A+%22ICHIMOKU+4+hr%22%2C+%22price_value%22%3A+%7B%22open%22%3A+0.000989%2C+%22high%22%3A+0.000998%2C+%22low%22%3A+0.00098%2C+%22close%22%3A+0.000998%7D%2C+%22decimal_format%22%3A+%22%25.6f%22%7D%2C+%7B%22values%22%3A+%7B%22bbp%22%3A+%220.96%22%2C+%22mfi%22%3A+%2298.05%22%7D%2C+%22exchange%22%3A+%22binance%22%2C+%22market%22%3A+%22BNT%2FETH%22%2C+%22base_currency%22%3A+%22BNT%22%2C+%22quote_currency%22%3A+%22ETH%22%2C+%22indicator%22%3A+%22bbp%22%2C+%22indicator_number%22%3A+1%2C+%22analysis%22%3A+%7B%22config%22%3A+%7B%22enabled%22%3A+true%2C+%22alert_enabled%22%3A+true%2C+%22alert_frequency%22%3A+%22once%22%2C+%22candle_period%22%3A+%224h%22%2C+%22period_count%22%3A+20%2C+%22hot%22%3A+0.09%2C+%22cold%22%3A+0.8%2C+%22std_dev%22%3A+2%2C+%22signal%22%3A+%5B%22bbp%22%2C+%22mfi%22%5D%2C+%22hot_label%22%3A+%22Lower+Band%22%2C+%22cold_label%22%3A+%22Upper+Band+BB%22%2C+%22indicator_label%22%3A+%22Bollinger+4+hr%22%2C+%22mute_cold%22%3A+false%7D%2C+%22status%22%3A+%22cold%22%7D%2C+%22status%22%3A+%22cold%22%2C+%22last_status%22%3A+%22cold%22%2C+%22prices%22%3A+%22+Open%3A+0.000989+High%3A+0.000998+Low%3A+0.000980+Close%3A+0.000998%22%2C+%22lrsi%22%3A+%22%22%2C+%22creation_date%22%3A+%222020-05-10+16%3A16%3A23%22%2C+%22hot_cold_label%22%3A+%22Upper+Band+BB%22%2C+%22indicator_label%22%3A+%22Bollinger+4+hr%22%2C+%22price_value%22%3A+%7B%22open%22%3A+0.000989%2C+%22high%22%3A+0.000998%2C+%22low%22%3A+0.00098%2C+%22close%22%3A+0.000998%7D%2C+%22decimal_format%22%3A+%22%25.6f%22%7D%5D"
parsed = urllib.parse.unquote_plus(stuff) # <<< encoded form, get rid of +
as_json = json.loads(parsed)
print(as_json)
gives me
[{'values': {'momentum': '0.00'}, 'exchange': 'binance', 'market': 'BNT/ETH', 'base_currency': 'BNT', 'quote_currency': 'ETH', 'indicator': 'momentum', 'indicator_number': 0, 'analysis': {'config': {'enabled': True, 'alert_enabled': True, 'alert_frequency': 'once', 'signal': ['momentum'], 'hot': 0, 'cold': 0, 'candle_period': '4h', 'period_count': 10}, 'status': 'hot'}, 'status': 'hot', 'last_status': 'hot', 'prices': ' Open: 0.000989 High: 0.000998 Low: 0.000980 Close: 0.000998', 'lrsi': '', 'creation_date': '2020-05-10 16:16:23', 'hot_cold_label': '', 'indicator_label': '', 'price_value': {'open': 0.000989, 'high': 0.000998, 'low': 0.00098, 'close': 0.000998}, 'decimal_format': '%.6f'}, {'values': {'leading_span_a': '0.00', 'leading_span_b': '0.00'}, 'exchange': 'binance', 'market': 'BNT/ETH', 'base_currency': 'BNT', 'quote_currency': 'ETH', 'indicator': 'ichimoku', 'indicator_number': 1, 'analysis': {'config': {'enabled': True, 'alert_enabled': True, 'alert_frequency': 'once', 'signal': ['leading_span_a', 'leading_span_b'], 'hot': True, 'cold': True, 'candle_period': '4h', 'hot_label': 'Bullish Alert', 'cold_label': 'Bearish Alert', 'indicator_label': 'ICHIMOKU 4 hr', 'mute_cold': False}, 'status': 'cold'}, 'status': 'cold', 'last_status': 'cold', 'prices': ' Open: 0.000989 High: 0.000998 Low: 0.000980 Close: 0.000998', 'lrsi': '', 'creation_date': '2020-05-10 16:16:23', 'hot_cold_label': 'Bearish Alert', 'indicator_label': 'ICHIMOKU 4 hr', 'price_value': {'open': 0.000989, 'high': 0.000998, 'low': 0.00098, 'close': 0.000998}, 'decimal_format': '%.6f'}, {'values': {'bbp': '0.96', 'mfi': '98.05'}, 'exchange': 'binance', 'market': 'BNT/ETH', 'base_currency': 'BNT', 'quote_currency': 'ETH', 'indicator': 'bbp', 'indicator_number': 1, 'analysis': {'config': {'enabled': True, 'alert_enabled': True, 'alert_frequency': 'once', 'candle_period': '4h', 'period_count': 20, 'hot': 0.09, 'cold': 0.8, 'std_dev': 2, 'signal': ['bbp', 'mfi'], 'hot_label': 'Lower Band', 'cold_label': 'Upper Band BB', 'indicator_label': 'Bollinger 4 hr', 'mute_cold': False}, 'status': 'cold'}, 'status': 'cold', 'last_status': 'cold', 'prices': ' Open: 0.000989 High: 0.000998 Low: 0.000980 Close: 0.000998', 'lrsi': '', 'creation_date': '2020-05-10 16:16:23', 'hot_cold_label': 'Upper Band BB', 'indicator_label': 'Bollinger 4 hr', 'price_value': {'open': 0.000989, 'high': 0.000998, 'low': 0.00098, 'close': 0.000998}, 'decimal_format': '%.6f'}]
Whereas if you want a JSON string to POST somewhere, call as_string = json.dumps(parsed)

Resources