Api does not return JSON correctly

Asked

Viewed 67 times

0

I am trying to request a list that should contain the indices 'asks' and 'bids' but I can only 'bids', I don’t know if there is a limit to the size of the request in python, I can’t handle this response with JSON, follow the code:

import requests as req
from binance.client import Client

class Binance():


def __init__(self, coin, base, publicApiKey, privateApiKey):
    self.coin = coin.upper()
    self.base = base.upper()
    self.pair = coin + base
    self.publicKey = publicApiKey
    self.privateKey = privateApiKey
    self.client = Client(self.publicKey, self.privateKey)
def getPair(self): return self.pair

def getName(self): return 'Binance'
def getTest(self): return self. client.get_order_book(symbol=self.coin+self.base)
def getPairBid(self):
    bid = self.client.get_order_book(symbol=self.coin + self.base)['bids']
    return bid
def getPairAsk(self):
    ask = self.client.get_order_book(symbol=self.coin + self.base)['ask']
    return ask

def sellBuy(self):
    bid = req.get('http://api.coinbene.com/v1/market/ticker?symbol=' + self.coin + self.base).json()['ticker'][0]['bid']
    ask = req.get('http://api.coinbene.com/v1/market/ticker?symbol=' + self.coin + self.base).json()['ticker'][0]['ask']
    return '::: Binance :::\n' + 'Buy: ' + str(bid) + '\n' + 'Sell: ' + str(ask) + '\n' + '/---------------------/'



print(Binance('eth', 'btc','NjD7K42nXFoRG2ptb1ify7YMlWjEH6E7JnhMDLhuxLsOzZp0SFQZy9bqLMAwI7va'
    ,'ZrNB0jJzjEhYVrBYS3FjjUeCucAJT2TBt0mVfLJJ5Q7PI8a48fxcVXTDO5sBpxDH').getTest())

API link: https://github.com/sammchardy/python-binance

  • already tested in Postman?

  • Problem is you’re putting ask and not asks, nay?

  • What’s the problem with JSON? Here I was able to process normally.

  • @That’s right, I didn’t pay attention, thank you !

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.