Binance_Futures_python | Binance Futures Python SDK , a lightweight python | Cryptocurrency library
kandi X-RAY | Binance_Futures_python Summary
kandi X-RAY | Binance_Futures_python Summary
This is Binance Futures Python SDK, a lightweight python library. You can import to your python project and use this SDK to query all market data, trading and manage your account. The SDK supports both synchronous RESTful API invoking and subscribing the market data and the user's private data from the websocket connection.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Deserialize a new AccountInformation object
- Parse a Position object
- Deserialize a JSON object into a Asset object
- Parse a new accountInformationV2
- Creates a AssetV2 object from the json data
- Parse a PositionV2
- Calls the callback function
- Unsubscribe all connections
- Post an order
- Creates a RestApiRequest object
- Subscribe to all mark price events
- Gets mark price data
- Request Candlestick data
- Gets BLTCandlestick data
- Gets the price change statistics for a symbol
- Returns a list of Candlestick data for a pair
- Returns a list of bids for a given pair
- Cancel list orders
- Get all orders
- Returns a list of aggregate trades
- Get a list of account trades
- Called when a message is received
- Call sync API
- Gets continuous kline data
- Construct a new AccountUpdate object from a JSON response
- Print data
Binance_Futures_python Key Features
Binance_Futures_python Examples and Code Snippets
Community Discussions
Trending Discussions on Binance_Futures_python
QUESTION
I've been running into this same problem for the last few days, googling everything and searching for answers on this forum, but nothing I'm trying is seeming to work. I've been following tutorials other people have posted and they're able to do this very simply, but I run into multiple problems when I try it from multiple angles. I've got my head so tangled up from all the things I've tried that I'm not even sure what's happening or what I've done anymore. This isn't all of the code, but this should be the only relevant code because the other parts do other functions, but I apologize if I missed anything.
Basically, I'm grabbing historical financial candlestick data from a website, trying to put it into a Pandas dataframe, and then use that dataframe to make charts with Plotly. I get the data as 'result', PyCharm outputs the data just fine into the 'Run' box, but now I need to save that data, so I have Pandas turn 'result' into a dataframe as 'priceData', and convert that to 'pricedata.csv'. When I open that CSV file, all I get is a list from 0 to 1439 (I'm importing 1440 1 minute candlesticks at a time), and each candlestick only shows the object reference (, or similar). That's obviously not what I'm after, I need the data within the candlesticks, which should be made up of 12 pieces of data (open time, open, low, close, high, etc...). When the chart function runs, it comes back with "AttributeError: 'DataFrame' object has no attribute 'high'", which I assume is because it's accessing that candlestick object ID and not the values.
I can get the specific values by going in-depth, and calling for it to save result[0].high, or result[0].low, etc. But then I have to iterate through 1440 candlesticks of data and write/save them all separately, and then bring together the high/low/open/close/time/etc of each of them to be able to plot, which is far more complicated than what the tutorials I've watched do. They're able to literally just use the dataframe right away to plot with no troubles, they don't run into the attribute error, it's like it just identifies the columns correctly for them. But when I look at the columns of 'result', there's 1440 columns (again one for each candlestick), but I would think it should be 12 columns for the 12 different bits of data each candlestick is made up of. I've tried transposing the columns and rows, but that doesn't work either.
Even if I try to get the whole candlestick data for just one object, by specifying "result[0]" without specifying the .high/.low/etc, I run into the same attribute error. Some things recommended to specify what the columns are, so that's what the hashed out "priceData.columns" is for, where I identify what each column is. But then I get "Length mismatch: Expected axis has 1440 elements, new values have 12 elements".
I'm really confusing myself and going in circles at this point, can anyone help point me in the right direction and tell me what I'm screwing up on? Thank you in advance to anyone who takes the time to even read this, or has any direction they can offer.
...ANSWER
Answered 2021-May-27 at 06:21The way you are currently getting the candlestick data, result
is a list of Candlestick objects, and each object has attributes that can be individually accessed, such as result[0].high
as you pointed out. It sounds like you want to unpack all of these attributes and put them into a DataFrame.
To obtain all of the attributes of an object, such as all 12 attributes of the Candlestick object in a dictionary, you can use result[0].__dict__
which returns: {'openTime': 1609473600000, 'open': '29302.11', 'high': '29356.04', 'low': '29302.10', 'close': '29344.00', 'volume': '170.018', 'closeTime': 1609473659999, 'quoteAssetVolume': '4988200.62513', 'numTrades': 1045, 'takerBuyBaseAssetVolume': '139.291', 'takerBuyQuoteAssetVolume': '4086412.01157', 'ignore': '0'}
To get a list of these dictionaries from result
, you can use a list comprehension: [candlestick_obj.__dict__ for candlestick_obj in result]
, and pd.DataFrame
allows you to construct a DataFrame from such a list of dictionaries so priceData = pd.DataFrame([candlestick_obj.__dict__ for candlestick_obj in result])
will create a DataFrame with columns for the keys in each of the dictionaries with 1 row for each list item.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install Binance_Futures_python
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page