Skip to content
This repository has been archived by the owner on Nov 4, 2023. It is now read-only.

Botcamp/statistical arbitrage #53

Open
wants to merge 32 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
f983c65
(fix) Update polkadex connector status
nikspz Jun 19, 2023
de8c610
Merge pull request #6385 from hummingbot/fix-update-polkadex-connecto…
nikspz Jun 19, 2023
0dc32c9
update readme
david-hummingbot Jun 19, 2023
cde5758
Update README.md
david-hummingbot Jun 19, 2023
32ad1d8
Merge pull request #6386 from hummingbot/readme-polkadex
nikspz Jun 19, 2023
4cae89f
Merge branch 'staging' into development
cardosofede Jun 19, 2023
838ae0e
Merge pull request #6384 from hummingbot/development
nikspz Jun 19, 2023
d747853
fix - Update VERSION on staging
nikspz Jun 21, 2023
8971bd3
Merge pull request #6393 from hummingbot/fix---Update-VERSION-on-staging
nikspz Jun 21, 2023
74a8182
Merge branch 'master' into staging
cardosofede Jun 22, 2023
5fee7bf
update setup.py version
nikspz Jun 26, 2023
1298535
Merge pull request #6404 from hummingbot/fix-update-setup.py-version
nikspz Jun 26, 2023
547580a
Fix/ broken link README.md staging
nikspz Jun 26, 2023
2ba95e8
Merge pull request #6407 from hummingbot/Fix/-broken-link-README.md-s…
nikspz Jun 26, 2023
6387843
Merge pull request #6398 from hummingbot/staging
cardosofede Jun 26, 2023
6dc4447
(fix) delete old issue templates and update new ones
fengtality Jun 28, 2023
2bdb4ad
Merge pull request #6417 from hummingbot/fix/issue-templates
cardosofede Jun 28, 2023
30d1569
fix github template typo
nikspz Jul 3, 2023
c481739
Merge pull request #6430 from hummingbot/fix-github-template-typo-1
cardosofede Jul 3, 2023
892e0d7
(add) statistical arbitrage script
doi-doi Jul 6, 2023
481a773
(add) statistical arbitrage script
doi-doi Jul 6, 2023
f6ef892
(add) statistical arbitrage script
doi-doi Jul 6, 2023
dd752ef
(edit) statistical arbitrage script
doi-doi Jul 6, 2023
dcab852
(edit) statistical arbitrage script
doi-doi Jul 6, 2023
d7b89b4
(add) left and right side of the stat arb
Jul 12, 2023
e20616f
(add) left and right side of the stat arb
Jul 13, 2023
6f586b7
Update directional_strategy_base.py
doi-doi Jul 17, 2023
934426b
Update statistical_arbitrage.py
doi-doi Jul 17, 2023
f8863b6
Update statistical_arbitrage.py
doi-doi Jul 18, 2023
88f9874
Update statistical_arbitrage.py
doi-doi Jul 18, 2023
0a0664a
Update statistical_arbitrage.py
doi-doi Jul 25, 2023
548948d
Update statistical_arbitrage.py
doi-doi Jul 28, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/ISSUE_TEMPLATE/bounty_request.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Bounty request
description: Submit a bounty for this project 2.0
title: "Bounty request"
name: Bounty Request
description: Create a bounty for developers to work on
title: "SUMMARY OF BOUNTY REQUEST"
labels: bounty
body:
- type: markdown
Expand All @@ -10,7 +10,7 @@ body:

* Please make sure to look on our GitHub issues to avoid duplicate tickets
* You can add additional `Labels` to support this ticket (connectors, strategies, etc)
* If this is something to do with installation and how to's we would recommend to visit our [Discord server](https://discord.gg/hummingbot) and [Hummingbot docs](https://docs.hummingbot.org/)
* See https://docs.hummingbot.org/governance/bounties/sponsors/ for more information on bounties
- type: textarea
id: bounty-description
attributes:
Expand Down
33 changes: 0 additions & 33 deletions .github/ISSUE_TEMPLATE/bug_report.md

This file was deleted.

6 changes: 3 additions & 3 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Bug Report
description: Create a bug report to help us improve 2.0
title: "Bug Report"
description: Create a bug report to help us improve
title: "SUMMARY OF BUG"
labels: bug
body:
- type: markdown
Expand Down Expand Up @@ -53,4 +53,4 @@ body:
label: Attach required files
description: Please attach your config file and log file located on the "../hummingbot/logs/" folder. It would be difficult for us to help you without those!
validations:
required: false
required: false
19 changes: 0 additions & 19 deletions .github/ISSUE_TEMPLATE/feature_request.md

This file was deleted.

4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE/feature_request.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Feature request
description: Suggest an idea for this project 2.0
title: "Feature request"
description: Suggest an idea that will improve the Hummingbot codebase
title: "SUMMARY OF FEATURE REQUEST"
labels: enhancement
body:
- type: markdown
Expand Down
18 changes: 0 additions & 18 deletions .github/ISSUE_TEMPLATE/scripts_request.md

This file was deleted.

22 changes: 0 additions & 22 deletions .github/ISSUE_TEMPLATE/user_story_template.md

This file was deleted.

3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ Exchanges may be centralized (**CEX**), or decentralized (**DEX**), in which cas
| ![](https://img.shields.io/static/v1?label=Hummingbot&message=BRONZE&color=green) | [Pangolin](https://docs.hummingbot.org/exchanges/pangolin/) | AMM DEX |
| ![](https://img.shields.io/static/v1?label=Hummingbot&message=BRONZE&color=green) | [Perpetual Protocol](https://docs.hummingbot.org/exchanges/perp/) | PERP DEX |
| ![](https://img.shields.io/static/v1?label=Hummingbot&message=BRONZE&color=green) | [Phemex Perpetual](https://docs.hummingbot.org/exchanges/perp/) | PERP DEX |
| ![](https://img.shields.io/static/v1?label=Hummingbot&message=BRONZE&color=green) | [Polkadex](https://docs.hummingbot.org/exchanges/polkadex/) | SPOT DEX |
| ![](https://img.shields.io/static/v1?label=Hummingbot&message=BRONZE&color=green) | [ProBit](https://docs.hummingbot.org/exchanges/probit/) | SPOT CEX |
| ![](https://img.shields.io/static/v1?label=Hummingbot&message=BRONZE&color=green) | [Ref Finance](https://docs.hummingbot.org/exchanges/ref/) | SPOT DEX |
| ![](https://img.shields.io/static/v1?label=Hummingbot&message=BRONZE&color=green) | [Sushiswap](https://docs.hummingbot.org/exchanges/sushiswap/) | AMM DEX |
Expand All @@ -112,7 +113,7 @@ We provide customizable strategy templates for core trading strategies that user
* [Cross Exchange Market Making](https://docs.hummingbot.org/strategies/cross-exchange-market-making/): Provide liquidity while hedging filled orders on another exchange
* [AMM Arbitrage](https://docs.hummingbot.org/strategies/amm-arbitrage/): Exploits price differences between AMM and SPOT exchanges

**CORE** strategies are selected via HBOT voting through quarterly [Polls](https://hummingbot.org/maintenance/certification/). In addition, the codebase includes **COMMUNITY** strategies that are maintained by individuals or firms in the community. See the [Hummingbot documentation](https://docs.hummingbot.org/strategies) for all strategies supported.
**CORE** strategies are selected via HBOT voting through quarterly [Polls](https://docs.hummingbot.org/governance/polls/). In addition, the codebase includes **COMMUNITY** strategies that are maintained by individuals or firms in the community. See the [Hummingbot documentation](https://docs.hummingbot.org/strategies) for all strategies supported.

### Scripts

Expand Down
2 changes: 1 addition & 1 deletion hummingbot/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
dev-1.17.0
1.17.0
1 change: 1 addition & 0 deletions hummingbot/connector/connector_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
'foxbit': 'bronze',
'phemex_perpetual': 'bronze',
'phemex_perpetual_testnet': 'bronze',
'polkadex': 'bronze',
}

warning_messages = {
Expand Down
123 changes: 90 additions & 33 deletions hummingbot/strategy/directional_strategy_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ class DirectionalStrategyBase(ScriptStrategyBase):
directional_strategy_name: str
# Define the trading pair and exchange that we want to use and the csv where we are going to store the entries
trading_pair: str
trading_pair_2: str
exchange: str

# Maximum position executors at a time
max_executors: int = 1
max_executors: int = 2
position_mode: PositionMode = PositionMode.HEDGE
active_executors: List[PositionExecutor] = []
stored_executors: List[PositionExecutor] = []
Expand All @@ -65,6 +66,7 @@ class DirectionalStrategyBase(ScriptStrategyBase):
time_limit_order_type: OrderType = OrderType.MARKET
trailing_stop_activation_delta = 0.003
trailing_stop_trailing_delta = 0.001
cooldown_after_execution = 30

# Create the candles that we want to use and the thresholds for the indicators
candles: List[CandlesBase]
Expand All @@ -89,6 +91,15 @@ def is_perpetual(self):
"""
return "perpetual" in self.exchange

@property
def max_active_executors_condition(self):
return len(self.get_active_executors()) < self.max_executors

@property
def time_between_signals_condition(self):
seconds_since_last_signal = self.current_timestamp - self.get_timestamp_of_last_executor()
return seconds_since_last_signal > self.cooldown_after_execution

def get_csv_path(self) -> str:
today = datetime.datetime.today()
csv_path = data_path() + f"/{self.directional_strategy_name}_position_executors_{self.exchange}_{self.trading_pair}_{today.day:02d}-{today.month:02d}-{today.year}.csv"
Expand Down Expand Up @@ -119,53 +130,96 @@ def on_stop(self):
for candle in self.candles:
candle.stop()

def get_active_executors(self):
def get_active_executors(self) -> List[PositionExecutor]:
return [signal_executor for signal_executor in self.active_executors
if not signal_executor.is_closed]

def get_closed_executors(self) -> List[PositionExecutor]:
return [signal_executor for signal_executor in self.active_executors
if signal_executor.is_closed]

def get_timestamp_of_last_executor(self):
if len(self.stored_executors) > 0:
return self.stored_executors[-1].close_timestamp
else:
return 0

def on_tick(self):
self.clean_and_store_executors()
if self.is_perpetual:
self.check_and_set_leverage()
if len(self.get_active_executors()) < self.max_executors and self.all_candles_ready:
position_config = self.get_position_config()
if position_config:
signal_executor = PositionExecutor(
strategy=self,
position_config=position_config,
)
self.active_executors.append(signal_executor)
self.clean_and_store_executors()
if self.max_active_executors_condition and self.all_candles_ready and self.time_between_signals_condition:
# edit to get 2 opposing trades from different trading pairs
positions_to_open = self.get_position_config()
if positions_to_open is not None: # Add a conditional check
for position_config in positions_to_open:
signal_executor = PositionExecutor(
strategy=self,
position_config=position_config,
)
self.active_executors.append(signal_executor)

def get_position_config(self):
# added another set of opposing position signal below
signal = self.get_signal()
if signal == 0:
return None
else:
positions = []
price = self.connectors[self.exchange].get_mid_price(self.trading_pair)
side = TradeType.BUY if signal == 1 else TradeType.SELL
if self.open_order_type.is_limit_type():
price = price * (1 - signal * self.open_order_slippage_buffer)
position_config = PositionConfig(
timestamp=self.current_timestamp,
trading_pair=self.trading_pair,
exchange=self.exchange,
side=side,
amount=self.order_amount_usd / price,
take_profit=self.take_profit,
stop_loss=self.stop_loss,
time_limit=self.time_limit,
entry_price=price,
open_order_type=self.open_order_type,
take_profit_order_type=self.take_profit_order_type,
stop_loss_order_type=self.stop_loss_order_type,
time_limit_order_type=self.time_limit_order_type,
trailing_stop=TrailingStop(
activation_price_delta=self.trailing_stop_activation_delta,
trailing_delta=self.trailing_stop_trailing_delta
),
leverage=self.leverage,
)
return position_config

for trading_pair in self.markets[self.exchange]:
side = TradeType.BUY if signal == 1 else TradeType.SELL
position_config = PositionConfig(
timestamp=self.current_timestamp,
trading_pair=self.trading_pair,
exchange=self.exchange,
side=side,
amount=self.order_amount_usd / price,
take_profit=self.take_profit,
stop_loss=self.stop_loss,
time_limit=self.time_limit,
entry_price=price,
open_order_type=self.open_order_type,
take_profit_order_type=self.take_profit_order_type,
stop_loss_order_type=self.stop_loss_order_type,
time_limit_order_type=self.time_limit_order_type,
trailing_stop=TrailingStop(
activation_price_delta=self.trailing_stop_activation_delta,
trailing_delta=self.trailing_stop_trailing_delta
),
leverage=self.leverage,
)
positions.append(position_config)

# opposing position signal
price_2 = self.connectors[self.exchange].get_mid_price(self.trading_pair_2)
opposing_side = TradeType.SELL if side == TradeType.BUY else TradeType.BUY
opposing_position_config = PositionConfig(
timestamp=self.current_timestamp,
trading_pair=self.trading_pair_2,
exchange=self.exchange,
side=opposing_side,
amount=self.order_amount_usd / price_2,
take_profit=self.take_profit,
stop_loss=self.stop_loss,
time_limit=self.time_limit,
entry_price=price_2,
open_order_type=self.open_order_type,
take_profit_order_type=self.take_profit_order_type,
stop_loss_order_type=self.stop_loss_order_type,
time_limit_order_type=self.time_limit_order_type,
trailing_stop=TrailingStop(
activation_price_delta=self.trailing_stop_activation_delta,
trailing_delta=self.trailing_stop_trailing_delta
),
leverage=self.leverage,
)
positions.append(opposing_position_config)

return positions

def get_signal(self):
"""Base method to get the signal from the candles."""
Expand Down Expand Up @@ -208,6 +262,9 @@ def check_and_set_leverage(self):
for trading_pair in connector.trading_pairs:
connector.set_position_mode(self.position_mode)
connector.set_leverage(trading_pair=trading_pair, leverage=self.leverage)
for trading_pair_2 in connector.trading_pairs:
connector.set_position_mode(self.position_mode)
connector.set_leverage(trading_pair=trading_pair_2, leverage=self.leverage)
self.set_leverage_flag = True

def clean_and_store_executors(self):
Expand Down
Loading