-
-
Save izikeros/d5cb72b20d7933e4fe95ba7d246fafcc to your computer and use it in GitHub Desktop.
[CCXT example] Binance example of usage #crypto #python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Binance: | |
def __init__(self, key, secret, test=False): | |
self.exchange = ccxt.binance({ | |
'apiKey': key, | |
'secret': secret, | |
'enableRateLimit': True, | |
}) | |
self.test = test | |
def buy(self, symbol, amount): | |
params = {} | |
if self.test: | |
params["test"] = True | |
return self.exchange.create_market_buy_order(symbol=symbol, amount=amount, params=params) | |
def sell(self, symbol, amount): | |
params = {} | |
if self.test: | |
params["test"] = True | |
return self.exchange.create_market_sell_order(symbol=symbol, amount=amount, params=params) | |
def get_balance(self, symbol): | |
balance = self.exchange.fetch_partial_balance(symbol) | |
if balance: | |
return balance.get("free") | |
return 0.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment