如何在Python中创建1分钟的蜡烛来交易对?
我试图弄清楚如何使用Python中的Binance软件包创建一个1分钟的烛台,用于交易对BTC-USD。
到目前为止,我可以弄清楚这一点:
from binance.client import Client
candles = client.get_klines(symbol='BTCUSDT', interval=Client.KLINE_INTERVAL_1MINUTE)
for candlestick in candles:
print(candlestick)
但是我不太确定这是否正确。
I'm trying to figure out how to create a 1 minute candlestick for trading pair BTC-USD using the binance package in Python.
So far I can get this down:
from binance.client import Client
candles = client.get_klines(symbol='BTCUSDT', interval=Client.KLINE_INTERVAL_1MINUTE)
for candlestick in candles:
print(candlestick)
But I'm not quite sure if this is correct.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您已经使用
client
(capital-case)或至少是异步等效asyncclient
来创建client
,那么以下内容将打印出最多的打印最近的1分钟烛台。例如,默认
情况下,
蜡烛
将是btcusdt
交易对的最后500 1分钟蜡烛(每个蜡烛本身)的列表,您可以使用get_klines
方法指定最多1000个最后1分钟蜡烛。最新的蜡烛是在列表的末尾蜡烛
,最古老的是一开始。因此,您的代码(假设您已经使用了
client
或ryncclient
createclient
)应该打印所有最后1分钟蜡烛的500个最古老到最近的。可以找到与蜡烛相对应的列表中的每个元素的详细信息在这里。特别是,在上面的输出(显示了最新的1分钟烛台)中,第一个要素是时间戳,第二个要素是开业价格,第三个高价,低价的第四个,第五个,第五次。 ,其他要素不是交易蜡烛的严格组成部分,而是有用的信息(例如量)。
顺便说一句,如果您不想仅限于最新的500 1分钟蜡烛,则可以使用
get_historical_klines
方法,该方法允许您指定开始日期/时间和结束日期/时间(仍然限制为每次通话1000蜡烛)。Assuming that you have used
Client
(capital-case) or at least the asynchronous equivalentAsyncClient
to createclient
, then the following will print the most recent 1-minute candlestick. For example,Output
By default,
candles
will be a list of the last 500 1-minute candles (each candle itself represented by a list) for theBTCUSDT
trading pair and you can specify a maximum of 1000 last 1-minute candles using theget_klines
method. The most recent candles are at the end of the listcandles
and the oldest are at the beginning.So your code (assuming you have used
Client
orAsyncClient
to createclient
) should be printing all 500 of the last 1-minute candles starting from the oldest to the most recent.The details of each element in a list corresponding to a candle can be found here. In particular, in the output above (showing the most recent 1-minute candlestick), the first element is the timestamp, the second element is the opening price, the third the high price, the fourth the low price, the fifth the closing price, and the other elements are not strictly components of a trading candle but are useful information nonetheless (e.g. volume).
By the way, if you do not want to be restricted to only the most recent 500 1-minute candles, you can make use of the
get_historical_klines
method which allows you to specify a start date/time and end date/time (still limited to 1000 candles per call).