Skip to content

Instantly share code, notes, and snippets.

@rodrigo-brito
Created July 28, 2019 22:16
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rodrigo-brito/8c82020f04e946e3f0c39c7243cfe1ee to your computer and use it in GitHub Desktop.
Save rodrigo-brito/8c82020f04e946e3f0c39c7243cfe1ee to your computer and use it in GitHub Desktop.
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