r/pythonhelp • • Oct 14 '21

trying to make a coinbase bot

good morning everyone, I am new to python and coding in general and decided that I want to make a coinbase bot for my first project(I know its kinda a tall order), so far I have been able to pull the price from coinbase plus all other data and can see the price in consol and the .txt file but I am currently stuck on trying to export the information to an excel sheet.

my current code allows me to pull selected crypto info to the console, then redirects it to a .txt file, so that I can extract it, but every time that I try and pull the information from the .txt all I get is -

trade_id

price

size

time

bid

ask

volume

but when I look at the .txt file I can clearly see that the current price is also their

if I could call upon you guys to assist me I would be greatly appreciated in this endeavor of mine

my current code

----

import cbpro

import sys

public = ----

passphrase = ---

secret = ----

auth_client = cbpro.AuthenticatedClient(public, secret, passphrase)

stdout_fileno = sys.stdout

sys.stdout = open("test.txt", "w")

public_client = cbpro.PublicClient()

result = public_client.get_product_ticker(product_id="BTC-USD")print(result)

for ip in result:

sys.stdout.write(ip + "\n")

stdout_fileno.write(ip + '\n')

sys.stdout.close()

----

this is a picture of the .txt file and what it looks like after running the code

the top line of the .txt is the information pulled from coinbase:

{'trade_id': 221192520, 'price': '57996.08', 'size': '0.00199445', 'time': '2021-10-14T19:00:19.723534Z', 'bid': '57990.22', 'ask': '57996.56', 'volume': '13242.84761033'}

the next 7 lines are:

trade_id

price

size

time

bid

ask

volume

when using sys.stdout to pull the information from the print(result) command and import it into a text file I can see the results of print(result) but when trying to extract the data I'm unable to have the numbers

I would like to note that my end goal for this part is to export to excel but since i have yet to figure out how to extract the information i have not added any code to transfer it to excel

2 Upvotes

4 comments sorted by

1

u/MT1961 Oct 14 '21

Could you show the output from your print statement? It might help.

1

u/xxxmrbadass Oct 14 '21

i have updated my post to hopefully include a better understanding of what it is I am trying to do, thankyou for your help in this matter

1

u/MT1961 Oct 14 '21

Okay, I think I see your problem. What you are getting back from CB is a dictionary. If you want the individual pieces of it, you can reference them by name:

line['trade_id']

Also, you are writing twice to the file. I think you probably only want one.

1

u/xxxmrbadass Oct 14 '21

thankyou it got me the information that i have been looking for