i have created django models to save the api keys
this is the models code
class Coinbaseapi(models.Model):
symbol = models.CharField(max_length=10, null=True, blank=True)
API = models.CharField(max_length=100, null=True, blank=True)
SECRET = models.CharField(max_length=250, null=True, blank=True)
and using this serializer
class Coinbaseserializer(serializers.ModelSerializer):
class Meta:
model = Coinbaseapi
fields = "__all__"
I tried getting the market data in a function with this code
coinbase = Coinbaseapi.objects.all().first()
cbSerializer = Coinbaseserializer(coinbase)
CoinbaseData = cbSerializer.data
current_price = coinbase.fetch_ticker(CoinbaseData['symbol'])['last']
it gives this error
print(coinbase.fetch_ticker(CoinbaseData['symbol'])['last'])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
n = string[0] if isinstance(string[0], int) else ord(string[0])
~~~~~~^^^
IndexError: index out of range
while i used it buy using local variable and tested in another 1 simple python file and it was working fine.
coinbase = ccxt.coinbase({
'apiKey': API,
'secret': SECRET,
"enableRateLimit": True,
'options': {
'defaultType': 'future',
}
})
cp = coinbase.fetch_ticker('MATIC/USDT')['last']
print(cp)
I checked on the internet to save it in this format given below
-----BEGIN EC PRIVATE KEY-----
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-----END EC PRIVATE KEY-----
instead of using this default format below but didn’t worked either
-----BEGIN EC PRIVATE KEY-----nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxnxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxnxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxn-----END EC PRIVATE KEY-----n