mirror of
https://git.wownero.com/lza_menace/totrader.git
synced 2024-08-15 00:33:13 +00:00
get pages and auto updating working
This commit is contained in:
parent
60a2998d80
commit
f7740ba778
6 changed files with 86 additions and 33 deletions
|
@ -1,6 +1,9 @@
|
|||
import quart.flask_patch
|
||||
from quart import Quart
|
||||
|
||||
from totrader.routes import meta, tasks, api
|
||||
from totrader import filters
|
||||
|
||||
|
||||
def create_app():
|
||||
app = Quart(__name__)
|
||||
|
@ -8,8 +11,6 @@ def create_app():
|
|||
|
||||
@app.before_serving
|
||||
async def startup():
|
||||
from totrader.routes import meta, tasks, api
|
||||
from totrader import filters
|
||||
app.register_blueprint(meta.bp)
|
||||
app.register_blueprint(tasks.bp)
|
||||
app.register_blueprint(api.bp)
|
||||
|
|
|
@ -23,16 +23,59 @@ async def get_ticker_data():
|
|||
|
||||
@bp.route('/get_balances')
|
||||
async def get_balances():
|
||||
base = Balance.select().where(
|
||||
Balance.currency == trader.base_currency
|
||||
).order_by(Balance.date.desc()).limit(1).first()
|
||||
trade = Balance.select().where(
|
||||
Balance.currency == trader.trade_currency
|
||||
).order_by(Balance.date.desc()).limit(1).first()
|
||||
if not base or not trade:
|
||||
return jsonify({})
|
||||
return jsonify({
|
||||
base.currency: {
|
||||
'total': base.total,
|
||||
'available': base.available
|
||||
},
|
||||
trade.currency: {
|
||||
'total': trade.total,
|
||||
'available': trade.available
|
||||
}
|
||||
})
|
||||
|
||||
@bp.route('/get_bitcoin_price')
|
||||
async def get_bitcoin_price():
|
||||
return jsonify({})
|
||||
btc = BitcoinPrice.select().order_by(BitcoinPrice.date.desc()).limit(1).first()
|
||||
return jsonify({
|
||||
'price': btc.price
|
||||
})
|
||||
|
||||
@bp.route('/get_orders')
|
||||
async def get_orders():
|
||||
return jsonify({})
|
||||
data = {}
|
||||
for order in Order.filter(Order.active == True).order_by(Order.date.desc()):
|
||||
data[order.uuid] = {
|
||||
'trade_pair': order.trade_pair,
|
||||
'trade_type': order.trade_type,
|
||||
'buy': order.buy,
|
||||
'quantity': order.quantity,
|
||||
'price': order.price,
|
||||
'uuid': order.uuid,
|
||||
'active': order.active,
|
||||
'cancelled': order.cancelled,
|
||||
'date': order.date,
|
||||
}
|
||||
return jsonify(data)
|
||||
|
||||
@bp.route('/get_trade_history')
|
||||
async def get_trade_history():
|
||||
return jsonify({})
|
||||
data = {}
|
||||
for trade in Trade.select().order_by(Trade.date.desc()):
|
||||
data[trade.id] = {
|
||||
'trade_pair': trade.trade_pair,
|
||||
'trade_type': trade.trade_type,
|
||||
'buy': trade.buy,
|
||||
'quantity': trade.quantity,
|
||||
'price': trade.price,
|
||||
'date': trade.date
|
||||
}
|
||||
return jsonify(data)
|
||||
|
|
|
@ -20,15 +20,15 @@ async def store_balances():
|
|||
@bp.route('/store_orders')
|
||||
async def store_orders():
|
||||
current_app.add_background_task(trader.reconcile_orders)
|
||||
current_app.add_background_task(trader.update_orders)
|
||||
current_app.add_background_task(trader.store_orders)
|
||||
return 'ok'
|
||||
|
||||
@bp.route('/store_trade_history')
|
||||
async def store_trade_history():
|
||||
current_app.add_background_task(trader.update_trade_history)
|
||||
current_app.add_background_task(trader.store_trade_history)
|
||||
return 'ok'
|
||||
|
||||
@bp.route('/store_bitcoin_price')
|
||||
async def store_bitcoin_price():
|
||||
current_app.add_background_task(trader.update_bitcoin_price)
|
||||
current_app.add_background_task(trader.store_bitcoin_price)
|
||||
return 'ok'
|
||||
|
|
|
@ -83,7 +83,7 @@ class Trader(TradeOgre):
|
|||
o.save()
|
||||
logging.info(f'[ORDERS] Saved order {order["uuid"]} to the database')
|
||||
|
||||
def update_orders(self):
|
||||
def store_orders(self):
|
||||
logging.info('[ORDERS] Updating orders in local database against TradeOgre')
|
||||
for order in self.get_active_orders():
|
||||
logging.info(f'Checking order {order.uuid}')
|
||||
|
@ -94,7 +94,7 @@ class Trader(TradeOgre):
|
|||
order.save()
|
||||
logging.info(f'Order {order.uuid} no longer active on TradeOgre. Setting inactive.')
|
||||
|
||||
def update_trade_history(self):
|
||||
def store_trade_history(self):
|
||||
logging.info('Updating trade history for the ticker')
|
||||
for trade in self.get_history(self.trade_pair):
|
||||
tr = Trade(
|
||||
|
@ -108,7 +108,7 @@ class Trader(TradeOgre):
|
|||
tr.save()
|
||||
logging.info('Trade added to the database')
|
||||
|
||||
def update_bitcoin_price(self):
|
||||
def store_bitcoin_price(self):
|
||||
logging.info('Updating Bitcoin price')
|
||||
r = self.get_bitcoin_price()
|
||||
bp = BitcoinPrice(
|
||||
|
|
|
@ -35,9 +35,7 @@
|
|||
// }).show();
|
||||
|
||||
render() {
|
||||
// fetch latest data for the UI
|
||||
let updateAllData;
|
||||
// trigger background tasks to store data
|
||||
let storeMarketData;
|
||||
let storeBalances;
|
||||
let storeBitcoinPrice;
|
||||
|
@ -49,12 +47,28 @@
|
|||
fetch('{{ url_for("api.get_ticker_data") }}')
|
||||
.then((response) => response.json())
|
||||
.then((res) => {
|
||||
console.log(res);
|
||||
document.getElementById('get_ticker_data').innerHTML = JSON.stringify(res);
|
||||
});
|
||||
fetch('{{ url_for("api.get_balances") }}')
|
||||
.then((response) => response.json())
|
||||
.then((res) => {
|
||||
document.getElementById('get_balances').innerHTML = JSON.stringify(res)
|
||||
});
|
||||
fetch('{{ url_for("api.get_bitcoin_price") }}')
|
||||
.then((response) => response.json())
|
||||
.then((res) => {
|
||||
document.getElementById('get_bitcoin_price').innerHTML = JSON.stringify(res)
|
||||
});
|
||||
fetch('{{ url_for("api.get_orders") }}')
|
||||
.then((response) => response.json())
|
||||
.then((res) => {
|
||||
document.getElementById('get_orders').innerHTML = JSON.stringify(res)
|
||||
});
|
||||
fetch('{{ url_for("api.get_trade_history") }}')
|
||||
.then((response) => response.json())
|
||||
.then((res) => {
|
||||
document.getElementById('get_trade_history').innerHTML = JSON.stringify(res)
|
||||
});
|
||||
fetch('{{ url_for("api.get_balances") }}');
|
||||
fetch('{{ url_for("api.get_bitcoin_price") }}');
|
||||
fetch('{{ url_for("api.get_orders") }}');
|
||||
fetch('{{ url_for("api.get_trade_history") }}');
|
||||
}
|
||||
|
||||
if (this.state.looping) {
|
||||
|
@ -78,7 +92,7 @@
|
|||
console.log('storing trade history');
|
||||
fetch('{{ url_for("tasks.store_trade_history") }}');
|
||||
}, 60000);
|
||||
updateAllData = setInterval(getAllData(), 10000);
|
||||
updateAllData = setInterval(getAllData, 10000);
|
||||
}
|
||||
|
||||
return(
|
||||
|
@ -88,7 +102,7 @@
|
|||
<div>
|
||||
<p>market making is started</p>
|
||||
<button onClick={() => {
|
||||
this.setState({looping: false});
|
||||
this.setState({...this.state, looping: false});
|
||||
clearInterval(storeMarketData);
|
||||
clearInterval(storeBalances);
|
||||
clearInterval(storeBitcoinPrice);
|
||||
|
@ -101,28 +115,23 @@
|
|||
<div>
|
||||
<p>market making is stopped</p>
|
||||
<button onClick={() => {
|
||||
this.setState({looping: true});
|
||||
this.setState({...this.state, looping: true});
|
||||
getAllData();
|
||||
}}>Start</button>
|
||||
</div>
|
||||
)}
|
||||
<p id="get_ticker_data"></p>
|
||||
<p id="get_balances"></p>
|
||||
<p id="get_bitcoin_price"></p>
|
||||
<p id="get_orders"></p>
|
||||
<p id="get_trade_history"></p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// this.setState(prevState => {
|
||||
// let jasper = { ...prevState.jasper }; // creating copy of state variable jasper
|
||||
// jasper.name = 'someothername'; // store the name property, assign a new value
|
||||
// return { jasper }; // return new object jasper object
|
||||
// });
|
||||
|
||||
const domContainer = document.querySelector('#container');
|
||||
const root = ReactDOM.createRoot(domContainer);
|
||||
root.render(e(App));
|
||||
|
||||
// setInterval(function() {
|
||||
// fetch('{{ url_for("tasks.store_ticker_data") }}');
|
||||
// }, 10000)
|
||||
|
||||
</script>
|
|
@ -59,7 +59,7 @@ class TradeOgre(object):
|
|||
return self.req(route, 'post', data)
|
||||
|
||||
def get_bitcoin_price(self):
|
||||
url = 'https://api.coingecko.com/api/v3/coins/wownero'
|
||||
url = 'https://api.coingecko.com/api/v3/coins/bitcoin'
|
||||
headers = {'accept': 'application/json'}
|
||||
data = {
|
||||
'localization': False,
|
||||
|
|
Loading…
Reference in a new issue