英文:
Issue with Binance API access from Heroku platform (ccxt library)
问题
I had a problem using the ccxt library to work with the Binance exchange on the Heroku platform. Calling the exchange.fetch_ticker('BTC/USDT') method throws an ExchangeNotAvailable exception with the message "Service unavailable from a restricted location according to 'b. Eligibility' in https://www.binance.com/en/terms. Please contact customer service if you believe you received this message in error." I understand that this is due to restrictions on access to Binance from certain locations.
I'm asking for help in resolving this issue, as I need to get data from the Binance exchange in order to calculate the amount of Bitcoin.
I would be grateful for any help or recommendations.
Thank you!
Region:
United States
Stack:
heroku-22
I also tried to add a proxy server, it didn't work for me.
英文:
I had a problem using the ccxt library to work with the Binance exchange on the Heroku platform. Calling the exchange.fetch_ticker('BTC/USDT') method throws an ExchangeNotAvailable exception with the message "Service unavailable from a restricted location according to 'b. Eligibility' in https://www.binance.com/en/terms. Please contact customer service if you believe you received this message in error." I understand that this is due to restrictions on access to Binance from certain locations.
I'm asking for help in resolving this issue, as I need to get data from the Binance exchange in order to calculate the amount of Bitcoin.
I would be grateful for any help or recommendations.
Thank you!
Region:
United States
Stack:
heroku-22
I also tried to add a proxy server, it didn't work for me
答案1
得分: 1
Binance Global已限制美国访问,这就是你出现错误的原因。要解决这个问题,你需要访问美国的终端点。
如果你只想访问BTC USDT这种货币,可以将你的请求直接发送到美国的终端点 https://api.binance.us/api/v3/
。
注意:美国市场数据有限,如果你想访问不在美国终端点的更多交易对,你需要将你的Heroku应用服务器切换到欧洲,然后你可以使用Binance Global终端点。
英文:
Binance Global has restricted access to USA, hence why you get that error. To resolve that, you need to access the US endpoint.
If the currency you wish to access is just BTC USDT, direct your request to the US endpoint https://api.binance.us/api/v3/
Note: US market data are limited, so if you want to access more pairs that isn't in the US endpoint, you will need to change your heroku app server to Europe then you can use the Binance Global endpoint.
答案2
得分: -1
I pass the price in dlls to this function, and it returns it to me in bitcoin:
import cxt
def calculate_bitcoin_amount(total_cost):
# 创建一个用于获取市场数据的ccxt客户端
exchange = ccxt.binance()
# 获取BTC/USD的当前汇率
ticker = exchange.fetch_ticker('BTC/USDT')
exchange_rate = ticker['close']
# 根据汇率计算比特币数量
bitcoin_amount = total_cost / exchange_rate
# 将比特币数量四舍五入到8位小数
bitcoin_amount = round(bitcoin_amount, 8)
return bitcoin_amount
The code works fine for me (I'm from Ukraine), but it doesn't work on Heroku servers in the USA.
英文:
I pass the price in dlls to this function, and it returns it to me in bitcoin:
import cxt
def calculate_bitcoin_amount(total_cost):
# Create a ccxt client for fetching market data
exchange = ccxt.binance()
# Get the current exchange rate for BTC/USD
ticker = exchange.fetch_ticker('BTC/USDT')
exchange_rate = ticker['close']
# Calculate the Bitcoin amount based on the exchange rate
bitcoin_amount = total_cost / exchange_rate
# Round the Bitcoin amount to 8 decimal places
bitcoin_amount = round(bitcoin_amount, 8)
return bitcoin_amount
The code works fine for me (I'm from Ukraine), but it doesn't work on Heroku servers in the USA.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论