Created
July 28, 2019 22:16
-
-
Save rodrigo-brito/8c82020f04e946e3f0c39c7243cfe1ee to your computer and use it in GitHub Desktop.
CCXT - Binance example of usage
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