@@ -3,14 +3,12 @@ defmodule Naive.Strategy do
33 Module in charge of making and executing decisions
44 """
55 alias Core.Struct.TradeEvent
6+ alias Naive.Repo
67 alias Naive.Schema.Settings
78
89 require Logger
910
1011 @ binance_client Application . compile_env ( :naive , :binance_client )
11- @ logger Application . compile_env ( :core , :logger )
12- @ pubsub_client Application . compile_env ( :core , :pubsub_client )
13- @ repo Application . compile_env ( :naive , :repo )
1412
1513 defmodule Position do
1614 @ enforce_keys [
@@ -255,7 +253,7 @@ defmodule Naive.Strategy do
255253 } = position ,
256254 _settings
257255 ) do
258- @ logger . info (
256+ Logger . info (
259257 "Position (#{ symbol } /#{ id } ): " <>
260258 "Placing a BUY order @ #{ price } , quantity: #{ quantity } "
261259 )
@@ -279,7 +277,7 @@ defmodule Naive.Strategy do
279277 } = position ,
280278 _settings
281279 ) do
282- @ logger . info (
280+ Logger . info (
283281 "Position (#{ symbol } /#{ id } ): The BUY order is now filled. " <>
284282 "Placing a SELL order @ #{ sell_price } , quantity: #{ quantity } "
285283 )
@@ -305,7 +303,7 @@ defmodule Naive.Strategy do
305303 } = position ,
306304 _settings
307305 ) do
308- @ logger . info ( "Position (#{ symbol } /#{ id } ): The BUY order is now partially filled" )
306+ Logger . info ( "Position (#{ symbol } /#{ id } ): The BUY order is now partially filled" )
309307
310308 { :ok , % Binance.Order { } = current_buy_order } =
311309 @ binance_client . get_order ( symbol , timestamp , order_id )
@@ -324,7 +322,7 @@ defmodule Naive.Strategy do
324322 settings
325323 ) do
326324 new_position = generate_fresh_position ( settings )
327- @ logger . info ( "Position (#{ symbol } /#{ id } ): Trade cycle finished" )
325+ Logger . info ( "Position (#{ symbol } /#{ id } ): Trade cycle finished" )
328326 { :ok , new_position }
329327 end
330328
@@ -341,7 +339,7 @@ defmodule Naive.Strategy do
341339 } = position ,
342340 _settings
343341 ) do
344- @ logger . info ( "Position (#{ symbol } /#{ id } ): The SELL order is now partially filled" )
342+ Logger . info ( "Position (#{ symbol } /#{ id } ): The SELL order is now partially filled" )
345343
346344 { :ok , % Binance.Order { } = current_sell_order } =
347345 @ binance_client . get_order ( symbol , timestamp , order_id )
@@ -360,7 +358,7 @@ defmodule Naive.Strategy do
360358 settings
361359 ) do
362360 new_position = generate_fresh_position ( settings )
363- @ logger . info ( "Position (#{ symbol } /#{ id } ): Rebuy triggered. Starting a new position" )
361+ Logger . info ( "Position (#{ symbol } /#{ id } ): Rebuy triggered. Starting a new position" )
364362 { :ok , new_position }
365363 end
366364
@@ -375,7 +373,7 @@ defmodule Naive.Strategy do
375373 end
376374
377375 defp broadcast_order ( % Binance.Order { } = order ) do
378- @ pubsub_client . broadcast ( Core.PubSub , "ORDERS:#{ order . symbol } " , order )
376+ Phoenix.PubSub . broadcast ( Core.PubSub , "ORDERS:#{ order . symbol } " , order )
379377 end
380378
381379 defp convert_to_order ( % Binance.OrderResponse { } = response ) do
@@ -395,7 +393,7 @@ defmodule Naive.Strategy do
395393 exchange_info =
396394 @ binance_client . get_exchange_info ( )
397395
398- db_settings = @ repo . get_by! ( Settings , symbol: symbol )
396+ db_settings = Repo . get_by! ( Settings , symbol: symbol )
399397
400398 merge_filters_into_settings ( exchange_info , db_settings , symbol )
401399 end
@@ -437,8 +435,8 @@ defmodule Naive.Strategy do
437435 end
438436
439437 def update_status ( symbol , status ) when is_binary ( symbol ) and is_binary ( status ) do
440- @ repo . get_by ( Settings , symbol: symbol )
438+ Repo . get_by ( Settings , symbol: symbol )
441439 |> Ecto.Changeset . change ( % { status: status } )
442- |> @ repo . update ( )
440+ |> Repo . update ( )
443441 end
444442end
0 commit comments