-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue3 - Some epochs might not get truevals fix this (#67)
* Add trueval_sign function * Update trueval * Add trueval subgraph module * Update trueval main * Formatting * Add models module * Fixes * Fixes * Fixes * First pass without threading * Fixes * Threading first pass * To be continued * To be continued * Almost there * Done * Update max threads default * Linter fixes * Fixes * Remove cache * No more threads! * Increase sleep time * Fix merge * Formatting * Fixes * Fixz * Remove fl * Remove trueval sign * Add try-except * Improvements * Formatting * Remove models.py * Add test files * Remove unused class * move trueval subgraph to util * Fix * Add contract_data test * Add slot test * Improvements * Fix * Add quote and base as property * Update data test * Fix * Add trueval tests * Formatting * Fixes * Fix * Fix * Fix symbol interpret * Add live tests * Improve main * Formatting * Fixes * Remove redundant var * Order import * Formatting * Tests * Add test mode * Main test * Fix and looks * Formatting * Disable * Fix default * Use filters * Formatting * improvements * Add subgraph test * Formatting
- Loading branch information
Showing
10 changed files
with
569 additions
and
93 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
class ContractData: | ||
def __init__( | ||
self, | ||
name: str, | ||
address: str, | ||
symbol: str, | ||
seconds_per_epoch: int, | ||
seconds_per_subscription: int, | ||
trueval_submit_timeout: int, | ||
owner: str, | ||
pair: str, | ||
timeframe: str, | ||
source: str, | ||
): | ||
self.name = name | ||
self.address = address | ||
self.symbol = symbol | ||
self.seconds_per_epoch = seconds_per_epoch | ||
self.seconds_per_subscription = seconds_per_subscription | ||
self.trueval_submit_timeout = trueval_submit_timeout | ||
self.owner = owner | ||
self.pair = pair | ||
self.timeframe = timeframe | ||
self.source = source | ||
|
||
@property | ||
def quote(self): | ||
return self.pair.split("-")[1] | ||
|
||
@property | ||
def base(self): | ||
return self.pair.split("-")[0] |
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,7 @@ | ||
from pdr_backend.models.contract_data import ContractData | ||
|
||
|
||
class Slot: | ||
def __init__(self, slot: int, contract: ContractData): | ||
self.slot = slot | ||
self.contract = contract |
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,29 @@ | ||
from pdr_backend.models.contract_data import ContractData | ||
|
||
|
||
def test_contract_data_initialization(): | ||
contract = ContractData( | ||
"Contract Name", | ||
"0x12345", | ||
"test", | ||
300, | ||
60, | ||
15, | ||
"0xowner", | ||
"BTC-ETH", | ||
"1h", | ||
"binance", | ||
) | ||
|
||
assert contract.name == "Contract Name" | ||
assert contract.address == "0x12345" | ||
assert contract.symbol == "test" | ||
assert contract.seconds_per_epoch == 300 | ||
assert contract.seconds_per_subscription == 60 | ||
assert contract.trueval_submit_timeout == 15 | ||
assert contract.owner == "0xowner" | ||
assert contract.pair == "BTC-ETH" | ||
assert contract.timeframe == "1h" | ||
assert contract.source == "binance" | ||
assert contract.quote == "ETH" | ||
assert contract.base == "BTC" |
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,24 @@ | ||
from pdr_backend.models.slot import Slot | ||
from pdr_backend.models.contract_data import ContractData | ||
|
||
|
||
def test_slot_initialization(): | ||
contract = ContractData( | ||
"Contract Name", | ||
"0x12345", | ||
"test", | ||
300, | ||
60, | ||
15, | ||
"0xowner", | ||
"BTC/ETH", | ||
"1h", | ||
"binance", | ||
) | ||
|
||
slot_number = 5 | ||
slot = Slot(slot_number, contract) | ||
|
||
assert slot.slot == slot_number | ||
assert slot.contract == contract | ||
assert isinstance(slot.contract, ContractData) |
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 |
---|---|---|
@@ -1,5 +1,91 @@ | ||
from unittest.mock import patch | ||
from pdr_backend.trueval.trueval import get_true_val | ||
from pdr_backend.models.contract_data import ContractData | ||
|
||
|
||
def test_get_true_val(): | ||
pass | ||
def mock_fetch_ohlcv(*args, **kwargs): | ||
since = kwargs.get("since") | ||
if since == 1: | ||
return [[None, 100]] | ||
elif since == 2: | ||
return [[None, 200]] | ||
else: | ||
raise ValueError("Invalid timestamp") | ||
|
||
|
||
def mock_fetch_ohlcv_fail(*args, **kwargs): | ||
return [] | ||
|
||
|
||
def test_get_trueval_success(): | ||
contract = ContractData( | ||
name="ETH-USDT", | ||
address="0x1", | ||
symbol="ETH-USDT", | ||
seconds_per_epoch=60, | ||
seconds_per_subscription=500, | ||
pair="eth-usdt", | ||
source="kraken", | ||
timeframe="5m", | ||
trueval_submit_timeout=100, | ||
owner="0xowner", | ||
) | ||
|
||
with patch("ccxt.kraken.fetch_ohlcv", mock_fetch_ohlcv): | ||
result = get_true_val(contract, 1, 2) | ||
assert result == (True, False) # 1st True because 200 > 100 | ||
|
||
|
||
def test_get_trueval_live_lowercase_slash(): | ||
contract = ContractData( | ||
name="ETH-USDT", | ||
address="0x1", | ||
symbol="ETH-USDT", | ||
seconds_per_epoch=60, | ||
seconds_per_subscription=500, | ||
pair="btc/usdt", | ||
source="kraken", | ||
timeframe="5m", | ||
trueval_submit_timeout=100, | ||
owner="0xowner", | ||
) | ||
|
||
result = get_true_val(contract, 1692943200, 1692943500) | ||
assert result == (True, False) | ||
|
||
|
||
def test_get_trueval_live_lowercase_dash(): | ||
contract = ContractData( | ||
name="ETH-USDT", | ||
address="0x1", | ||
symbol="ETH-USDT", | ||
seconds_per_epoch=60, | ||
seconds_per_subscription=500, | ||
pair="btc-usdt", | ||
source="kraken", | ||
timeframe="5m", | ||
trueval_submit_timeout=100, | ||
owner="0xowner", | ||
) | ||
|
||
result = get_true_val(contract, 1692943200, 1692943500) | ||
assert result == (True, False) | ||
|
||
|
||
def test_get_trueval_fail(): | ||
contract = ContractData( | ||
name="ETH-USDT", | ||
address="0x1", | ||
symbol="ETH-USDT", | ||
seconds_per_epoch=60, | ||
seconds_per_subscription=500, | ||
pair="eth-usdt", | ||
source="kraken", | ||
timeframe="5m", | ||
trueval_submit_timeout=100, | ||
owner="0xowner", | ||
) | ||
|
||
with patch("ccxt.kraken.fetch_ohlcv", mock_fetch_ohlcv_fail): | ||
result = get_true_val(contract, 1, 2) | ||
assert result == (False, True) # 2nd True because failed |
Oops, something went wrong.