python-binance: Get all orders, without specifying symbol - python

Trying to fetch my Binance accounts order history with the python-binance module. There is an option to get all orders within one symbol (see documentation):
orders = client.get_all_orders(symbol='BNBBTC', limit=10)
Bu the problem is I can't pass more than 1coin in the symbol parameter
How can I pass a list for the symbol parameter, I want to fetch more than 1 coins order history in a single function
as I'm trying to build a portfolio for my Binance account. Or is there another method to do so?

Currently it is not possible to get all historical orders or trades without specifying the symbol in one call, even without the module python-binance.
There is an ongoing discussion on the Binance forum, requesting this feature.
As a workaround:
If you know your ordered symbols: Use the function get_all_orders() multiple times for each symbol in a loop.
If you don't know your ordered symbols: you could send a GET request for each symbol available at Binance (as mentioned in the discussion linked above). But be careful with the rateLimits.

I was asking myself the same thing. Well, a work around would be to iterate over all the tickers available in Binance looking for the ones we did traded in the past.
If you are working the free plan of the API, the best would be to setup a storage file or database and store all the result. Then you have to care about keeping with the changes from there.
Yeah, it is exactly how I am going to deal with this.
(edit) :
Sleep function will be needed to avoid more than 1200 queries per minute.
(example) :
def getAllTickers(self):
# Get all available exchange tickers
exchangeInfo = self.client.get_exchange_info()
# Extract the tickers general info
exchangeSymbols = []
for i in exchangeInfo['symbols']:
exchangeSymbols.append(i)
return exchangeSymbols
def getMyTrades(self, strSymbol):
return self.client.get_my_trades(symbol=strSymbol)
def getMyTradedTickers(self):
tickers = self.getAllTickers()
# Extract every ticker where trade happened
traded = []
for i in tickers:
tickerTransactions = self.getMyTrades(i["symbol"])
if tickerTransactions :
traded.append(tickerTransactions)
print(i["symbol"], " transactions available")
else :
print(i["symbol"], " has no transactions")
self.time.sleep(0.1)
return traded
**Srry for the code quality. Python is not my main coding language and im getting use to it.

Related

query all elements containing selected string symbolkeys from API

I am querying price data from an API, using the request.get function in python.
the query looks like:
requests.get(url_specified_contract, headers=headers, params={'SymbolKeys':'NDX GNM FMZ0022!'}).json()
where 'SymbolKeys' identifies the contract I look for.
Several contracts are traded for specific delivery periods, with a similar SymbolKey that varies only in the latter part. For instance:
'NDX GNM FMZ0022!'
'NDX GNM FMZ0023!'
'NDX GNM FMZ0024!'
....
Since the changing component could vary depending on the commodity I look at, I would like an easy way to get all ids containing a specified string (in my example 'NDX GNM'), without knowing which ones exist in advance.
I was trying queries like:
requests.get(url_quotes, headers=headers, params={'SymbolKeys':'*NDX GNM*'}).json()
Without success ({'Error': 'Unknown symbol(s): NDX GNM. This/these symbol(s) will not be part of the result.'}
).
The only solution for the time being is a for loop over each possible integer like:
quotes = []
for i in range(1,300):
try:
temp = requests.get(url_quotes, headers=headers, params={'SymbolKeys':'NDX GNM M'+str(i)}).json()
except: pass
quotes.append(temp)
But this approach consumes a large amount of daily queries.
Could you suggest me a possible solution?
thanks in advance, cheers.

WETH Transaction does not appear in the web3.eth.get_transaction

I am trying to understand how can I see the amount of WETH transferred in a transaction. for example on OpenSea. When you go to etherscan you can see the amount. but if you use web3.eth.get_transcation(tx_hash) you will find the value to be 0 ( since its WETH and not ETH).
Any suggestions?
I'm also having trouble with this.
The Phunkbot code is on github (https://github.com/albanow/phunks-nll-twitter-bot/blob/main/bot.py), and this part from the 'input' is interesting:
bid = "0x6d728796"
sale = "0xf8529df3"
accepted_bid = "0xbad9f860"
Somehow the first 10 characters of the 'input' hex is a sign of what kind of transaction it is? Doesn't seem to be the case for the contract I'm trying to monitor but maybe this code will lead you somewhere.

Problem with getting tweet_fields from Twitter API 2.0 using Tweepy

I have a similar problem as in this question (Problem with getting user.fields from Twitter API 2.0)
but I am using Tweepy. When making the request with tweet_fields, the response is only giving me the default values. In another fuction where I use user_fields it works perfectly.
I followed this guide, specifically number 17 (https://dev.to/twitterdev/a-comprehensive-guide-for-using-the-twitter-api-v2-using-tweepy-in-python-15d9)
My function looks like this:
def get_user_tweets():
client = get_client()
tweets = client.get_users_tweets(id=get_user_id(), max_results=5)
ids = []
for tweet in tweets.data:
ids.append(str(tweet.id))
tweets_info = client.get_tweets(ids=ids, tweet_fields=["public_metrics"])
print(tweets_info)
This is my response (with the last tweets from elonmusk) also there is no error code or anything else
Response(data=[<Tweet id=1471419792770973699 text=#WholeMarsBlog I came to the US with no money & graduated with over $100k in debt, despite scholarships & working 2 jobs while at school>, <Tweet id=1471399837753135108 text=#TeslaOwnersEBay #PPathole #ScottAdamsSays #johniadarola #SenWarren It’s complicated, but hopefully out next quarter, along with Witcher. Lot of internal debate as to whether we should be putting effort towards generalized gaming emulation vs making individual games work well.>, <Tweet id=1471393851843792896 text=#PPathole #ScottAdamsSays #johniadarola #SenWarren Yeah!>, <Tweet id=1471338213549744130 text=link>, <Tweet id=1471325148435394566 text=#24_7TeslaNews #Tesla ❤️>], includes={}, errors=[], meta={})
I found this link: https://giters.com/tweepy/tweepy/issues/1670. According to it,
Response is a namedtuple. Here, within its data field, is a single Tweet object.
The string representation of a Tweet object will only ever include its ID and text. This was an intentional design choice, to reduce the excess of information that could be displayed when printing all the data as the string representation, as with models.Status. The ID and text are the only default / guaranteed fields, so the string representation remains consistent and unique, while still being concise. This design is used throughout the API v2 models.
To access the data of the Tweet object, you can use attributes or keys (like a dictionary) to access each field.
If you want all the data as a dictionary, you can use the data attribute/key.
In that case, to access public metrics, you could maybe try doing this instead:
tweets_info = client.get_tweets(ids=ids, tweet_fields=["public_metrics"])
for tweet in tweets_info.data:
print(tweet["id"])
print(tweet["public_metrics"])

pyxero get LineItems on banktransactions

I'm running pyxero and trying to get the reference and description from a bank transaction but am having trouble getting it.
I can run:
trans = xero.banktransactions.filter(BankAccount_Name="chosen_account")
Which gives me the transcations and details, however the reference and description are not present.
It also shows the LineItems are empty:
'LineItems': []
I also get the same if I try:
transaction = xero.banktransactions.filter(BankTransactionID=BankTransactionID)
Is there a way to get this information?
Many thanks
Need to use get instead of filter to get the LineItems:
transaction = xero.banktransactions.get(BankTransactionID)
To get all the lineitem detail you either need to :
retrieve a specific item by BankTransactionID (as #blountdj implies in their answer)
OR
use Xero API's built-in paging in the request by passing 'page=xxx' as an optional parameter (which you might need to loop through multiple pages/requests if >100 transactions - which is likely).
Refer Xero API reference re Bank Transaction paging here

Fetching data Yahoo Finance

I am currently creating a program where I want to fetch stock data from yahoo finance using the yahoo_finance module. However, I want to fetch data for 4 stocks using what i assume would be a loop. Here's the basic structure I thought of using:
from yahoo_finance import Share
ticker_symbols = ["YHOO", "GOOG", "AAPL"]
i = 0
while i < 4:
company = Share(str(i))
print (company.get_open())
i += 1
The main problem I need assistance with is how I would construct a loop that iterates over all the ticker_symbols. As you can tell from my "try" above I am completely clueless, since I am new to python. A secondary problem I have is how I would fetch data from 30 days ago up to current date using the module. Maybe I should have resorted to web scraping but it seems so much more difficult.
to loop over a list you can just do :
for symbol in ticker_symbols :
company = Share(symbol)
That's basic python ! I will advise you to follow a small tutorial to learn the python basics.
You can get historical daily data using Share(symbol).get_historical('aDate'). Here you can find all the available methods for the package : https://pypi.python.org/pypi/yahoo-finance
good luck with that
You need to iterate over the ticker_symbols list and simply ditch the while loop:
from yahoo_finance import Share
ticker_symbols = ["YHOO", "GOOG", "AAPL"]
for i in ticker_symbols:
company = Share(i)
print (company.get_open())

Categories