WISEPLAT / backtrader_binance

Binance API integration with Backtrader. Run strategies for Backtest and Live Trading. Get historical price data for Bitcoin, Ethereum and all coins from Binance. EASY create your strategies.
MIT License
127 stars 46 forks source link

Connecting to 'us' instead of 'com' #5

Closed 6lackHeart closed 1 year ago

6lackHeart commented 1 year ago

Is there a way to pass the tld='us' parameter? Or do you have any suggestions for connecting to the .us exchange instead of the .com url?

WISEPLAT commented 1 year ago

Hello! Can you provide more information about your issue?

6lackHeart commented 1 year ago

Of course. Binance does not allow US customers to use their Binance.com url. Instead US customers have to use the 'Binance.us' url. In like the Binance.client 'Client' module you can pass the 'tld' parameter to point the 'Client' to the correct url. Like this: clinet = Client(tld='us'). Usually passed in the same function as the API keys. I was thinking maybe it could be passed in the 'BinanceStore' but it doesn't have a 'tld' attribute.

WISEPLAT commented 1 year ago

Of course. Binance does not allow US customers to use their Binance.com url. Instead US customers have to use the 'Binance.us' url. In like the Binance.client 'Client' module you can pass the 'tld' parameter to point the 'Client' to the correct url. Like this: clinet = Client(tld='us'). Usually passed in the same function as the API keys. I was thinking maybe it could be passed in the 'BinanceStore' but it doesn't have a 'tld' attribute.

Fixed )) Please test, and provide some example (I will publish it in Examples folder), as I'm not from US, and can't test it.

store = BinanceStore(
    api_key=Config.BINANCE_API_KEY,
    api_secret=Config.BINANCE_API_SECRET,
    coin_target=coin_target,
    testnet=False,
    tld="us",  # for US customers => to use the 'Binance.us' url
)

Thanks.

6lackHeart commented 1 year ago

Oleg,

Thank you very much my friend. This works perfectly.

I am very thankful of the module that you've created. I would like to offer my services to help test anything you may need tested as far as the backtrader_binance module goes.

Cheers,

Brence

6lackHeart commented 1 year ago

Hey Oleg,

I apologize. I thought the fix was working, but it seems to not be working now that I've got my bot ready to go. I have the 'tld='us',' parameter in the 'BinanceStore' like this:

store = BinanceStore( api_key=data_api_key, api_secret=data_api_secret, coin_target=coin_target, tld='us', testnet=False) # Binance Storage

this is the error code that I get from the binance api:

in _handle_response raise BinanceAPIException(response, response.status, await response.text()) binance.exceptions.BinanceAPIException: APIError(code=0): 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 apologize again, for not testing the fix correctly last time around.

WISEPLAT commented 1 year ago

Service unavailable from a restricted location according to 'b. Eligibility' in https://www.binance.com/en/terms

Hi! In your message I saw this: "Service unavailable from a restricted location according to 'b. Eligibility' in https://www.binance.com/en/terms" - so may be you are trying to get access from location - which is restricted to US? May be you should try to use VPN? From which location you have tried to get access to US binance?

WISEPLAT commented 1 year ago

Closed as I didn't get the answer.