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
COINMETRO = "https://api.coinmetro.com" | |
coin = 'ETH' | |
price, orderAmount = getAmountETH(amount, 0) | |
pSize = str(orderAmount) # coin position size | |
headers={"Authorization":CMclient.bearerToken, 'Content-Type': 'application/x-www-form-urlencoded'} | |
payload = {'orderType':'market', 'buyingCurrency':coin, 'sellingCurrency':'USD', | |
'sellingQty':pSize} |
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
def get_tick_and_step_size( symbol): | |
tick_size = None | |
step_size = None | |
symbol_info = client.get_symbol_info(symbol) | |
for filt in symbol_info['filters']: | |
if filt['filterType'] == 'PRICE_FILTER': | |
tick_size = float(filt['tickSize']) | |
elif filt['filterType'] == 'LOT_SIZE': | |
step_size = float(filt['stepSize']) | |
return tick_size, step_size |
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
def float_precision(f, n): | |
n = int(math.log10(1 / float(n))) | |
f = math.floor(float(f) * 10 ** n) / 10 ** n | |
f = "{:0.0{}f}".format(float(f), n) | |
return str(int(f)) if int(n) == 0 else f |
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
def order_market_buy(symbol, quantity): | |
tick_size, step_size = get_tick_and_step_size(symbol) | |
order = client.order_market_buy(symbol=symbol, quantity=float_precision(quantity, step_size)) | |
print(symbol, 'order placed...', end="", flush=True) | |
return wait_confirmation(symbol, order) |
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
# deal with possible delay in getting order confirmation | |
# per: https://dev.binance.vision/t/faq-error-message-order-does-not-exist/46 | |
def wait_confirmation(symbol, order, status=ORDER_STATUS_FILLED, try_times=20): | |
for t in range(1,try_times): # try a few times | |
try: | |
currentOrder = client.get_order(symbol=symbol,orderId=order["orderId"]) | |
if currentOrder['status'] == status: | |
return currentOrder | |
except Exception as e: | |
pass |
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
verbose = True | |
if True: | |
if True: | |
p = 20 | |
arm = 6 | |
df = pd.DataFrame(candlesticks, columns=['timestamp', 'open', 'high', 'low', 'close', 'volume']) | |
df['timestamp'] = pd.to_datetime(df['timestamp'], unit='ms') | |
df['open'] = df['open'].astype(float) |
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
verbose = True | |
if True: | |
if True: | |
p = 20 | |
arm = 6 | |
df = pd.DataFrame(candlesticks, columns=['timestamp', 'open', 'high', 'low', 'close', 'volume']) | |
df['timestamp'] = pd.to_datetime(df['timestamp'], unit='ms') | |
df['open'] = df['open'].astype(float) |
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
def tr(data): | |
data['previous_close'] = data['close'].shift(1) | |
data['high-low'] = abs(data['high'] - data['low']) | |
data['high-pc'] = abs(data['high'] - data['previous_close']) | |
data['low-pc'] = abs(data['low'] - data['previous_close']) | |
tr = data[['high-low', 'high-pc', 'low-pc']].max(axis=1) | |
return tr |
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
trades = [] | |
long_trades = [] | |
for key in results: | |
for trade in results[key]: | |
if trade[0] > 4: | |
if long_trades: | |
long_trades.append(float(trade[2])) | |
else: | |
long_trades = [float(trade[2])] | |
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
results = {} | |
sequences = [] | |
sequence = 0 | |
prev_time = None | |
for key in norm: | |
for t in norm[key]: | |
if not prev_time: | |
prev_time = t[0] | |
continue | |
|