Skip to content

Instantly share code, notes, and snippets.

@izikeros
Forked from rodrigo-brito/binance_ccxt.py
Last active March 14, 2024 10:01
Show Gist options
  • Save izikeros/d5cb72b20d7933e4fe95ba7d246fafcc to your computer and use it in GitHub Desktop.
Save izikeros/d5cb72b20d7933e4fe95ba7d246fafcc to your computer and use it in GitHub Desktop.
[CCXT example] Binance example of usage #crypto #python
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