This file contains hidden or 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
| from mnemonic import Mnemonic | |
| from bip32 import BIP32 | |
| import hashlib | |
| import base58 | |
| from datetime import datetime | |
| def privkey_to_wif_compressed(privkey_hex): | |
| extended_key = "80" + privkey_hex + "01" | |
| first_sha256 = hashlib.sha256(bytes.fromhex(extended_key)).hexdigest() | |
| second_sha256 = hashlib.sha256(bytes.fromhex(first_sha256)).hexdigest() |
This file contains hidden or 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
| # VIP level 0, paying fees with BNB = 0.075% | |
| env = TradingEnv(balance_amount=100,balance_unit='USDT', trading_fee_multiplier=0.99925) | |
| for i in range(len(df)): | |
| if env.balance_unit == 'USDT': | |
| for symbol in symbols: | |
| if df[f'{symbol}-USD_Low'].iloc[i] < df[f'{symbol}_lower_band'].iloc[i]: #buy signal | |
| env.buy(symbol, df[f'{symbol}_lower_band'].iloc[i], df['OpenTime'].iloc[i]) | |
| break | |
This file contains hidden or 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
| class TradingEnv: | |
| def __init__(self, balance_amount, balance_unit, trading_fee_multiplier): | |
| self.balance_amount = balance_amount | |
| self.balance_unit = balance_unit | |
| self.buys = [] | |
| self.sells = [] | |
| self.trading_fee_multiplier = trading_fee_multiplier | |
| def buy(self, symbol, buy_price, time): | |
| self.balance_amount = (self.balance_amount / buy_price) * self.trading_fee_multiplier |
This file contains hidden or 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
| import pandas as pd | |
| df = pd.read_csv('BTC_ETH_LTC_Jan2721_Jul2121_1h.csv') | |
| def sma(data, window): | |
| return(data.rolling(window = window).mean()) | |
| def bollinger_band(data, sma, window, nstd): | |
| std = data.rolling(window = window).std() | |
| upper_band = sma + std * nstd |
This file contains hidden or 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
| import pandas as pd | |
| from binance.client import Client | |
| from binance_keys import api_key, secret_key | |
| import time | |
| from datetime import datetime | |
| import plotly.graph_objects as go | |
| client = Client(api_key, secret_key) | |
| coins = ['BTC','ETH','LTC'] |
This file contains hidden or 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
| def get_action(model, observation, epsilon): | |
| #determine whether model action or random action based on epsilon | |
| act = np.random.choice(['model','random'], 1, p=[1-epsilon, epsilon])[0] | |
| observation = np.array(observation).reshape(1,6,7,1) | |
| logits = model.predict(observation) | |
| prob_weights = tf.nn.softmax(logits).numpy() | |
| if act == 'model': | |
| action = list(prob_weights[0]).index(max(prob_weights[0])) | |
| if act == 'random': |
This file contains hidden or 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
| class Memory: | |
| def __init__(self): | |
| self.clear() | |
| # Resets/restarts the memory buffer | |
| def clear(self): | |
| self.observations = [] | |
| self.actions = [] | |
| self.rewards = [] | |
| self.info = [] |
This file contains hidden or 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
| def check_if_action_valid(obs,action): | |
| if obs[action] == 0: | |
| valid = True | |
| else: | |
| valid = False | |
| return valid | |
| def player_1_agent(observation, configuration): | |
| action, prob_weights = get_action(player_1_model,observation['board'],0) |
This file contains hidden or 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
| def create_model(): | |
| model = models.Sequential() | |
| model.add(Flatten()) | |
| model.add(Dense(50, activation='relu')) | |
| model.add(Dense(50, activation='relu')) | |
| model.add(Dense(50, activation='relu')) | |
| model.add(Dense(50, activation='relu')) | |
| model.add(Dense(50, activation='relu')) | |
| model.add(Dense(50, activation='relu')) |
This file contains hidden or 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
| def check_if_done(observation): | |
| done = [False,'No Winner Yet'] | |
| #horizontal check | |
| for i in range(6): | |
| for j in range(4): | |
| if observation[i][j] == observation[i][j+1] == observation[i][j+2] == observation[i][j+3] == 1: | |
| done = [True,'Player 1 Wins Horizontal'] | |
| if observation[i][j] == observation[i][j+1] == observation[i][j+2] == observation[i][j+3] == 2: | |
| done = [True,'Player 2 Wins Horizontal'] | |
| #vertical check |
NewerOlder