DeviaVir / zenbot

Zenbot is a command-line cryptocurrency trading bot using Node.js and MongoDB.
MIT License
8.22k stars 2.04k forks source link

Bot Markup seems to be broken? #360

Closed ghost closed 7 years ago

ghost commented 7 years ago

Hello, sometimes the bot gets stuck when buying coins using my own script plugin.

order status: rejected, bid: 0.00000103, -0.00000001 below best bid, 0.0% filled order status: rejected, bid: 0.00000103, -0.00000001 below best bid, 0.0% filled order status: rejected, bid: 0.00000103, -0.00000001 below best bid, 0.0% filled order status: rejected, bid: 0.00000103, -0.00000001 below best bid, 0.0% filled order status: rejected, bid: 0.00000103, -0.00000001 below best bid, 0.0% filled order status: rejected, bid: 0.00000103, -0.00000001 below best bid, 0.0% filled ^C [root@www zenbot]# ./zenbot.sh buy --buy_pct=100 --order_type=maker --markup_pct=-1 --order_adjust_time=1000 poloniex.DOGE-BTC

I want to buy at a higher price so that my transactions go smoothly, but all I get is rejected.

Thanks for fixing this loop by the way!!!

ghost commented 7 years ago

It would also be nice if the bot when it sells 100% to actually sell 100% haha

import json
import requests
import re
import unicodedata
import subprocess
import os
import sqlite3
import time
from decimal import *

flag = "undefined"

##Main App Loop
while True:
    ##DB Refresh
    os.remove('/example.db')
    print("File Removed!")
    conn = sqlite3.connect('/example.db')
    c = conn.cursor()
    c.execute('''CREATE TABLE gains (ke4,pct1,dips,dips1)''')
    wjdata = requests.get('https://poloniex.com/public?command=returnTicker&period=60').json()
    ##Load Initial Data
    for key in wjdata:
        if re.match(r'BTC_+', key):
            ke1=key.replace('_', '-')
            ke2=ke1.replace('BTC-', '')
            ke3='-BTC'
            ke9=ke2+ke3
            pct=(wjdata[key]['last'])
            pct0=Decimal(pct)
            pct1=format(pct0, 'f')
            print(ke9)
            print(pct1)
            dips='undefined'
            dips1='undefined'
            c.execute("INSERT INTO gains VALUES (?, ?, ?, ?);", (ke9, pct1, dips, dips1))
            conn.commit()
    print('Waiting some time for comparison...')
    time.sleep(600)
    ##600 seems less volatile
    wjdata = requests.get('https://poloniex.com/public?command=returnTicker&period=60').json()
    ##Load the second Data
    for key in wjdata:
        if re.match(r'BTC_+', key):
            ke1=key.replace('_', '-')
            ke2=ke1.replace('BTC-', '')
            ke3='-BTC'
            ke4=ke2+ke3
            pct2=(wjdata[key]['last'])
            pct3=Decimal(pct2)
            dips=format(pct3, 'f')
            print(ke4)
            print(dips)
            c.execute('UPDATE gains SET dips = ? WHERE ke4 = ?;', (dips, ke4))
            conn.commit()
    for row in c.execute('SELECT ke4, (dips-pct1) as diff FROM gains ORDER BY diff DESC LIMIT 1;'):
            print(row)
            row=str(tuple(row))
            ro1=row.replace("u", '')
            ro2=ro1.replace("'", '')
            ro3=ro2.replace('(', '')
            ro4=ro3.replace(')', '')
            ro5=ro4.replace(",", '')
            s = ro5
            s=re.sub('\d', '', s)
            ros=s.replace(".", '')
    if flag == ros:
            print(ros)
            print(flag)
            print ('Current Profitable Coin Is The Same!')
    else:
            print(ros)
            print(flag)
            sell=subprocess.call('./zenbot.sh sell --sell_pct=100 poloniex.'+flag,shell=True)
    ##Doublecheck the data
            for key in wjdata:
                if re.match(r'BTC_+', key):
                    ke1=key.replace('_', '-')
                    ke2=ke1.replace('BTC-', '')
                    ke3='-BTC'
                    ke4=ke2+ke3
                    pct2=(wjdata[key]['last'])
                    pct3=Decimal(pct2)
                    dips1=format(pct3, 'f')
                    print(ke4)
                    print(dips1)
                    c.execute('UPDATE gains SET dips1 = ? WHERE ke4 = ?;', (dips1, ke4))
                    conn.commit()
            for row in c.execute('SELECT ke4, (dips1-pct1) as diff FROM gains ORDER BY diff DESC LIMIT 1;'):
                    print(row)
                    row=str(tuple(row))
                    ro1=row.replace("u", '')
                    ro2=ro1.replace("'", '')
                    ro3=ro2.replace('(', '')
                    ro4=ro3.replace(')', '')
                    ro5=ro4.replace(",", '')
                    s = ro5
                    s=re.sub('\d', '', s)
                    ros=s.replace(".", '')
                    buy=subprocess.call('./zenbot.sh buy --buy_pct=100 poloniex.'+ros,shell=True)
    flag=ros
ghost commented 7 years ago

./zenbot.sh buy --order_type=taker --order_adjust_time=3000 poloniex. ./zenbot.sh sell --order_type=taker --order_adjust_time=3000 poloniex.

and

// avoid trading at a slippage above this pct
c.max_slippage_pct = 5
// buy with this % of currency balance
c.buy_pct = 100
// sell with this % of asset balance
c.sell_pct = 100
// ms to adjust non-filled order after
c.order_adjust_time = 3000
// avoid selling at a loss below this pct
c.max_sell_loss_pct = 25
// ms to poll order status
c.order_poll_time = 3000
// ms to wait for settlement (after an order cancel)
c.wait_for_settlement = 5000
// % to mark up or down price for orders
c.markup_pct = 0
// become a market taker (high fees) or a market maker (low fees)
c.order_type = 'taker'

// Misc options:

// default # days for backfill and sim commands
c.days = 14
// ms to poll new trades at
c.poll_trades = 5000
// amount of currency to start simulations with
c.currency_capital = 1000
// amount of asset to start simulations with
c.asset_capital = 0
// for sim, reverse time at the end of the graph, normalizing buy/hold to 0
c.symmetrical = false
// number of periods to calculate RSI at
c.rsi_periods = 14
// period to record balances for stats
c.balance_snapshot_period = '15m'
// avg. amount of slippage to apply to sim trades
c.avg_slippage_pct = 0.045

Might work better, testing now.

ghost commented 7 years ago

No dice, I updated zenbot to the latest and it's just now says placing order when run from my script.

But is fine from the command line.