Created
July 11, 2018 21:26
-
-
Save skeller88/a77d0fc04753c5bb39e83903910d8605 to your computer and use it in GitHub Desktop.
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
from typing import Dict | |
# Start | |
# binance - 2 BTC | |
# bittrex - 4 ETH | |
# allocations: { | |
# 'free': {'binance': {'BTC': 2}, 'bittrex: {'ETH': 4} } | |
# } | |
# receive arbitrage signal for BTC and ETH | |
# create arbitrage strategy execution instance, "arb_btc_eth_1" | |
# query portfolio manager for initial capital allocated to a new arbitrage strategy. It's 50% of free balance on each | |
# exchange. | |
# Execute | |
# arb_btc_eth_1 - allocate 50% of each of current free balances - 1 BTC on binance and 4 ETH on bittrex | |
# allocations: { | |
# 'arb_btc_eth_1': {'binance': {'BTC': 1}, 'bittrex: {'ETH': 2} } | |
# 'free': {'binance': {'BTC': 1}, 'bittrex: {'ETH': 2} } | |
# } | |
# arb_btc_eth_1 - rebalance 1 BTC from binance to bittrex and 1 ETH from bittrex to binance. Note that a strategy | |
# may attempt to use the alloted balance before the deposit has completed. Waiting until completion is an enchancement | |
# for later | |
# allocations: { | |
# 'arb_btc_eth_1': {'binance': {'BTC': 1}, 'bittrex: {'ETH': 2} } | |
# 'free': {'binance': {'BTC': 1}, 'bittrex: {'ETH': 2} } | |
# } | |
# arb_btc_eth_1 - BTC buy order for ETH on bittrex is completed at a price of 3 ETH per BTC. | |
# allocations: { | |
# 'arb_btc_eth_1': {'binance': {'ETH': 2}, 'bittrex: {'ETH': 3} } | |
# 'free': {'binance': {'BTC': 1}, 'bittrex: {'ETH': 2} } | |
# } | |
# arb_btc_eth_1 - ETH sell order for BTC on binance is completed at a sell price of 1.1 BTC per ETH | |
# allocations: { | |
# 'arb_btc_eth_1': {'binance': {'BTC': 1.1}, 'bittrex: {'ETH': 3} } | |
# 'free': {'binance': {'BTC': 1}, 'bittrex: {'ETH': 2} } | |
# } | |
# receive new market signal for XRP. Execute buy order on binance. | |
# create "new_market_xrp_1 execution" instance | |
# query portfolio manager for initial capital allocated to a new arbitrage strategy. It's 50% of free balance on exchange | |
# to purchase. | |
# allocations: { | |
# 'arb_btc_eth_1': {'binance': {'BTC': 1.1}, 'bittrex: {'ETH': 3} } | |
# 'new_market_xrp_1': {'binance': {'BTC': .5 } } | |
# 'free': {'binance': {'BTC': .5}, 'bittrex: {'ETH': 2} } | |
# } | |
# Execute | |
# new_market_xrp_1 - buy XRP at 5000 XRP/BTC - remove .5 BTC on bittrex, allocate 5000 XRP on bittrex | |
# allocations: { | |
# 'arb_btc_eth_1': {'bittrex': {'ETH': 3}, 'binance: {'BTC': 1.1} }, | |
# 'new_market_xrp_1': {'bittrex': {'XRP': 5000 } } | |
# 'free': {'binance': {'BTC': .5}, 'bittrex: {'ETH': 2} } | |
# } | |
# new_market_xrp_1 - sell 5000 XRP for 1.5 BTC - end strategy - remove 5000 XRP on bittrex | |
# allocations: { | |
# 'arb_btc_eth_1': {'bittrex': {'ETH': 3}, 'binance: {'BTC': 1.1} }, | |
# 'free': {'binance': {'BTC': 2}, 'bittrex: {'ETH': 2} } | |
# } | |
class PortfolioManagerService: | |
""" | |
Allocate % of capital on each exchange to each strategy. | |
""" | |
def __init__(self, allocations: Dict[str, Dict]): | |
""" | |
Args: | |
allocations: Dict[str, Dict[str]]. Example: { | |
'new_market': float | |
} | |
""" | |
self.allocations_by_strategy: Dict[str, Dict] = allocations | |
def set_allocations(self, allocations: Dict): | |
self.allocations_by_strategy: Dict = allocations | |
def get_allocations_for_strategy_id(strategy_id: str): | |
return self.allocations_by_strategy.get(strategy_id) | |
def set_allocations_for_strategy_id(strategy_id: str, allocations: Dict): | |
self.allocations_by_strategy[strategy_id] = allocations | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment