From bc56861ca1d63ede55160d4dfea96009056a178a Mon Sep 17 00:00:00 2001 From: lza_menace Date: Sun, 6 Sep 2020 06:27:19 -0700 Subject: [PATCH] adding work thus far --- README.md | 22 +- db.py | 64 +++++ docker-compose.yaml | 33 +++ grafana/daemon_metrics.json | 506 ++++++++++++++++++++++++++++++++++++ grafana/dashboards.yaml | 13 + grafana/prometheus.yaml | 9 + requirements.txt | 3 + trade.py | 86 ++++++ 8 files changed, 735 insertions(+), 1 deletion(-) create mode 100644 db.py create mode 100644 docker-compose.yaml create mode 100644 grafana/daemon_metrics.json create mode 100644 grafana/dashboards.yaml create mode 100644 grafana/prometheus.yaml create mode 100644 requirements.txt create mode 100755 trade.py diff --git a/README.md b/README.md index ff6d696..95260f0 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,23 @@ # to-trade-bot -Makin money, ya bitch, can ya dig it? \ No newline at end of file +Makin money, ya bitch, can ya dig it? + +From this youtube vid: https://www.youtube.com/watch?v=es9jyTTxKB4 + +1. get current price +2. look at book and place 1 buy order directly below price and 1 sell order above price +3. Once the buy and sell is filled, do it again + + +### 1. Manipulations and beliefs + +Market is not driven by price, but by belief. The market is determined by what traders believe. + +The market is manipulated; it is a manipulative process. (Beliefs of the traders is being manipulated). + + +3 phases of the manipulation process: + +* Accumulation - when accumulation of buy or sell orders is taking place. +* Manipulation - where market makers use well established practices to manipulate traders beliefs about future price. +* Profit Release - where market makers are able to distribute the orders they accumulated in the first phase. diff --git a/db.py b/db.py new file mode 100644 index 0000000..2c08b37 --- /dev/null +++ b/db.py @@ -0,0 +1,64 @@ +from os import getenv +from dotenv import load_dotenv +from peewee import * +from datetime import datetime, timedelta + + +load_dotenv('.env') + +db = PostgresqlDatabase( + 'trader', + user=getenv('DB_USER'), + password=getenv('DB_PASS'), + host=getenv('DB_HOST', '127.0.0.1'), + port=getenv('DB_PORT', 5432) +) + +def get_time(): + now = datetime.now() + now = now + timedelta(hours=7) + return now + +class Ticker(Model): + id = AutoField() + trade_pair = CharField() + initial_price = DoubleField() + current_price = DoubleField() + high_price = DoubleField() + low_price = DoubleField() + volume = DoubleField() + bid = DoubleField() + ask = DoubleField() + spread_btc = DoubleField() + spread_sats = IntegerField() + spread_perc = DoubleField() + date = DateTimeField(default=get_time) + + class Meta: + database = db + +class Balance(Model): + total = DoubleField() + available = DoubleField() + currency = CharField() + date = DateTimeField(default=get_time) + + class Meta: + database = db + +# class Trade(Model): +# id = AutoField() +# title = CharField() +# text = CharField() +# submitter = CharField() +# image_name = CharField() +# readonly = BooleanField(default=False) +# hidden = BooleanField(default=False) +# account_index = DoubleField() +# address_index = DoubleField() +# timestamp = DateTimeField(default=datetime.now) +# +# class Meta: +# database = db + +db.create_tables([Ticker, Balance]) diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..e132f72 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,33 @@ +version: '3' +volumes: + grafana: + postgres: +services: + grafana: + image: grafana/grafana:6.5.0 + container_name: trader_grafana + ports: + - 127.0.0.1:3000:3000 + environment: + HOSTNAME: grafana + GF_SECURITY_ADMIN_USER: admin + GF_SECURITY_ADMIN_PASSWORD: ${GRAFANA_PASSWORD} + GF_SERVER_ROOT_URL: ${GRAFANA_URL} + GF_ANALYTICS_REPORTING_ENABLED: "false" + GF_ANALYTICS_CHECK_FOR_UPDATES: "false" + GF_USERS_ALLOW_SIGN_UP: "false" + GF_USERS_ALLOW_ORG_CREATE: "false" + GF_LOG_LEVEL: "debug" + volumes: + - grafana:/var/lib/grafana + postgres: + image: postgres:9.6.15-alpine + container_name: trader_postgres + ports: + - 5432:5432 + environment: + POSTGRES_PASSWORD: ${DB_PASS} + POSTGRES_USER: ${DB_USER} + POSTGRES_DB: ${DB_NAME} + volumes: + - postgres:/var/lib/postgresql/data diff --git a/grafana/daemon_metrics.json b/grafana/daemon_metrics.json new file mode 100644 index 0000000..a3f7cd3 --- /dev/null +++ b/grafana/daemon_metrics.json @@ -0,0 +1,506 @@ +{ + "annotations": { + "list": [ + { + "builtIn": 1, + "datasource": "-- Grafana --", + "enable": true, + "hide": true, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations & Alerts", + "type": "dashboard" + } + ] + }, + "editable": true, + "gnetId": null, + "graphTooltip": 0, + "id": 1, + "links": [], + "panels": [ + { + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": null, + "fill": 1, + "fillGradient": 0, + "gridPos": { + "h": 9, + "w": 12, + "x": 0, + "y": 0 + }, + "hiddenSeries": false, + "id": 4, + "legend": { + "avg": false, + "current": false, + "max": false, + "min": false, + "show": true, + "total": false, + "values": false + }, + "lines": true, + "linewidth": 1, + "nullPointMode": "connected", + "options": { + "dataLinks": [] + }, + "percentage": false, + "pointradius": 2, + "points": false, + "renderer": "flot", + "seriesOverrides": [], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "expr": "avg(monerod_connections_incoming)", + "legendFormat": "Incoming", + "refId": "A" + }, + { + "expr": "avg(monerod_connections_outgoing)", + "legendFormat": "Outgoing", + "refId": "B" + } + ], + "thresholds": [], + "timeFrom": null, + "timeRegions": [], + "timeShift": null, + "title": "Connections", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "type": "graph", + "xaxis": { + "buckets": null, + "mode": "time", + "name": null, + "show": true, + "values": [] + }, + "yaxes": [ + { + "decimals": null, + "format": "none", + "label": null, + "logBase": 1, + "max": null, + "min": "0", + "show": true + }, + { + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": true + } + ], + "yaxis": { + "align": false, + "alignLevel": null + } + }, + { + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": null, + "fill": 1, + "fillGradient": 0, + "gridPos": { + "h": 9, + "w": 12, + "x": 12, + "y": 0 + }, + "hiddenSeries": false, + "id": 2, + "legend": { + "avg": false, + "current": false, + "max": false, + "min": false, + "show": false, + "total": false, + "values": false + }, + "lines": true, + "linewidth": 1, + "nullPointMode": "connected", + "options": { + "dataLinks": [] + }, + "percentage": false, + "pointradius": 2, + "points": false, + "renderer": "flot", + "seriesOverrides": [ + { + "alias": "/.*/", + "color": "#C4162A" + } + ], + "spaceLength": 10, + "stack": false, + "steppedLine": true, + "targets": [ + { + "expr": "avg(monerod_block_difficulty)", + "refId": "A" + } + ], + "thresholds": [], + "timeFrom": null, + "timeRegions": [], + "timeShift": null, + "title": "Difficulty", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "type": "graph", + "xaxis": { + "buckets": null, + "mode": "time", + "name": null, + "show": true, + "values": [] + }, + "yaxes": [ + { + "format": "none", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": true + }, + { + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": true + } + ], + "yaxis": { + "align": false, + "alignLevel": null + } + }, + { + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": null, + "fill": 1, + "fillGradient": 0, + "gridPos": { + "h": 8, + "w": 12, + "x": 0, + "y": 9 + }, + "hiddenSeries": false, + "id": 8, + "legend": { + "avg": false, + "current": false, + "max": false, + "min": false, + "show": false, + "total": false, + "values": false + }, + "lines": true, + "linewidth": 1, + "nullPointMode": "connected", + "options": { + "dataLinks": [] + }, + "percentage": false, + "pointradius": 2, + "points": false, + "renderer": "flot", + "seriesOverrides": [ + { + "alias": "/.*/", + "color": "#FA6400" + } + ], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "expr": "avg(monerod_block_reward)", + "legendFormat": "Block Reward (WOW)", + "refId": "A" + } + ], + "thresholds": [], + "timeFrom": null, + "timeRegions": [], + "timeShift": null, + "title": "Block Reward (WOW)", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "type": "graph", + "xaxis": { + "buckets": null, + "mode": "time", + "name": null, + "show": true, + "values": [] + }, + "yaxes": [ + { + "decimals": null, + "format": "none", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": true + }, + { + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": false + } + ], + "yaxis": { + "align": false, + "alignLevel": null + } + }, + { + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": null, + "fill": 1, + "fillGradient": 0, + "gridPos": { + "h": 8, + "w": 12, + "x": 12, + "y": 9 + }, + "hiddenSeries": false, + "id": 6, + "legend": { + "avg": false, + "current": false, + "max": false, + "min": false, + "show": false, + "total": false, + "values": false + }, + "lines": true, + "linewidth": 1, + "nullPointMode": "connected", + "options": { + "dataLinks": [] + }, + "percentage": false, + "pointradius": 2, + "points": false, + "renderer": "flot", + "seriesOverrides": [ + { + "alias": "/.*/", + "color": "#8F3BB8" + } + ], + "spaceLength": 10, + "stack": false, + "steppedLine": true, + "targets": [ + { + "expr": "avg(monerod_tx_mempool)", + "legendFormat": "Pool Transactions", + "refId": "A" + } + ], + "thresholds": [], + "timeFrom": null, + "timeRegions": [], + "timeShift": null, + "title": "Mempool Transactions", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "type": "graph", + "xaxis": { + "buckets": null, + "mode": "time", + "name": null, + "show": true, + "values": [] + }, + "yaxes": [ + { + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": true + }, + { + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": true + } + ], + "yaxis": { + "align": false, + "alignLevel": null + } + }, + { + "cacheTimeout": null, + "colorBackground": false, + "colorPostfix": false, + "colorPrefix": false, + "colorValue": false, + "colors": [ + "#299c46", + "rgba(237, 129, 40, 0.89)", + "#d44a3a" + ], + "datasource": null, + "format": "none", + "gauge": { + "maxValue": 100, + "minValue": 0, + "show": false, + "thresholdLabels": false, + "thresholdMarkers": true + }, + "gridPos": { + "h": 5, + "w": 8, + "x": 8, + "y": 17 + }, + "id": 10, + "interval": null, + "links": [], + "mappingType": 1, + "mappingTypes": [ + { + "name": "value to text", + "value": 1 + }, + { + "name": "range to text", + "value": 2 + } + ], + "maxDataPoints": 100, + "nullPointMode": "connected", + "nullText": null, + "options": {}, + "postfix": "", + "postfixFontSize": "50%", + "prefix": "", + "prefixFontSize": "50%", + "rangeMaps": [ + { + "from": "null", + "text": "N/A", + "to": "null" + } + ], + "sparkline": { + "fillColor": "rgba(31, 118, 189, 0.18)", + "full": false, + "lineColor": "rgb(31, 120, 193)", + "show": false, + "ymax": null, + "ymin": null + }, + "tableColumn": "", + "targets": [ + { + "expr": "avg(monerod_tx_chain)", + "instant": true, + "refId": "A" + } + ], + "thresholds": "", + "timeFrom": null, + "timeShift": null, + "title": "Total Transactions", + "type": "singlestat", + "valueFontSize": "100%", + "valueMaps": [ + { + "op": "=", + "text": "N/A", + "value": "null" + } + ], + "valueName": "current" + } + ], + "refresh": "30s", + "schemaVersion": 21, + "style": "dark", + "tags": [], + "templating": { + "list": [] + }, + "time": { + "from": "now-6h", + "to": "now" + }, + "timepicker": { + "refresh_intervals": [ + "5s", + "10s", + "30s", + "1m", + "5m", + "15m", + "30m", + "1h", + "2h", + "1d" + ] + }, + "timezone": "", + "title": "Daemon Stats", + "uid": "0ktA4KDGk", + "version": 2 +} diff --git a/grafana/dashboards.yaml b/grafana/dashboards.yaml new file mode 100644 index 0000000..ce46f5a --- /dev/null +++ b/grafana/dashboards.yaml @@ -0,0 +1,13 @@ +apiVersion: 1 + +providers: +- name: 'default' + orgId: 1 + folder: '' + type: file + disableDeletion: true + editable: true + updateIntervalSeconds: 60 + allowUiUpdates: true + options: + path: /var/lib/grafana/dashboards diff --git a/grafana/prometheus.yaml b/grafana/prometheus.yaml new file mode 100644 index 0000000..75672ce --- /dev/null +++ b/grafana/prometheus.yaml @@ -0,0 +1,9 @@ +apiVersion: 1 + +datasources: +- name: PostgreSQL + type: postgresql + url: http://prometheus:9090 + access: proxy + isDefault: true + timeInterval: 10s diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..701266f --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +requests +peewee +psycopg2-binary diff --git a/trade.py b/trade.py new file mode 100755 index 0000000..d0f571a --- /dev/null +++ b/trade.py @@ -0,0 +1,86 @@ +#!/usr/bin/env python + +from os import getenv +from dotenv import load_dotenv +from requests import get as requests_get +from requests import post as requests_post +from requests.auth import HTTPBasicAuth +from decimal import Decimal +from pprint import pprint +from time import sleep +from db import Ticker, Balance + + +class TradeOgre(object): + def __init__(self): + load_dotenv('.env') + self.base = 'https://tradeogre.com/api/v1' + self.auth = HTTPBasicAuth( + getenv('TO_USER'), + getenv('TO_PASS') + ) + + def req(self, route, method='get', data={}): + url = self.base + route + if method == 'get': + r = requests_get(url, auth=self.auth) + else: + r = requests_post(url, auth=self.auth, data=data) + return r.json() + + def get_trade_pair(self, pair): + route = f'/ticker/{pair}' + return self.req(route) + + def get_balance(self, currency): + route = '/account/balance' + return self.req(route, 'post', {'currency': currency}) + + def get_balances(self): + route = '/account/balances' + return self.req(route) + + +def run(): + # define vars + to = TradeOgre() + base = 'BTC' + currency = 'WOW' + trade_pair = f'{base}-{currency}' + + # ticker market data + tp_res = to.get_trade_pair(trade_pair) + print(tp_res) + spreat_btc = Decimal(tp_res['ask']) - Decimal(tp_res['bid']) + spread_sats = float(spreat_btc / Decimal(.00000001)) + spread_perc = (spreat_btc / Decimal(tp_res['ask'])) * 100 + t = Ticker( + trade_pair=trade_pair, + initial_price=tp_res['initialprice'], + current_price=tp_res['price'], + high_price=tp_res['high'], + low_price=tp_res['low'], + volume=tp_res['volume'], + bid=tp_res['bid'], + ask=tp_res['ask'], + spread_btc=spreat_btc, + spread_sats=spread_sats, + spread_perc=spread_perc + ) + t.save() + + for c in base, currency: + gb_res = to.get_balance(c) + print(gb_res) + b = Balance( + currency=c, + total=gb_res['balance'], + available=gb_res['available'] + ) + b.save() + + +if __name__ == '__main__': + while True: + run() + sleep(30)