Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # IF YOU FOUND THIS USEFUL, Please Donate some Bitcoin ....
- # 1FWt366i5PdrxCC6ydyhD8iywUHQ2C7BWC
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- import numpy
- import pandas
- import matplotlib.pyplot as plt
- import matplotlib.dates as mdates
- # Scikit's LinearRegression model
- from sklearn.linear_model import LinearRegression
- from scipy import stats
- import math
- import os
- import requests
- import json
- import time
- import random
- import uuid
- from time import localtime, strftime
- import datetime as dt
- from datetime import date
- import calendar
- import sys
- import itertools
- import operator
- import sched
- from random import shuffle
- # ALL EPICS
- main_epic_ids = [
- 'CS.D.AUDUSD.TODAY.IP',
- 'CS.D.EURCHF.TODAY.IP',
- 'CS.D.EURGBP.TODAY.IP',
- 'CS.D.EURJPY.TODAY.IP',
- 'CS.D.EURUSD.TODAY.IP',
- 'CS.D.GBPEUR.TODAY.IP',
- 'CS.D.GBPUSD.TODAY.IP',
- 'CS.D.USDCAD.TODAY.IP',
- 'CS.D.USDCHF.TODAY.IP',
- 'CS.D.USDJPY.TODAY.IP',
- 'CS.D.CADCHF.TODAY.IP',
- 'CS.D.CADJPY.TODAY.IP',
- 'CS.D.CHFJPY.TODAY.IP',
- 'CS.D.EURCAD.TODAY.IP',
- 'CS.D.EURSGD.TODAY.IP',
- 'CS.D.EURZAR.TODAY.IP',
- 'CS.D.GBPCAD.TODAY.IP',
- 'CS.D.GBPCHF.TODAY.IP',
- 'CS.D.GBPJPY.TODAY.IP',
- 'CS.D.GBPSGD.TODAY.IP',
- 'CS.D.GBPZAR.TODAY.IP',
- 'CS.D.MXNJPY.TODAY.IP',
- 'CS.D.NOKJPY.TODAY.IP',
- 'CS.D.PLNJPY.TODAY.IP',
- 'CS.D.SEKJPY.TODAY.IP',
- 'CS.D.SGDJPY.TODAY.IP',
- 'CS.D.USDSGD.TODAY.IP',
- 'CS.D.USDZAR.TODAY.IP',
- 'CS.D.AUDCAD.TODAY.IP',
- 'CS.D.AUDCHF.TODAY.IP',
- 'CS.D.AUDEUR.TODAY.IP',
- 'CS.D.AUDGBP.TODAY.IP',
- 'CS.D.AUDJPY.TODAY.IP',
- 'CS.D.AUDNZD.TODAY.IP',
- 'CS.D.AUDSGD.TODAY.IP',
- 'CS.D.EURAUD.TODAY.IP',
- 'CS.D.EURNZD.TODAY.IP',
- 'CS.D.GBPAUD.TODAY.IP',
- 'CS.D.GBPNZD.TODAY.IP',
- 'CS.D.NZDAUD.TODAY.IP',
- 'CS.D.NZDCAD.TODAY.IP',
- 'CS.D.NZDCHF.TODAY.IP',
- 'CS.D.NZDEUR.TODAY.IP',
- 'CS.D.NZDGBP.TODAY.IP',
- 'CS.D.NZDJPY.TODAY.IP',
- 'CS.D.NZDUSD.TODAY.IP',
- 'CS.D.CHFHUF.TODAY.IP',
- 'CS.D.EURCZK.TODAY.IP',
- 'CS.D.EURHUF.TODAY.IP',
- 'CS.D.EURILS.TODAY.IP',
- 'CS.D.EURMXN.TODAY.IP',
- 'CS.D.EURPLN.TODAY.IP',
- 'CS.D.EURTRY.TODAY.IP',
- 'CS.D.GBPCZK.TODAY.IP',
- 'CS.D.GBPHUF.TODAY.IP',
- 'CS.D.GBPILS.TODAY.IP',
- 'CS.D.GBPMXN.TODAY.IP',
- 'CS.D.GBPPLN.TODAY.IP',
- 'CS.D.GBPTRY.TODAY.IP',
- 'CS.D.TRYJPY.TODAY.IP',
- 'CS.D.USDCZK.TODAY.IP',
- 'CS.D.USDHUF.TODAY.IP',
- 'CS.D.USDILS.TODAY.IP',
- 'CS.D.USDMXN.TODAY.IP',
- 'CS.D.USDPLN.TODAY.IP',
- 'CS.D.USDTRY.TODAY.IP',
- 'CS.D.CADNOK.TODAY.IP',
- 'CS.D.CHFNOK.TODAY.IP',
- 'CS.D.EURDKK.TODAY.IP',
- 'CS.D.EURNOK.TODAY.IP',
- 'CS.D.EURSEK.TODAY.IP',
- 'CS.D.GBPDKK.TODAY.IP',
- 'CS.D.GBPNOK.TODAY.IP',
- 'CS.D.GBPSEK.TODAY.IP',
- 'CS.D.NOKSEK.TODAY.IP',
- 'CS.D.USDDKK.TODAY.IP',
- 'CS.D.USDNOK.TODAY.IP',
- 'CS.D.USDSEK.TODAY.IP',
- 'CS.D.AUDCNH.TODAY.IP',
- 'CS.D.CADCNH.TODAY.IP',
- 'CS.D.CNHJPY.TODAY.IP',
- 'CS.D.BRLJPY.TODAY.IP',
- 'CS.D.GBPINR.TODAY.IP',
- 'CS.D.USDBRL.TODAY.IP',
- 'CS.D.USDIDR.TODAY.IP',
- 'CS.D.USDINR.TODAY.IP',
- 'CS.D.USDKRW.TODAY.IP',
- 'CS.D.USDMYR.TODAY.IP',
- 'CS.D.USDPHP.TODAY.IP',
- 'CS.D.USDTWD.TODAY.IP',
- 'CS.D.EURCNH.TODAY.IP',
- 'CS.D.sp_EURRUB.TODAY.IP',
- 'CS.D.GBPCNH.TODAY.IP',
- 'CS.D.NZDCNH.TODAY.IP',
- 'CS.D.USDCNH.TODAY.IP',
- 'CS.D.sp_USDRUB.TODAY.IP']
- # ALL EPICS
- # TESTINGs
- # main_epic_ids = [
- # 'CS.D.AUDUSD.TODAY.IP',
- # 'CS.D.EURGBP.TODAY.IP',
- # 'CS.D.EURJPY.TODAY.IP',
- # 'CS.D.EURUSD.TODAY.IP',
- # 'CS.D.GBPUSD.TODAY.IP',
- # 'CS.D.USDCAD.TODAY.IP',
- # 'CS.D.USDCHF.TODAY.IP',
- # 'CS.D.USDJPY.TODAY.IP',
- # 'CS.D.AUDEUR.TODAY.IP',
- # 'CS.D.AUDGBP.TODAY.IP',
- # 'CS.D.AUDJPY.TODAY.IP',
- # 'CS.D.EURAUD.TODAY.IP',
- # 'CS.D.GBPAUD.TODAY.IP']
- # # TESTING
- # TIME_FRAMES = ["MINUTE/1", "MINUTE_2/1", "MINUTE_3/1", "MINUTE_5/1", "MINUTE_10/1",
- # "MINUTE_15/1", "MINUTE_30/1", "HOUR/1", "HOUR_2/1", "HOUR_3/1", "HOUR_4/1",
- # "DAY/1", "WEEK/1", "MONTH/1"]
- REAL_OR_NO_REAL = 'https://api.ig.com/gateway/deal'
- API_ENDPOINT = "https://api.ig.com/gateway/deal/session"
- API_KEY = '<<<YOUR API KEY HERE>>>'
- data = {"identifier": "<<<YOUR USERNAME HERE>>>", "password": "<<<YOUR PASSWORD HERE>>>"}
- headers = {'Content-Type': 'application/json; charset=utf-8',
- 'Accept': 'application/json; charset=utf-8',
- 'X-IG-API-KEY': API_KEY,
- 'Version': '2'
- }
- r = requests.post(API_ENDPOINT, data=json.dumps(data), headers=headers)
- headers_json = dict(r.headers)
- CST_token = headers_json["CST"]
- print(R"CST : " + CST_token)
- x_sec_token = headers_json["X-SECURITY-TOKEN"]
- print(R"X-SECURITY-TOKEN : " + x_sec_token)
- # GET ACCOUNTS
- base_url = REAL_OR_NO_REAL + '/accounts'
- authenticated_headers = {'Content-Type': 'application/json; charset=utf-8',
- 'Accept': 'application/json; charset=utf-8',
- 'X-IG-API-KEY': API_KEY,
- 'CST': CST_token,
- 'X-SECURITY-TOKEN': x_sec_token}
- auth_r = requests.get(base_url, headers=authenticated_headers)
- d = json.loads(auth_r.text)
- # print ("-----------------DEBUG-----------------")
- # print ("#################DEBUG#################")
- # print(auth_r.status_code)
- # print(auth_r.reason)
- # print (auth_r.text)
- # print ("-----------------DEBUG-----------------")
- # print ("#################DEBUG#################")
- for i in d['accounts']:
- if str(i['accountType']) == "SPREADBET":
- print("Spreadbet Account ID is : " + str(i['accountId']))
- spreadbet_acc_id = str(i['accountId'])
- # SET SPREAD BET ACCOUNT AS DEFAULT
- base_url = REAL_OR_NO_REAL + '/session'
- data = {"accountId": spreadbet_acc_id, "defaultAccount": "True"}
- auth_r = requests.put(
- base_url,
- data=json.dumps(data),
- headers=authenticated_headers)
- # print ("-----------------DEBUG-----------------")
- # print ("#################DEBUG#################")
- # print(auth_r.status_code)
- # print(auth_r.reason)
- # print (auth_r.text)
- # print ("-----------------DEBUG-----------------")
- # print ("#################DEBUG#################")
- # ERROR about account ID been the same, Ignore!
- ##########################################################################
- ##########################END OF LOGIN CODE###############################
- ##########################END OF LOGIN CODE###############################
- ##########################END OF LOGIN CODE###############################
- ##########################END OF LOGIN CODE###############################
- ##########################################################################
- # PROGRAMMABLE VALUES
- # SET INITIAL VARIABLES, Hacky for now!
- orderType_value = "MARKET"
- size_value = "3"
- expiry_value = "DFB"
- guaranteedStop_value = True
- currencyCode_value = "GBP"
- forceOpen_value = True
- stopDistance_value = "15" # Make this a global variable for ease!
- SL_MULTIPLIER = 2.99
- LOW_SL_WATERMARK = 20
- HIGH_SL_WATERMARK = 70
- STR_CHECK = ""
- def is_between(time, time_range):
- if time_range[1] < time_range[0]:
- return time >= time_range[0] or time <= time_range[1]
- return time_range[0] <= time <= time_range[1]
- def midpoint(p1, p2):
- return (p1 + p2) / 2
- def distance(a, b):
- if (a == b):
- return 0
- elif (a < 0) and (b < 0) or (a > 0) and (b > 0):
- if (a < b):
- return (abs(abs(a) - abs(b)))
- else:
- return -(abs(abs(a) - abs(b)))
- else:
- return math.copysign((abs(a) + abs(b)), b)
- # Frankfurt
- # Germany
- # EUR
- # print("Frankfurt Market Status:...." + str(is_between(str(now_time), ("06:00", "14:00"))))
- # London
- # Great Britain
- # GBP
- # print("London Market Status:...." + str(is_between(str(now_time), ("07:00", "15:00"))))
- # New York
- # United States
- # USD
- # print("New York Market Status:...." + str(is_between(str(now_time), ("12:00", "20:30"))))
- # Sydney
- # Austrailia
- # AUD
- # print("Sydney Market Status:...." + str(is_between(str(now_time), ("22:00", "06:30"))))
- # Tokyo
- # Japan
- # JPY
- # print("Tokyo Market Status:...." + str(is_between(str(now_time),
- # ("23:00", "07:30"))))
- def percentage(part, whole):
- return 100 * float(part) / float(whole)
- def humanize_time(secs):
- mins, secs = divmod(secs, 60)
- hours, mins = divmod(mins, 60)
- return '%02d:%02d:%02d' % (hours, mins, secs)
- def lowest_spread_epic():
- spreads_and_epics = []
- i_count = 0
- pick_from_epics = []
- for epic_id in main_epic_ids:
- tmp_lst = []
- base_url = REAL_OR_NO_REAL + '/markets/' + epic_id
- auth_r = requests.get(base_url, headers=authenticated_headers)
- d = json.loads(auth_r.text)
- try:
- i_count = i_count + 1
- if epic_id.find('MXN') != -1:
- #print("!!DEBUG!!...skipping, FOUND MXN in..." + str(epic_id))
- time.sleep(1)
- elif epic_id.find('SEK') != -1:
- #print("!!DEBUG!!...skipping, FOUND SEK in..." + str(epic_id))
- time.sleep(1)
- elif epic_id.find('NOK') != -1:
- #print("!!DEBUG!!...skipping, FOUND NOK in..." + str(epic_id))
- time.sleep(1)
- elif epic_id.find('CNH') != -1:
- #print("!!DEBUG!!...skipping, FOUND CNH in..." + str(epic_id))
- time.sleep(1)
- else:
- b_TRADE_OK = False
- while True:
- now_time = strftime("%H:%M", localtime())
- # A bit about this, If market is not open...Don't trade it's respective pair!
- ###################EUROPE############################
- ###################EUROPE############################
- ###################EUROPE############################
- if is_between(str(now_time), ("06:00", "14:00")):
- #print("!!DEBUG!!...FRANKFURT MARKET OPEN!!")
- time.sleep(1)
- STR_CHECK = "EUR"
- if STR_CHECK in epic_id:
- b_TRADE_OK = True
- break
- ###################LONDON############################
- ###################LONDON############################
- ###################LONDON############################
- if is_between(str(now_time), ("07:00", "15:00")):
- #print("!!DEBUG!!...LONDON MARKET OPEN!!")
- time.sleep(1)
- STR_CHECK = "GBP"
- if STR_CHECK in epic_id:
- b_TRADE_OK = True
- break
- ###################NY############################
- ###################NY############################
- ###################NY############################
- if is_between(str(now_time), ("12:00", "22:00")):
- #print("!!DEBUG!!...NEW YORK MARKET OPEN!!")
- time.sleep(1)
- STR_CHECK = "USD"
- if STR_CHECK in epic_id:
- b_TRADE_OK = True
- break
- ###################AUS############################
- ###################AUS############################
- ###################AUS############################
- if is_between(str(now_time), ("22:00", "06:00")):
- #print("!!DEBUG!!...SYDNEY MARKET OPEN!!")
- time.sleep(1)
- STR_CHECK = "AUD"
- if STR_CHECK in epic_id:
- b_TRADE_OK = True
- break
- ###################TOKYO############################
- ###################TOKYO############################
- ###################TOKYO############################
- if is_between(str(now_time), ("23:00", "07:00")):
- #print("!!DEBUG!!...TOKYO MARKET OPEN!!")
- time.sleep(1)
- STR_CHECK = "JPY"
- if STR_CHECK in epic_id:
- b_TRADE_OK = True
- break
- break
- if b_TRADE_OK:
- current_bid = d['snapshot']['bid']
- ask_price = d['snapshot']['offer']
- spread = float(current_bid) - float(ask_price)
- if float(spread) >= -1:
- # tmp_lst.append(epic_id)
- # spreads_and_epics.append(tmp_lst)
- pick_from_epics.append(epic_id)
- # print ("bid : " + str(current_bid))
- # print ("ask : " + str(ask_price))
- # print ("-------------------------")
- # print ("spread : " + str(spread))
- # print ("-------------------------")
- print("!!DEBUG!!...FOUND GOOD EPIC..." +
- str(i_count) + "/" + str(len(main_epic_ids)))
- time.sleep(1)
- else:
- print(
- "!!DEBUG!!...skipping, NO GOOD EPIC....Checking next epic spreads..." +
- str(i_count) +
- "/" +
- str(
- len(main_epic_ids)))
- time.sleep(1)
- continue
- except Exception as e:
- print(e)
- pass
- # sorted_list = sorted(spreads_and_epics, key=operator.itemgetter(1))
- # for i in range(len(sorted_list)):
- # print(sorted_list[i])
- # print (max(sorted_list, key=lambda x: x[1]))
- # lowest_epic = max(sorted_list, key=lambda x: x[1])
- # return (str(lowest_epic[0]))
- return (pick_from_epics)
- def are_we_going_to_trade(epic_id, TRADE_DIRECTION, limit):
- if TRADE_DIRECTION == "NONE":
- return None
- limitDistance_value = str(limit)
- ##########################################################################
- print(
- "Order will be a " +
- str(TRADE_DIRECTION) +
- " Order, With a limit of: " +
- str(limitDistance_value))
- print(
- "stopDistance_value for " +
- str(epic_id) +
- " will bet set at " +
- str(stopDistance_value))
- ##########################################################################
- # MAKE AN ORDER
- base_url = REAL_OR_NO_REAL + '/positions/otc'
- data = {
- "direction": TRADE_DIRECTION,
- "epic": epic_id,
- "limitDistance": limitDistance_value,
- "orderType": orderType_value,
- "size": size_value,
- "expiry": expiry_value,
- "guaranteedStop": guaranteedStop_value,
- "currencyCode": currencyCode_value,
- "forceOpen": forceOpen_value,
- "stopDistance": stopDistance_value}
- r = requests.post(
- base_url,
- data=json.dumps(data),
- headers=authenticated_headers)
- print("-----------------DEBUG-----------------")
- print("#################DEBUG#################")
- print(r.status_code)
- print(r.reason)
- print(r.text)
- print("-----------------DEBUG-----------------")
- print("#################DEBUG#################")
- d = json.loads(r.text)
- deal_ref = d['dealReference']
- time.sleep(1)
- # CONFIRM MARKET ORDER
- base_url = REAL_OR_NO_REAL + '/confirms/' + deal_ref
- auth_r = requests.get(base_url, headers=authenticated_headers)
- d = json.loads(auth_r.text)
- DEAL_ID = d['dealId']
- print("DEAL ID : " + str(d['dealId']))
- print(d['dealStatus'])
- print(d['reason'])
- if str(d['reason']) != "SUCCESS":
- print("!!DEBUG!!...!!some thing occurred ERROR!!")
- time.sleep(10)
- print("-----------------DEBUG-----------------")
- print("#################DEBUG#################")
- print("!!DEBUG!! Resuming...")
- print("-----------------DEBUG-----------------")
- print("#################DEBUG#################")
- else:
- print("-----------------DEBUG-----------------")
- print("#################DEBUG#################")
- print("!!DEBUG!!...Yay, ORDER OPEN")
- time.sleep(10)
- print("-----------------DEBUG-----------------")
- print("#################DEBUG#################")
- def Chandelier_Exit_formula(TRADE_DIR, ATR, Price):
- # Chandelier Exit (long) = 22-day High - ATR(22) x 3
- # Chandelier Exit (short) = 22-day Low + ATR(22) x 3
- if TRADE_DIR == "BUY":
- return float(Price) - float(ATR) * 3
- elif TRADE_DIR == "SELL":
- return float(Price) + float(ATR) * 3
- def calculate_stop_loss(d):
- price_ranges = []
- closing_prices = []
- first_time_round_loop = True
- TR_prices = []
- price_compare = "bid"
- for i in d['prices']:
- if first_time_round_loop:
- # First time round loop cannot get previous
- closePrice = i['closePrice'][price_compare]
- closing_prices.append(closePrice)
- high_price = i['highPrice'][price_compare]
- low_price = i['lowPrice'][price_compare]
- price_range = float(high_price - closePrice)
- price_ranges.append(price_range)
- first_time_round_loop = False
- else:
- prev_close = closing_prices[-1]
- ###############################
- closePrice = i['closePrice'][price_compare]
- closing_prices.append(closePrice)
- high_price = i['highPrice'][price_compare]
- low_price = i['lowPrice'][price_compare]
- price_range = float(high_price - closePrice)
- price_ranges.append(price_range)
- TR = max(high_price - low_price,
- abs(high_price - prev_close),
- abs(low_price - prev_close))
- TR_prices.append(TR)
- return str(int(float(max(TR_prices))))
- if __name__ == '__main__':
- while True:
- try:
- base_url = REAL_OR_NO_REAL + "/accounts"
- auth_r = requests.get(base_url, headers=authenticated_headers)
- d = json.loads(auth_r.text)
- print("-----------------DEBUG-----------------")
- print("#################DEBUG#################")
- print(auth_r.status_code)
- print(auth_r.reason)
- print(auth_r.text)
- print("-----------------DEBUG-----------------")
- print("#################DEBUG#################")
- for i in d['accounts']:
- if str(i['accountType']) == "SPREADBET":
- balance = i['balance']['balance']
- deposit = i['balance']['deposit']
- percent_used = percentage(deposit, balance)
- print("-----------------DEBUG-----------------")
- print("#################DEBUG#################")
- print(
- "!!DEBUG!!...Percent of account used ..." +
- str(percent_used))
- print("-----------------DEBUG-----------------")
- print("#################DEBUG#################")
- if float(percent_used) > 70:
- print("!!DEBUG!!...Don't trade, Too much margin used up already")
- time.sleep(60)
- continue
- else:
- print("!!DEBUG!!...OK to trade, Account balance OK!!")
- tradeable_epic_ids = lowest_spread_epic()
- shuffle(tradeable_epic_ids)
- except Exception as e:
- print(e)
- print("!!DEBUG!!...No Suitable Epics...Yet!!, Try again!!")
- continue
- for epic_id in tradeable_epic_ids:
- base_url = REAL_OR_NO_REAL + "/prices/" + epic_id + "/MINUTE_15/16"
- # Price resolution (MINUTE, MINUTE_2, MINUTE_3, MINUTE_5,
- # MINUTE_10, MINUTE_15, MINUTE_30, HOUR, HOUR_2, HOUR_3,
- # HOUR_4, DAY, WEEK, MONTH)
- auth_r = requests.get(base_url, headers=authenticated_headers)
- d = json.loads(auth_r.text)
- # print("-----------------DEBUG-----------------")
- # print("#################DEBUG#################")
- # print(auth_r.status_code)
- # print(auth_r.reason)
- # print(auth_r.text)
- # print("-----------------DEBUG-----------------")
- # print("#################DEBUG#################")
- high_prices = []
- low_prices = []
- mid_prices = []
- close_prices = []
- ATR = calculate_stop_loss(d)
- remaining_allowance = d['allowance']['remainingAllowance']
- reset_time = humanize_time(int(d['allowance']['allowanceExpiry']))
- print("-----------------DEBUG-----------------")
- print("#################DEBUG#################")
- print("Remaining API Calls left: " + str(remaining_allowance))
- print("Time to API Key reset: " + str(reset_time))
- print("-----------------DEBUG-----------------")
- print("#################DEBUG#################")
- for i in d['prices']:
- if i['highPrice']['bid'] is not None:
- highPrice = i['highPrice']['bid']
- high_prices.append(highPrice)
- ########################################
- if i['lowPrice']['bid'] is not None:
- lowPrice = i['lowPrice']['bid']
- low_prices.append(lowPrice)
- ########################################
- if i['closePrice']['bid'] is not None:
- closePrice = i['lowPrice']['bid']
- close_prices.append(closePrice)
- ########################################
- mid_prices.append(float(midpoint(highPrice, lowPrice)))
- close_prices = numpy.asarray(close_prices)
- low_prices = numpy.asarray(low_prices)
- high_prices = numpy.asarray(high_prices)
- mid_prices = numpy.asarray(mid_prices)
- xi = numpy.arange(0, len(low_prices))
- close_prices_slope, close_prices_intercept, close_prices_r_value, close_prices_p_value, close_prices_std_err = stats.linregress(
- xi, close_prices)
- low_prices_slope, low_prices_intercept, low_prices_r_value, low_prices_p_value, low_prices_std_err = stats.linregress(
- xi, low_prices)
- high_prices_slope, high_prices_intercept, high_prices_r_value, high_prices_p_value, high_prices_std_err = stats.linregress(
- xi, high_prices)
- mid_prices_slope, mid_prices_intercept, mid_prices_r_value, mid_prices_p_value, mid_prices_std_err = stats.linregress(
- xi, mid_prices)
- # close_prices_line = close_prices_slope * xi + close_prices_intercept
- # low_prices_line = low_prices_slope * xi + low_prices_intercept
- # high_prices_line = high_prices_slope * xi + high_prices_intercept
- # mid_prices_line = mid_prices_slope * xi + mid_prices_intercept
- # plt.plot(
- # xi,
- # low_prices_line,
- # xi,
- # high_prices_line,
- # xi,
- # close_prices,
- # 'g--',
- # xi,
- # mid_prices_line)
- # plt.fill_between(
- # xi,
- # low_prices_line,
- # high_prices_line,
- # facecolor='green',
- # alpha=0.5)
- # plt.xlabel('X Axis')
- # plt.ylabel('Y Axis')
- # plt.show()
- # plt.clf()
- base_url = REAL_OR_NO_REAL + '/markets/' + epic_id
- auth_r = requests.get(
- base_url, headers=authenticated_headers)
- d = json.loads(auth_r.text)
- # print("-----------------DEBUG-----------------")
- # print("#################DEBUG#################")
- # print(auth_r.status_code)
- # print(auth_r.reason)
- # print(auth_r.text)
- # print("-----------------DEBUG-----------------")
- # print("#################DEBUG#################")
- current_bid = d['snapshot']['bid']
- if distance(current_bid, mid_prices_intercept) > 1: # Upper Line
- TRADE_DIRECTION = "BUY"
- pip_limit = int(abs(float(max(high_prices)) -
- float(current_bid)) / SL_MULTIPLIER)
- print("-----------------DEBUG-----------------")
- print("#################DEBUG#################")
- print("!!DEBUG!!...BUY!!")
- print(str(epic_id))
- print(
- "!!DEBUG!!...Take Profit@...." +
- str(pip_limit) +
- " pips")
- print("-----------------DEBUG-----------------")
- print("#################DEBUG#################")
- ce_stop = Chandelier_Exit_formula(
- TRADE_DIRECTION, ATR, min(low_prices))
- tmp_stop = int(abs(float(current_bid) - (ce_stop)))
- elif distance(current_bid, mid_prices_intercept) < -1: # Lower Line
- TRADE_DIRECTION = "SELL"
- pip_limit = int(abs(float(min(low_prices)) -
- float(current_bid)) / SL_MULTIPLIER)
- print("-----------------DEBUG-----------------")
- print("#################DEBUG#################")
- print("!!DEBUG!!...SELL!!")
- print(str(epic_id))
- print(
- "!!DEBUG!!...Take Profit@...." +
- str(pip_limit) +
- " pips")
- print("-----------------DEBUG-----------------")
- print("#################DEBUG#################")
- ce_stop = Chandelier_Exit_formula(
- TRADE_DIRECTION, ATR, max(high_prices))
- tmp_stop = int(abs(float(current_bid) - (ce_stop)))
- else:
- pip_limit = 9999999
- tmp_stop = "999999"
- TRADE_DIRECTION = "NONE"
- print("!!DEBUG!!...Within trading range...Leave!!")
- if int(pip_limit) <= 1:
- print("!!DEBUG!!...No Trade!!, Pip Limit Under 1")
- TRADE_DIRECTION = "NONE"
- stopDistance_value = str(tmp_stop)
- if int(stopDistance_value) <= LOW_SL_WATERMARK or int(
- stopDistance_value) >= HIGH_SL_WATERMARK:
- TRADE_DIRECTION = "NONE"
- try:
- are_we_going_to_trade(epic_id, TRADE_DIRECTION, pip_limit)
- except Exception as e:
- print(e)
- print("Something fucked up!!, Try again!!")
- continue
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement