def public_api(): client = BinanceAPI() print(client.ping()) print(client.time()) print(client.depth('BTCUSDT', limit=10)) print(client.aggTrades('ETHBTC')) print(client.klines('BNBBTC', '1h', limit=10)) print(client.stats24hr('ETHUSDT')) print(client.allPrices()) print(client.allBookTickers())
def private_api(): client = BinanceAPI(API_KEY, API_SECRET) # or # client = BinanceAPI() # client.set_api(API_KEY, API_SECRET) print(client.openOrders('KNCETH')) print(client.allOrders('KNCETH')) print(client.account()) print(client.myTrades('KNCETH')) print(client.newLimitBuyOrder('BTCUSDT', quantity=1.0, price=5203.0)) print(client.queryOrder('BNBETH', orderId=387643)) print(client.deleteOrder('BNBETH', orderId=387643))
def main(): """ Entrypoint """ env = Environment('.env') api = BinanceAPI(env) wapi = BinanceWSAPI(env) if env.override: print('Want to skip prompts? Set PROMPT_OVERRIDE to 0!') loop = asyncio.get_event_loop() # initialize Market Manager (prepare everything) manager = MarketManager(api, wapi, *loop.run_until_complete(setup(api))) # Start coin name listeners: stdin and HTTP http_thr = Thread(target=coin_from_http, args=(manager, ), daemon=True) stdin_thr = Thread(target=coin_from_stdin, args=(manager, ), daemon=True) print( f'Starting HTTP listener at {env["SERVER_HOST"]}:{env["SERVER_PORT"]}') http_thr.start() stdin_thr.start() if env.bailout: print( 'Bailout enabled: once trading starts, press Ctrl+C to sell immediately' ) # wait for coin lock try: with manager.cvar: manager.cvar.wait_for(lambda: manager.ready) except KeyboardInterrupt: return # start trading try: loop.run_until_complete(manager.start()) except KeyboardInterrupt: try: loop.run_until_complete(manager.bailout()) except CException as exc: print(str(exc))
async def main(): """ Entrypoint """ klen = 241 # 4h remanence thresh = 5, 900 # 5% positive price fluctuation, 900% positive volume fluctuation min_vol = 0.1 # do not alert under 0.1 executed quote volume (tuned for BTC) min_chg = 0.1 # minimum acceptable price change, regardless of volume limits = KlineLimits(*thresh, min_vol, min_chg) env = Environment('.env') api = BinanceAPI(env) wapi = BinanceWSAPI(env) # fetch symbols to track qsymbols = await quote_symbols(api) qvalues = qsymbols.values() symb_names = [symb['symbol'] for symb in qvalues] qlen = len(qvalues) CColors.iprint( f'DawnSpotter online.\nTracking {qlen} pairs: {", ".join(symb_names)}') # prepare the kline data structure manager = KlineManager(qvalues, klen, limits) # Pull historical data from the API maxrun = 1200 // (qlen + 41) print( f'Pulling historical data from REST API, do not rerun this more than {maxrun}x/min!' ) async with aiohttp.ClientSession() as client: coros = (api.last_klines(client, '1m', klen, symbol) for symbol in qvalues) preconf = await asyncio.gather(*coros) manager.fill(zip(symb_names, preconf)) # read trade data from WS print('Updating data from WebSockets...') async for tdata in wapi.klines_bulk(symb_names, '1m'): manager.update(tdata['data']['k'])
import json import asyncio from api import BinanceAPI with open("logs.json") as file: data = json.load(file) api_key = data["KEY"] api_secret = data["SECRET"] client = BinanceAPI(api_key, api_secret) def extract_balance(json_data): for key in json_data.keys(): try: return float(json_data[key]) except KeyError: return 0 def get_balance(): res = client.get_account_status() final_balance = [] for coin in res["balances"]: if float(coin["free"]) > 0.0001: final_balance.append({"%s" % coin["asset"]: coin["free"]}) with open("results.json", "w") as outfile:
from api import BinanceAPI client = BinanceAPI( '8SqwIw1lYhaxQZa9LSCUx2wjN1GqguDDAuewtKUCKmUlO4uwXoQ3ylz0Efs', '5Phlc0ldADa6rQYJANguTIe1mSekiSTN2SiaowBPcs2gXi3wsgQ2TCQssmo4B') ping = client.time() print(ping)
def setUp(self): self.client = BinanceAPI(API_KEY,API_SECRET)
###### Inspired by the Turtle Traders from the 1980s ###### More information at http://www.tradingblox.com/originalturtles/ ###### Testing suggests this strategy does NOT work well with crypto ###### This is in the middle of a refactor from api import BinanceAPI client = BinanceAPI('[API key]','[API secret]') # import time # from data_checks import Data_checks # import pandas # from datetime import datetime # import matplotlib.pyplot as plt import datetime from excepts import MalformedRequest, StatusUnknown, InternalError from requests.exceptions import ConnectionError from http.client import RemoteDisconnected from http.client import HTTPException from urllib3.exceptions import ProtocolError class turtle: def __init__(self): self.pair = "" self.pip_sats = None self.price_mult = 1 self.interval = None self.capital = None self.limit = None self.exit_trigger = None