-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A rather difficult bug in Mimic, affecting only position flipping, ha…
…s *finally* been crushed. The bug caused reporting errors in the quote currency. Added charting program for Mimic by alCa. Version Update. Changes to be committed: modified: Base/JackrabbitLocker modified: Base/JackrabbitOliverTwist modified: Base/JackrabbitRelay modified: Base/Library/JRRmimic.py modified: Base/Library/JackrabbitProxy.py modified: Base/Library/JackrabbitRelay.py modified: Base/MIMIC-PlaceOrder new file: Extras/Mimic/alCaCharts modified: requirements.txt
- Loading branch information
Showing
10 changed files
with
221 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Jackrabbit Relay | ||
# 2021 Copyright © Robert APM Darin | ||
# All rights reserved unconditionally. | ||
|
||
import sys | ||
sys.path.append('/home/JackrabbitRelay2/Base/Library') | ||
import os | ||
import time | ||
import json | ||
import pandas as pd | ||
import matplotlib.pyplot as plt | ||
|
||
import JRRsupport | ||
|
||
chartDir='/home/JackrabbitRelay2/Data/Charts/' | ||
MimicData='/home/JackrabbitRelay2/Data/Mimic/' | ||
|
||
def plot_trading_data(trading_data,account,base,quot): | ||
# Convert JSON strings to a list of dictionaries | ||
# data = [json.loads(line) for line in trading_data.split('\n') if line] | ||
data=trading_data | ||
|
||
# Convert to DataFrame | ||
df = pd.DataFrame(data) | ||
|
||
# Convert 'DateTime' to datetime object | ||
df['DateTime'] = pd.to_datetime(df['DateTime']) | ||
|
||
# Plot PEPE balance over time | ||
plt.figure(figsize=(15, 8)) | ||
|
||
plt.subplot(3, 2, 1) | ||
plt.plot(df['DateTime'], df[base], marker='o') | ||
plt.title(f'{base} Balance Over Time') | ||
plt.xlabel('DateTime') | ||
plt.ylabel(base) | ||
|
||
# Plot USDT balance over time | ||
plt.subplot(3, 2, 2) | ||
plt.plot(df['DateTime'], df[quote], marker='o', color='orange') | ||
plt.title(f'{quote} Balance Over Time') | ||
plt.xlabel('DateTime') | ||
plt.ylabel(quote) | ||
|
||
# Plot transaction amounts over time | ||
plt.subplot(3, 2, 3) | ||
plt.plot(df['DateTime'], df['Amount'], marker='o', color='green') | ||
plt.title('Transaction Amount Over Time') | ||
plt.xlabel('DateTime') | ||
plt.ylabel('Amount') | ||
|
||
# Plot transaction prices over time | ||
plt.subplot(3, 2, 4) | ||
plt.plot(df['DateTime'], df['Price'], marker='o', color='red') | ||
plt.title('Transaction Price Over Time') | ||
plt.xlabel('DateTime') | ||
plt.ylabel('Price') | ||
|
||
# Plot fees over time | ||
plt.subplot(3, 2, 5) | ||
plt.plot(df['DateTime'], df['Fee'], marker='o', color='purple') | ||
plt.title('Transaction Fee Over Time') | ||
plt.xlabel('DateTime') | ||
plt.ylabel('Fee') | ||
|
||
# Plot action distribution | ||
plt.subplot(3, 2, 6) | ||
df['Action'].value_counts().plot(kind='bar', color=['blue', 'red']) | ||
plt.title('Action Distribution') | ||
plt.xlabel('Action') | ||
plt.ylabel('Count') | ||
|
||
plt.tight_layout() | ||
# plt.show() | ||
plt.savefig(f'{chartDir}alCaChart.mimic.{account}.{base}{quote}.png') | ||
plt.close() | ||
|
||
# Sample data input | ||
#trading_data = """ | ||
#{"DateTime": "2024-05-26 19:42:27.144159", "ID": "17167453471441732", "Action": "buy", "Asset": "PEPE/USDT", "PEPE": 2451113.05611632, "USDT": 94817.5613180798, "Amount": 2450818.31777792, "Price": 1.593e-05, "Fee": 0.09760384} | ||
#{"DateTime": "2024-05-26 19:42:29.191986", "ID": "17167453491920022", "Action": "sell", "Asset": "PEPE/USDT", "PEPE": 2591.021503230091, "USDT": 94856.4687616998, "Amount": 2448522.03461309, "Price": 1.593e-05, "Fee": 0.09751239} | ||
#""" | ||
#plot_trading_data(trading_data) | ||
|
||
### | ||
### Main code base. | ||
### | ||
|
||
if len(sys.argv)<2: | ||
print("A Mimic account is required.") | ||
sys.exit(1) | ||
|
||
account=sys.argv[1] | ||
acn=f'{MimicData}{account}.history' | ||
if not os.path.exists(acn): | ||
print('Please verify wallet name and case') | ||
sys.exit(1) | ||
|
||
TradeData=JRRsupport.ReadFile(acn) | ||
lines=TradeData.strip().split('\n') | ||
|
||
Wallet={} | ||
|
||
for line in lines: | ||
if line=='': | ||
continue | ||
|
||
try: | ||
data=json.loads(line) | ||
except: | ||
print("Line damaged:") | ||
print(f" {line}") | ||
sys.exit(1) | ||
|
||
if data['Asset'] not in Wallet: | ||
Wallet[data['Asset']]=[] | ||
|
||
Wallet[data['Asset']].append(data) | ||
|
||
for asset in sorted(Wallet.keys()): | ||
base,quote=asset.split('/') | ||
if ':' in asset: | ||
quote=asset.split(':')[1] | ||
if '-' in quote: | ||
quote=quote.split('-')[0] | ||
plot_trading_data(Wallet[asset],account,base,quote) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,5 @@ numpy | |
ccxt | ||
oandapyV20 | ||
plotly | ||
matplotlib | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
current_position = self.Wallet['Wallet'].get(base, 0) | ||
|
||
if (current_position > 0 and actualAmount < 0) or (current_position < 0 and actualAmount > 0): | ||
# Flipping logic | ||
flip_proceeds = abs(current_position) * actualPrice | ||
self.Wallet['Wallet'][quote] += flip_proceeds # Cover the existing position | ||
self.Wallet['Wallet'][base] = 0 # Clear the existing position | ||
|
||
# Open the new position with the amount provided | ||
new_position_cost = abs(actualAmount) * actualPrice * (1 + fee_rate) | ||
if self.Wallet['Wallet'][quote] < new_position_cost: | ||
self.Wallet['Enabled'] = 'N' | ||
return 'Account Liquidated!' | ||
|
||
self.Wallet['Wallet'][quote] -= new_position_cost | ||
self.Wallet['Wallet'][base] = actualAmount # Set the new position with the provided amount | ||
|
||
# Update fees | ||
fee = abs(actualAmount) * actualPrice * fee_rate | ||
self.Wallet['Fees'] = self.Wallet.get('Fees', 0) + fee | ||
|
||
# Record the order | ||
order = { | ||
'DateTime': datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f'), | ||
'ID': f"{time.time() * 10000000:.0f}", | ||
'Action': action, | ||
'Asset': asset, | ||
base: self.Wallet['Wallet'][base], | ||
quote: self.Wallet['Wallet'][quote], | ||
'Amount': round(actualAmount, 8), | ||
'Price': round(actualPrice, 8), | ||
'Fee': round(fee, 8) | ||
} | ||
JRRsupport.AppendFile(self.history, json.dumps(order) + '\n') | ||
return order | ||
|