0

I am a newbie to python and trying to get a specific value from JSON response I receive over ccxt Binance API.the response received from server

I need to extract the average value and store it in a variable for further calculations

I am planning to use actualdata = (data['info']['average'])I have not yet tried the code as it requires actual order to be placed. I want to make sure that this is the correct way to parse the required data.

Also, I want to store the whole JSON response in the text file so will the below code work ("order" returns the below JSON response that I have attached) i.e passing "order" directly through json.dump

order = exchange.create_market_buy_order('ETH/USD', 0.05)
with open('orderdata/ETHUSDTorder.txt', 'w') as json_file:
    json.dump(order, json_file) 

JSON SCRIPT below

{
    'info': {
        'symbol': 'ETHUSD',
        'orderid': '20556566',
        'orderlistid': '-1',
        'clientorderid': 'TXgguEidjfF9eLKF',
        'transactiontime': '1619882734',
        'price': '0.00',
        'origqty': '0.00500',
        'executedQty': '0.005000',
        'commutativeQuoteQty': '143.06',
        'status': 'Filled',
        'timeInforce': 'GTC',
        'type': 'MARKET',
        'side': 'buy',
        'fills': [{
            'price': '2861.34',
            'qty': '0.030',
            'comission': '0.0001',
            'comissionAsset': 'BNB',
            'tradeid': '5722834'
        }, {
            'price': '2761.23',
            'qty': '0.019',
            'comission': '0.0001',
            'comissionAsset': 'BNB',
            'tradeid': '5722834'
        }]
    },
    'id': '2044343',
    'clientorderid': 'TXgguEidjfF9eLKF',
    'timestamp': '1619882734',
    'datetime': '2021-06-10T20:21:234',
    'lasttradetimestamp': None,
    'symbol': 'ETHUSD',
    'type': 'MARKET',
    'timeInforce': 'GTC',
    'postonly': 'false',
    'side': 'buy',
    'price': '2861.23',
    'stopprice': 'None',
    'amount': 0.05,
    'cost': 143.06,
    'average': 2861.23,
    'filled': 0.05,
    'remaining': 0.0,
    'status': 'closed',
    'fee': {
        'cost': 0.00013,
        'currency': 'BNB'
    },
    'trades': [{
        'info': {
            'price': '2861.17',
            'qty': '0.0330',
            'comission': '0.0001',
            'commissionAsset': 'BNB',
            'tradeid': '2383487'
        },
        'timestamp': None,
        'datetime': None,
        'symbol': 'ETHUSD',
        'id': None,
        'order': None,
        'type': None,
        'side': None,
        'takerOrMaker': None,
        'price': 2861.23,
        'amount': 0.034,
        'cost': 87.534,
        'fee': {
            'cost': 0.0034,
            'currency': 'BNB'
        }
    }, {
        'info': {
            'price': '2861.23',
            'qty': '0.0019',
            'comission': '0.0023',
            'comissionAsset': 'BNB',
            'tradeid': '453233'
        },
        'timestamp': None,
        'datetime': None,
        'symbol': 'ETHUSD',
        'id': None,
        'order': None,
        'type': None,
        'side': None,
        'takerOrMaker': None,
        'price': 2861.39,
        'amount': 0.01941,
        'cost': 55.53,
        'fee': {
            'cost': 6.737,
            'currency': 'BNB'
        }
    }]
}
Pavan Alur
  • 45
  • 6

0 Answers0