Skip to content

Commit

Permalink
Reorganization
Browse files Browse the repository at this point in the history
  • Loading branch information
ProfitWaveTradingCo committed Jul 8, 2023
1 parent 790ee07 commit 8615a5f
Show file tree
Hide file tree
Showing 104 changed files with 129 additions and 185,247 deletions.
30 changes: 3 additions & 27 deletions Trading_Pal/oanda.py → 1st_ version/oanda.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
CEO: Dectrick A. McGee
For inquiries and support, please contact:
Email: profitwave[email protected]
Email: profitwavet[email protected]
"""

import json
Expand All @@ -16,17 +16,15 @@
import configparser
import winsound

This comment has been minimized.

Copy link
@nicolad

nicolad Jul 18, 2023

@ProfitWaveTradingCo this is Windows-specific, I am runnning MacOS

from words import trading_keywords, endpoint_phrases
from backtest import Strategies
import pandas as pd
import oandapyV20
import oandapyV20.endpoints.transactions as transactions
from oandapyV20.contrib.requests import MarketOrderRequest
from oandapyV20.exceptions import V20Error
from oandapyV20.endpoints.orders import OrderCreate
import openai
from backtest import Strategies
import pandas as pd

import pandas as pd
# Read keys from config.ini
config = configparser.ConfigParser()
config.read('config.ini')
Expand Down Expand Up @@ -85,8 +83,7 @@ def text_to_speech(text):
def print_with_voice(text):
print(text)
text_to_speech(text)
# Initialize backtest module
strategies_instance = Strategies(pd)




Expand Down Expand Up @@ -601,27 +598,6 @@ def get_tradeable_instruments(ACCOUNT_ID):

matched_endpoint = input("Enter 'ok' to continue creating orders or press Enter to exit: ")

elif matched_endpoint == "execute_backtest":

# Assuming that backtest requires parameters, let's say the name of the strategy and historical data.
# You should replace these inputs with actual ones according to your backtest module's requirements.
strategy_name = input("Enter the strategy name: ")
# Here you need to provide the data for backtesting, assuming it is stored in a CSV file
data = pd.read_csv(r'C:\Users\kingp\Downloads\Trading_Pal-main\Trading_Pal-main\GBP_USD_D.csv')

try:
backtest_results = strategies_instance.backtest(strategy_name, data)
# Add the backtest results to the messages as a system message
messages.append({"role": "system", "content": f"Backtest results: {backtest_results}"})

# Send the backtest results to the GPT-3 model as a user message
messages.append({"role": "user", "content": f"The backtest results for the {strategy_name} strategy are: {backtest_results}"})

except Exception as e:
# If there was an error executing the backtest, add that to the messages
messages.append({"role": "system", "content": str(e)})





Expand Down
File renamed without changes.
File renamed without changes.
82 changes: 82 additions & 0 deletions Execute _strategy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
from oandapyV20 import API
from oandapyV20.contrib.requests import MarketOrderRequest
from oandapyV20.endpoints.pricing import PricingStream
from oandapyV20.endpoints.orders import OrderCreate
from oandapyV20.exceptions import V20Error
import time

account_id = "101-001-25836141-002"
api_key = "ba62e5ad63f2a8759ee31761ba01e196-fb6f30ba3b58d44a94152fa5cd4f3ce2"
api = API(access_token=api_key, environment="practice")
instrument = "GBP_USD"

prices = []
moving_average_period = 5
moving_average_sum = 0
position = 0
position_time = None
position_timeout = 30 # Position timeout in seconds

try:
r = PricingStream(accountID=account_id, params={"instruments": instrument})
for msg in api.request(r):
if msg["type"] == "HEARTBEAT":
continue

if msg["type"] == "PRICE":
bids = msg["bids"]
asks = msg["asks"]
closeout_bid = bids[0]["price"]
closeout_ask = asks[0]["price"]
curr_close = (float(closeout_bid) + float(closeout_ask)) / 2

if len(prices) == moving_average_period:
moving_average_sum -= prices[0]
prices = prices[1:]

moving_average_sum += curr_close
prices.append(curr_close)
moving_average = moving_average_sum / len(prices)

if position != 0 and time.time() - position_time >= position_timeout:
if position == 1:
order_data = MarketOrderRequest(instrument=instrument, units=-1000)
else:
order_data = MarketOrderRequest(instrument=instrument, units=1000)
r = OrderCreate(account_id, data=order_data.data)
api.request(r)
position = 0
print(f"Position closed due to timeout. Time: {time.time()}")

elif position == 0:
if curr_close > moving_average:
position = 1
order_data = MarketOrderRequest(instrument=instrument, units=1000)
r = OrderCreate(account_id, data=order_data.data)
api.request(r)
position_time = time.time()
print(f"Position opened at {curr_close}. Time: {time.time()}")
elif curr_close < moving_average:
position = -1
order_data = MarketOrderRequest(instrument=instrument, units=-1000)
r = OrderCreate(account_id, data=order_data.data)
api.request(r)
position_time = time.time()
print(f"Position opened at {curr_close}. Time: {time.time()}")
elif position == 1 and curr_close < moving_average:
position = 0
order_data = MarketOrderRequest(instrument=instrument, units=-1000)
r = OrderCreate(account_id, data=order_data.data)
api.request(r)
print(f"Position closed at {curr_close}. Time: {time.time()}")
elif position == -1 and curr_close > moving_average:
position = 0
order_data = MarketOrderRequest(instrument=instrument, units=1000)
r = OrderCreate(account_id, data=order_data.data)
api.request(r)
print(f"Position closed at {curr_close}. Time: {time.time()}")

except V20Error as e:
print("V20Error occurred: {e}")
except Exception as e:
print(f"An unexpected error occurred: {e}")
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file.
File renamed without changes.
Empty file added Gpt Trading/README.md
Empty file.
File renamed without changes.
File renamed without changes.
Empty file added Gpt Transactions/README.md
Empty file.
File renamed without changes.
Empty file added Gpt social/README.md
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 8615a5f

Please sign in to comment.