Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
CCXT - Binance example of usage
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
You can’t perform that action at this time.